Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 8 Sept 29, 2011 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 8 Sept 29, 2011 Regular expressions – examples Converting DFA to regular expression. (same works for NFA to r.e. conversion.) Converting R.E. to."— Presentation transcript:

1 Lecture 8 Sept 29, 2011 Regular expressions – examples Converting DFA to regular expression. (same works for NFA to r.e. conversion.) Converting R.E. to NFA Pumping lemma

2

3 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.

4

5

6

7 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:

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

9 So far, we have seen how to design DFA, NFA or regular expressions for various languages. We also learned how to convert: NFA  DFA DFA  regular expression Regular expression  NFA But there are many languages for which we can never build a DFA or an NFA or a regular expression. Can you think of such a language?

10 Two fundamental examples L = { a n b n | n > 0} This contains strings , ab, aabb, aaabbb, … etc. Why is it not possible to create a DFA for L? L’ = { w | w is a balanced parentheses string over [, ] } This includes strings such as [ ], [ ][ ], [ [ ] ], etc. How can we show that it is impossible to build DFA for these languages?

11 A tool known as pumping lemma is used to show that certain languages are not regular. Idea: Because a DFA D has a finite number of states, say n D, before reading n D + 1 input characters, D must enter some state q for a second time. Characteristics of Regular Languages

12 The Pumping Lemma If L is a regular language, then:  a value n such that:  w in L such that |w| > n,  x,y,z such that w = xyz where |y| > 0, |xy| < n  i > 0, xy i z  L

13 Proof: let L = L(D) Given w = w 1 w 2 … w k, let s 1 s 2 … s k+1 be the consecutive states reached by DFA D on w (where s 1 = s the start state) If k>n D, then by the pigeon hole principle, we know  i,j, (i<j), i, j  {1 … k+1} such that s i = s j Then x = w 1 w 2 … w i-1 puts D in state s i and so does xy = w 1 w 2 … w i-1 w i … w j-1 … and so does xy t = w 1 w 2 … w i-1 (w i … w j-1 ) t

14 Proof … visualization x = w 1 w 2 … w i-1 y = w i … w j-1 z = w j … w k accept s1s1 s k+1 sisi

15 Proof … continued z = w j … w k takes D from state s i to s k+1, an accept state So xy t z = w 1 w 2 … w i-1 (w i … w j-1 ) t w j … w k takes D from the start state to the same accept state

16 Crucial use of the Pumping Lemma: to show that L is not regular ! Using the contrapositive A implies B B implies A

17 the Pumping Lemma in contrapositive form L is NOT a regular language  n in Z  w such that |w| > n  x,y,z such that w = xyz and |y|>0 and |xy|<n  i>0 s.t. xy i z is NOT in L If then

18 Applications of pumping lemma Therefore L is not regular.

19

20 A technique for showing lower-bound on the number of states in a DFA Example: Consider the regular language L = { x | the 5-th symbol from the right-end of x is 1} over the alphabet  = {0, 1}. We will show that any DFA for this language requires at least 32 states. Let w 0 = 00000, w 1 = 00001, …, w 31 = 11111 be the list of all strings of length 5 over . Let M be any DFA accepting L. Let q j =  (s, w j ) be the state reached from the starting state on input w j. We will argue that all q j ’s must be distinct. (The proof will be completed in lecture.) Note: Problem 4 of HW 4 requires you to use this technique.


Download ppt "Lecture 8 Sept 29, 2011 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