340 likes | 344 Views
Regular Expressions. Regular Expressions. Regular expressions describe regular languages Example: describes the language. Given regular expressions and. Are regular expressions. Recursive Definition. Primitive regular expressions:. Not a regular expression:.
E N D
Regular Expressions COMP 335
Regular Expressions • Regular expressions • describe regular languages • Example: • describes the language COMP 335
Given regular expressions and Are regular expressions Recursive Definition Primitive regular expressions: COMP 335
Not a regular expression: Examples A regular expression: COMP 335
Languages of Regular Expressions • : language of regular expression • Example: COMP 335
Definition • For primitive regular expressions : COMP 335
Definition (continued) • For regular expressions and COMP 335
Example • Regular expression: COMP 335
Example • Regular expression COMP 335
Example • Regular expression COMP 335
= {all strings with at least two consecutive 0} Example • Regular expression COMP 335
= { all strings without two consecutive 0 } Example • Regular expression COMP 335
Equivalent Regular Expressions • Definition: • Regular expressions and • are equivalent if COMP 335
and are equivalent Reg. expressions Example = { all strings without two consecutive 0 } COMP 335
Theorem Languages Generated by Regular Expressions Regular Languages COMP 335
1. For any regular expression the language is regular Theorem - Part 1 Languages Generated by Regular Expressions Regular Languages COMP 335
2. For any regular language , there is a regular expression with Theorem - Part 2 Languages Generated by Regular Expressions Regular Languages COMP 335
1. For any regular expression the language is regular Proof by induction on the size of Proof - Part 1 COMP 335
NFAs regular languages Induction Basis • Primitive Regular Expressions: COMP 335
Inductive Hypothesis • Assume for regular expressions and • that and are regular languages COMP 335
Inductive Step • We will prove: are regular Languages. COMP 335
We also know: Regular languages are closed under: Union Concatenation Star By inductive hypothesis we know: and are regular languages COMP 335
Therefore: Are regular languages COMP 335
And trivially: is a regular language COMP 335
Proof – Part 2 2. For any regular language there is a regular expression with Proof by construction of regular expression COMP 335
Since is regular, take an • NFA that accepts it Single final state COMP 335
From , construct an equivalent • Generalized Transition Graph in which • transition labels are regular expressions Example: COMP 335
Another Example: COMP 335
Reducing the states: COMP 335
Resulting Regular Expression: COMP 335
In General • Removing states: COMP 335
The final transition graph: The resulting regular expression: COMP 335