1 / 26

Intro to Theory of Computation

Intro to Theory of Computation. L ECTURE 5 Theory of Computation Conversion from NFAs to regular expressions Proving that a language is not regular: pumping lemma. CS 464. Sofya Raskhodnikova. 01*0. 0. 0. 1. NFAs to regular expressions.

Download Presentation

Intro to Theory of Computation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Intro to Theory of Computation • LECTURE5 • Theory of Computation • Conversion from NFAs to regular expressions • Proving that a language is not regular: pumping lemma CS 464 Sofya Raskhodnikova SofyaRaskhodnikova; based on slides by Nick Hopper

  2. 01*0 0 0 1 NFAs to regular expressions Theorem.Every NFA has an equivalent regular expression. Proof idea: Transform NFA to a regular expression by removing states and relabeling the arrows with regular expressions. Sofya Raskhodnikova; based on slides by Nick Hopper

  3. Generalized NFAs Sofya Raskhodnikova; based on slides by Nick Hopper Each transition is labeled with a regular expression Unique and distinct start and accept states No transitions to the start state No transitions from the accept state

  4. Generalized NFAs a[b a*b a qs q2 qa G accepts w if it finds q0q1…qk, w1…wk: wi2 R(qi,qi+1) w = w1w2…wk q0=qs, qk=qa R(qs,q2) = a*b R(qa,q) = Ø R(q,qs) = Ø Sofya Raskhodnikova; based on slides by Nick Hopper

  5. NFA to GNFA ε ε ε NFA ε Add unique and distinct start and accept states Sofya Raskhodnikova; based on slides by Nick Hopper

  6. GNF to regular expression ε ε ε NFA While machine has more than 2 states: Pick an internal state, rip it out and relabelthe arrows with regular expressions to account for the missing state Sofya Raskhodnikova; based on slides by Nick Hopper

  7. b bb a q1 q2 a ε b ε b a ε q3 Sofya Raskhodnikova; based on slides by Nick Hopper

  8. b bb a q1 q2 a  ba a ε b ε b a ε Sofya Raskhodnikova; based on slides by Nick Hopper

  9. b = R(q1,q1) bb  (a  ba)b*a bb a q1 q2 a  ba ε ε b  (a  ba)b* b Sofya Raskhodnikova; based on slides by Nick Hopper

  10. Convert the NFA to a regular expression a, b (a  b)b*b(bb*b)* b q1 q2 (a  b)b*b ε b (a  b)b*b(bb*b)*a bb*b a b ε q3 ε Sofya Raskhodnikova; based on slides by Nick Hopper

  11. GNF to regular expression Formally: Add qstart and qaccept to create G Run CONVERT(G): If #states > 2 If #states = 2 return the expression on the arrow going from qstart to qaccept Sofya Raskhodnikova; based on slides by Nick Hopper

  12. GNF to regular expression Formally: Add qstart and qaccept to create G Run CONVERT(G): If #states > 2 select qripQ different from qstart and qaccept define Q = Q – {qrip} define Ras: R(qi,qj) = R(qi,qrip)R(qrip,qrip)*R(qrip,qj)  R(qi,qj) return CONVERT(G) Sofya Raskhodnikova; based on slides by Nick Hopper

  13. Conversion procedures NFA DFA definition Regular Language Regular Expression Sofya Raskhodnikova; based on slides by Nick Hopper

  14. REGULAR OR NOT? Design a NFA for the language: {0n1n | 0 < n · 2} {0n1n | 0 < n · k} {0n1n | n > 0}? n (For R a regexp, R2 means RR, and Rnmeans RR…R) Sofya Raskhodnikova; based on slides by Nick Hopper

  15. SOME LANGUAGES ARE NOT REGULAR! B = {0n1n | n ≥ 0} is NOT regular! Sofya Raskhodnikova; based on slides by Nick Hopper

  16. qk … q2k 2 F qj 0.. 011111…11 Proof (by contradiction) Let M be a k-state DFA that recognizes B. Consider the path M takes on 0k1k: q0 q1 q2… qiqi+1 0000… 00.. There must be i < j ≤ k such that qi = qj M accepts 0k-(j-i)1k B! So M does not recognize the language B. Sofya Raskhodnikova; based on slides by Nick Hopper

  17. REGULAR OR NOT? C = { w | w has equal number of 1s and 0s} NOT REGULAR D = { w | w has equal number of occurrences of 01 and 10} (0Σ*0)  (1Σ*1)  1  0  ε Sofya Raskhodnikova; based on slides by Nick Hopper

  18. THE PUMPING LEMMA Let L be a regular language with |L| =  Then there exists a length p such that if w  L and |w| ≥ p then w can be split into three parts w=xyz where: 1. |y| > 0 2. |xy| ≤ p 3. xyiz L for all i ≥ 0 Sofya Raskhodnikova; based on slides by Nick Hopper

  19. THE PUMPING LEMMA Example: Let L = 0*1* ; p = 1 w = 011 ε x = y = 0 if w  L and |w| ≥ p then w = xyz, where: z = 11 1. |y| > 0 2. |xy| ≤ p 3. xyiz L for all i ≥ 0 Let L = (0[1)2*; p = 2 2 w = 1 1 x = y = 2 z = ε Sofya Raskhodnikova; based on slides by Nick Hopper

  20. q|w| Proof of the pumping lemma Let M be a DFA that recognizes L. Let p be the number of states in M. Assume w  L is such that |w| ≥ p. 1. |y| > 0 2. |xy| ≤ p 3. xyiz L for all i ≥ 0 We show w = xyz y x z … q0 qi qj There must be j > i such that qi = qj. Sofya Raskhodnikova; based on slides by Nick Hopper

  21. USING THE PUMPING LEMMA Use the pumping lemma to prove that B = {0n1n | n ≥ 0} is not regular Hint: Assume B is regular, and try pumping w = 0P1P If B is regular, w can be split into w = xyz, where 1. |y| > 0 2. |xy| ≤ p 3. xyiz Bfor all i ≥ 0 xyyz has more 0s than 1s y is all 0s: Contradiction! Sofya Raskhodnikova; based on slides by Nick Hopper

  22. GENERAL STRATEGY Proof by contradiction – assume L is regular Then there is a pumping length p Find a string w 2 L with |w| ¸p Show that no matter how you choose xyz, w cannot be pumped! Conclude that L is not regular Sofya Raskhodnikova; based on slides by Nick Hopper

  23. USING THE PUMPING LEMMA PALINDROMES = { wwR | w 2 {0,1}* } is not regular. Proof: Assume … pumping length p Find a w 2 PALINDROMES longer than p 0P1P1P0P Show that … w cannot be pumped: 2p p p w= 00…0011…1100…00 y xyyz = 00…00011…1100…00 > p p 2p Sofya Raskhodnikova; based on slides by Nick Hopper

  24. USING THE PUMPING LEMMA PALINDROMES = { wwR | w 2 {0,1}* } is not regular. Proof: Assume … pumping length p Find a w 2 PALINDROMES longer than p 0P1P1P0P Show that … w cannot be pumped: If w = xyz with |xy| ·p then y = 0Jfor some J>0. Then xyyz = 0P+J12P0P PALINDROMES Contradiction! Sofya Raskhodnikova; based on slides by Nick Hopper

  25. PUMPING DOWN ProveC= { 0i1j | i > j ¸ 0} is not regular. Proof: Assume … pumping length p Find a w 2C longer than p 0P+11P Show that … w cannot be pumped: p p+1 w= 00…0011…11 y xz = 0…0011…11 xyyz = 00…00011…11 ·p > p+1 P P Sofya Raskhodnikova; based on slides by Nick Hopper

  26. PUMPING DOWN ProveC= { 0i1j | i > j ¸ 0} is not regular. Proof: Assume … pumping length p Find a w 2C longer than p 0P+11P If w = xyz with |xy| ·p then y = 0J for some J¸ 1. Then xy0z = xz = 0P+1-J1P C Contradiction! xz = 0…0011…11 Sofya Raskhodnikova; based on slides by Nick Hopper

More Related