cs 301
play

CS 301 Lecture 06 Nonregular languages and the pumping lemma - PowerPoint PPT Presentation

CS 301 Lecture 06 Nonregular languages and the pumping lemma Stephen Checkoway February 5, 2018 1 / 23 DFA M 1 b a a q 0 q 1 q 2 b a,b q 3 a,b 2 / 23 DFA M 1 Strings in the language b aa a a q 0 q 1 q 2 aba abba


  1. CS 301 Lecture 06 – Nonregular languages and the pumping lemma Stephen Checkoway February 5, 2018 1 / 23

  2. DFA M 1 b a a q 0 q 1 q 2 b a,b q 3 a,b 2 / 23

  3. DFA M 1 Strings in the language b • aa a a q 0 q 1 q 2 • aba • abba • abbba b a,b • ab k a for all k ≥ 0 q 3 a,b 2 / 23

  4. DFA M 1 Strings in the language b • aa a a q 0 q 1 q 2 • aba • abba • abbba b a,b • ab k a for all k ≥ 0 q 3 All of the strings w ∈ L ( M 1 ) s.t. ∣ w ∣ ≥ 3 a,b have a curious property: w can be written as w = xyz where 1 ∣ y ∣ > 0 and 2 xy i z ∈ L ( M 1 ) for all i ≥ 0 2 / 23

  5. DFA M 2 a b q 0 q 1 q 2 a,b a a b q 3 q 4 a,b b 3 / 23

  6. DFA M 2 a b Again, strings w ∈ L ( M 2 ) s.t. ∣ w ∣ ≥ 3 can q 0 q 1 q 2 be written as w = xyz with ∣ y ∣ > 0 and a,b xy i z ∈ L ( M 2 ) . a a b E.g., x = ba , y = ba , z = ε q 3 q 4 a,b • xy 0 z = ba b • xy 1 z = baba • xy 2 z = bababa Strings in the language include • a • abb • . . . • b • baba • ba • abbba • aba • bababb 3 / 23

  7. DFA M 3 a,b a b b a q 0 q 1 q 2 4 / 23

  8. DFA M 3 a,b a b b a q 0 q 1 q 2 L ( M 3 ) = { a m b n ∣ m, n ≥ 0 } Strings w ∈ L ( M 3 ) s.t. ∣ w ∣ ≥ 1 have the same property. E.g., x = ε , y = a , z = abb • xy 0 z = abb • xy 1 z = aabb • xy 2 z = aaabb • xy i z = a i + 1 bb 4 / 23

  9. DFA M 3 a,b a b b a q 0 q 1 q 2 L ( M 3 ) = { a m b n ∣ m, n ≥ 0 } Strings w ∈ L ( M 3 ) s.t. ∣ w ∣ ≥ 1 have the same property. E.g., x = ε , y = a , z = abb Not every way we split the strings works • xy 0 z = abb x = a , y = ab , z = b • xy 0 z = ab ∈ L ( M 3 ) • xy 1 z = aabb • xy 1 z = aabb ∈ L ( M 3 ) • xy 2 z = aaabb • xy 2 z = aababb ∉ L ( M 3 ) • xy i z = a i + 1 bb 4 / 23

  10. DFA M 4 a q 0 q 3 a,b b a,b q 1 q 2 a,b 5 / 23

  11. DFA M 4 a q 0 q 3 a,b b a,b q 1 q 2 a,b L ( M 4 ) = { ε, b , ba , bb } L ( M 4 ) doesn’t appear to have this property (unless we say it holds for all strings in L ( M 4 ) with length at least 3 because there are no such strings) 5 / 23

  12. What do M 1 , M 2 , and M 3 have that M 4 lacks? b M 1 : M 2 : a a a b q 0 q 1 q 2 q 0 q 1 q 2 a,b a a b b a,b q 3 q 3 q 4 a,b b M 4 : a,b a q 0 q 3 a,b a,b a b b a,b M 3 : b a q 1 q 2 q 0 q 1 q 2 a,b 6 / 23

  13. Repeated state for some string in the language M 1 , M 2 , and M 3 all have a repeated state in some accepting computation b a a q 0 q 1 q 2 b a,b q 3 a,b On input aba , M 1 goes through states q 0 , q 1 , q 1 , q 2 State q 1 is repeated so we can repeat it 0 or more times by following the loop on b 7 / 23

  14. M 2 a b q 0 q 1 q 2 a,b a a b q 3 q 4 a,b b On input baba , M 2 goes through states q 0 , q 3 , q 1 , q 2 , q 1 State q 1 is repeated so we can perform the q 1 → q 2 → q 1 sequence corresponding to input ba 0 or more times 8 / 23

  15. M 3 a,b a b b a q 0 q 1 q 2 On input aabb , M 2 goes through states q 0 , q 0 , q 0 , q 1 , q 1 State q 0 is repeated so we can perform the q 0 → q 0 sequence corresponding to input a 0 or more times 9 / 23

  16. M 4 a q 0 q 3 a,b b a,b q 1 q 2 a,b None of the strings in L ( M 4 ) lead to a repeated state As mentioned, we can “cheat” and say that the property holds for strings of length at least 3 since L ( M 4 ) has no strings of length at least 3 10 / 23

  17. Pumpable languages A language A is said to be pumpable if there exists an integer p > 0 s.t. for all strings w ∈ A with ∣ w ∣ ≥ p , there exist strings x, y, z ∈ Σ ∗ with w = xyz s.t. 1 xy i z ∈ A for all i ≥ 0 2 ∣ y ∣ > 0 3 ∣ xy ∣ ≤ p The integer p is called the pumping length 11 / 23

  18. Pumpable languages A language A is said to be pumpable if there exists an integer p > 0 s.t. for all strings w ∈ A with ∣ w ∣ ≥ p , there exist strings x, y, z ∈ Σ ∗ with w = xyz s.t. 1 xy i z ∈ A for all i ≥ 0 2 ∣ y ∣ > 0 3 ∣ xy ∣ ≤ p The integer p is called the pumping length Almost certainly the most complicated mathematical definition you’ve seen: ∃ p > 0 . ∀ w ∈ A. ∃ x, y, z ∈ Σ ∗ . ∀ i ≥ 0 . [ . . . ] Contrast with the definition of a continuous function f ∶ R → R from calculus ∀ ε > 0 . ∃ δ > 0 . [ . . . ] 11 / 23

  19. A two-player game Player One ( ∃ ) Player Two ( ∀ ) Claims A is pumpable with p.l. p A, p − − − − − − − − − − − − − − − → Picks w ∈ A s.t. ∣ w ∣ ≥ p w − − − − − − − − − − − − − − − ← Picks x, y, z s.t. w = xyz x, y, z − − − − − − − − − − − − − − − → Checks 3 conditions Player One “wins” the game if 1 xy i z ∈ A for all i ≥ 0 2 ∣ y ∣ > 0 3 ∣ xy ∣ ≤ p Player One can win if and only if A is pumpable 12 / 23

  20. Pumping lemma for regular languages Theorem (Pumping lemma) Regular languages are pumpable. Note: The converse is not true! There are pumpable languages that are not regular 13 / 23

  21. Proof Let M = ( Q, Σ , δ, q 0 , F ) be a DFA with L ( M ) = A and set p = ∣ Q ∣ . If A contains no strings of length at least p , then we’re finished since A is pumpable with pumping length p . 14 / 23

  22. Proof Let M = ( Q, Σ , δ, q 0 , F ) be a DFA with L ( M ) = A and set p = ∣ Q ∣ . If A contains no strings of length at least p , then we’re finished since A is pumpable with pumping length p . Otherwise, let w be a string in A of length n ≥ p . Write w = w 1 w 2 ⋯ w n where each w i ∈ Σ . Let r 0 , r 1 , . . . , r n be the accepting computation of M on w . By the pigeonhole principle, in the first p + 1 states ( r 0 , r 1 , . . . , r p ), there are states r j = r k s.t. 0 ≤ j < k ≤ p . 14 / 23

  23. Proof Set x = w 1 w 2 ⋯ w j y = w j + 1 w j + 2 ⋯ w k z = w k + 1 w k + 2 ⋯ w n . x y z �������������������������������������������������������������������������������������� ��������������������������������������������������������������������������������������������������������������������� ������������������������������������������������������������������������������������������������������������������������ input: w 1 w 2 ⋯ w j w j + 1 w j + 2 ⋯ w k w k + 1 w k + 2 ⋯ w n states: r 0 r 1 r 2 ⋯ r j r j + 1 r j + 2 ⋯ r k r k + 1 r k + 2 ⋯ r n Remember δ ( r m − 1 , w m ) = r m for all 1 ≤ m ≤ n 2 ∣ y ∣ = k − j > 0 3 ∣ xy ∣ ≤ p because k ≤ p 15 / 23

  24. Proof ? 1 xy i z ∈ A δ ( r m − 1 , w m ) = r m ∀ m 16 / 23

  25. Proof ? 1 xy i z ∈ A δ ( r m − 1 , w m ) = r m ∀ m i = 0 x z �������������������������������������������������������������������������������������� ������������������������������������������������������������������������������������������������������������������������ w 1 w 2 ⋯ w j w k + 1 w k + 2 ⋯ w n r 0 r 1 r 2 ⋯ r j 16 / 23

  26. Proof ? 1 xy i z ∈ A δ ( r m − 1 , w m ) = r m ∀ m δ ( r j , w k + 1 ) = δ ( r k , w k + 1 ) = r k + 1 i = 0 x z �������������������������������������������������������������������������������������� ������������������������������������������������������������������������������������������������������������������������ w 1 w 2 ⋯ w j w k + 1 w k + 2 ⋯ w n r 0 r 1 r 2 ⋯ r j 16 / 23

Recommend


More recommend