Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 5 Sept 06, 2012 Regular expressions – examples Converting DFA to regular expression. (same works for NFA to r.e. conversion.) Converting R.E. to.

Similar presentations


Presentation on theme: "Lecture 5 Sept 06, 2012 Regular expressions – examples Converting DFA to regular expression. (same works for NFA to r.e. conversion.) Converting R.E. to."— Presentation transcript:

1 Lecture 5 Sept 06, 2012 Regular expressions – examples Converting DFA to regular expression. (same works for NFA to r.e. conversion.) Converting R.E. to NFA

2 RE’s: Introduction vRegular expressions are an algebraic way to describe languages. vThey describe exactly the regular languages. vIf E is a regular expression, then L(E) is the language it defines. vWe’ll describe RE’s and their languages recursively.

3 RE’s: Definition  Basis 1: If a is any symbol, then a is a RE, and L(a) = {a}.  Note: {a} is the language containing one string, and that string is of length 1.  Basis 2: ε is a RE, and L(ε) = {ε}.  Basis 3:  is a RE, and L(  ) = { }.

4 RE’s: Definition – (2) vInduction 1: If E 1 and E 2 are regular expressions, then E 1 +E 2 is a regular expression, and L(E 1 +E 2 ) = L(E 1 )  L(E 2 ). vInduction 2: If E 1 and E 2 are regular expressions, then E 1 E 2 is a regular expression, and L(E 1 E 2 ) = L(E 1 )L(E 2 ). Concatenation : the set of strings wx such that w Is in L(E 1 ) and x is in L(E 2 ).

5 RE’s: Definition – (3) vInduction 3: If E is a RE, then E* is a RE, and L(E*) = (L(E))*. Closure, or “Kleene closure” = set of strings w 1 w 2 …w n, for some n > 0, where each w i is in L(E). Note: when n=0, the string is ε.

6 Precedence of Operators vParentheses may be used wherever needed to influence the grouping of operators. vOrder of precedence is * (highest), then concatenation, then + (lowest).

7 Examples: RE’s  L(01) = {01}.  L(01+0) = {01, 0}.  L(0(1+0)) = {01, 00}.  Note order of precedence of operators.  L(0*) = {ε, 0, 00, 000,… }.  L((0+10)*(ε+1)) = all strings of 0’s and 1’s without two consecutive 1’s.

8

9 Theorem: A language is regular if and only if it is accepted by a regular expression. Proof: Show how to convert from regular expression to NFA and vice- versa. Let L be accepted by a regular expression. We prove that it is regular, i.e., there is a NFA for L. Cases to consider: (1)empty-set (2) single symbol {a} (3) {  } (4)(a) R1 + R2 (b) R1. R2 (c) R1* (1), (2) and (3) are easy base cases. For (4), inductively construct NFA’s for R1 and R2, and from it construct an NFA for R.

10

11 Induction step is shown in the next theorem.

12 Theorem: The set of Regular languages is closed under the three operations concatenation, union and Kleene star. Proof: (by construction) Union: Given DFA’s M 1 and M 2 for L 1 and L 2, we design a NFA for L 1 U L 2. s1 s2 s   M1M1 M2M2

13 Concatenation:

14

15 Concatenation – Formal Proof

16 Closure under Kleene star – informal proof DFA for a language L is shown on the left. The NFA for L* can be constructed as shown on the right.

17

18 Converse is shown as follows: Given a DFA (or NFA), we remove states one by one until we have one state left. At this point, we can write down the regular expression. The idea is to use generalized NFA, one in which the transitions are labeled not by a single symbol, but by a regular expression. Example of GNFA:

19 Conversion from DFA to regular expression Key step: how to remove a state of a GNFA

20 So far, we have seen how to design DFA, NFA or regular expressions for various languages. We also learned how to convert: e-NFA  NFA NFA -> DFA DFA  regular expression Regular expression  NFA


Download ppt "Lecture 5 Sept 06, 2012 Regular expressions – examples Converting DFA to regular expression. (same works for NFA to r.e. conversion.) Converting R.E. to."

Similar presentations


Ads by Google