dfa minimization pumping lemma
play

DFA Minimization, Pumping Lemma CSCI 3130 Formal Languages and - PowerPoint PPT Presentation

1/27 DFA Minimization, Pumping Lemma CSCI 3130 Formal Languages and Automata Theory Siu On CHAN Chinese University of Hong Kong Fall 2015 2/27 There is a simpler one L = strings ending in 111 0 3/27 1 0 1 0 1 0 1 Can we do it in


  1. 1/27 DFA Minimization, Pumping Lemma CSCI 3130 Formal Languages and Automata Theory Siu On CHAN Chinese University of Hong Kong Fall 2015

  2. 2/27 There is a simpler one… L = strings ending in 111

  3. 0 3/27 1 0 1 0 1 0 1 Can we do it in 3 states? L = strings ending in 111 q 0 q 1 q 2 q 3

  4. 4/27 Even smaller DFA? Intuitively, needs to remember number of ones recently read We will show In other words are all distinguishable by L Then use this result from last lecture: must have at least n states L = strings ending in 111 ε, 1 , 11 , 111 are pairwise distinguishable by L ( ε, 1 ) , ( ε, 11 ) , ( ε, 111 ) , ( 1 , 11 ) , ( 1 , 111 ) , ( 11 , 111 ) If strings x 1 , . . . , x n are pairwise distinguishable by L , any DFA accepting L

  5. 5/27 Recap: distinguishable strings What do we mean by “1 and 11 are distinguishable”? We saw from last lecture If x and y are distinguishable by L , any DFA accepting L must reach different states upon reading x and y x y z ( x , y ) are distinguishable by L if there is string z such that xz ∈ L and yz / ∈ L (or the other way round) ✗

  6. More generally, why are 1 i and 1 j distinguishable by L ? Thus our 4-state DFA is minimal Take z 1 11 111 are pairwise distinguishable by L L j 1 j 1 L j 1 i 1 j 1 6/27 Distinguishable strings i L 111 L 11 1 Take z Why are 1 and 11 distinguishable by L ? j L = strings ending in 111

  7. 6/27 Distinguishable strings Why are 1 and 11 distinguishable by L ? L = strings ending in 111 Take z = 1 11 / ∈ L 111 ∈ L More generally, why are 1 i and 1 j distinguishable by L ? (0 � i < j � 3) Take z = 1 3 − j 1 i 1 3 − j / 1 j 1 3 − j ∈ L ∈ L ε, 1 , 11 , 111 are pairwise distinguishable by L Thus our 4-state DFA is minimal

  8. 7/27 DFA minimization 0 1 0 1 0 1 0 1 q 0 q 1 q 2 q 3 We now show how to turn any DFA for L into the minimal DFA for L

  9. 8/27 1 Indistinguishable strings may end up in the same state Distinguishable strings must be in different states 1 0 1 0 0 Minimal DFA and distinguishability 1 0 q 0 q 1 q 2 q 3 DFA minimial ⇔ Every pair of states is distinguishable

  10. 9/27 Distinguishable states z k reject … r z k accept … q Two states q and r are distinguishable if one accepts, but the other rejects z k − 1 z 1 z 2 z 1 z 2 z k − 1 on the same continuation string z = z 1 . . . z k ,

  11. 10/27 0 indistinguishable pairs indistinguishable distinguishable by 0 distinguishable by 0 distinguishable by distinguishable by distinguishable by Which of the following pairs are distinguishable? by which string? 0,1 Examples of distinguishable states 1 0,1 q 0,1 0 q 1 can be merged 0,1 0 1 q q 0 q 2 q 1 q 3 ( q 0 , q 3 ) ( q 1 , q 3 ) ( q 2 , q 3 ) ( q 1 , q 2 ) ( q 0 , q 2 ) ( q 0 , q 1 )

  12. 10/27 q indistinguishable pairs Which of the following pairs are distinguishable? by which string? 0,1 0,1 1 0 Examples of distinguishable states q q 1 0 0 can be merged 1 0,1 0,1 q 0 q 2 q 1 q 3 ( q 0 , q 3 ) distinguishable by ε ( q 1 , q 3 ) distinguishable by ε ( q 2 , q 3 ) distinguishable by ε ( q 1 , q 2 ) distinguishable by 0 ( q 0 , q 2 ) distinguishable by 0 ( q 0 , q 1 ) indistinguishable

  13. 10/27 1 indistinguishable pairs Which of the following pairs are distinguishable? by which string? 0,1 0,1 1 0 Examples of distinguishable states can be merged 0 0,1 0,1 1 0 q 2 q 0 q 2 q 01 q 1 q 3 q 3 ( q 0 , q 3 ) distinguishable by ε ( q 1 , q 3 ) distinguishable by ε ( q 2 , q 3 ) distinguishable by ε ( q 1 , q 2 ) distinguishable by 0 ( q 0 , q 2 ) distinguishable by 0 ( q 0 , q 1 ) indistinguishable

  14. 11/27 Finding (in)distinguishable states Unmarked pairs are indistinguishable Phase 3: X X a a r q Phase 2: X q Phase 1: Merge them into groups If q is accepting and q ′ is rejecting q ′ Mark ( q , q ′ ) as distinguishable (X) If ( q , q ′ ) are marked q ′ Mark ( r , r ′ ) as distinguishable (X) r ′

  15. 11/27 Finding (in)distinguishable states Unmarked pairs are indistinguishable Phase 3: X X a a r q Phase 2: X q Phase 1: Merge them into groups If q is accepting and q ′ is rejecting q ′ Mark ( q , q ′ ) as distinguishable (X) If ( q , q ′ ) are marked q ′ Mark ( r , r ′ ) as distinguishable (X) r ′

  16. 11/27 Finding (in)distinguishable states Unmarked pairs are indistinguishable Phase 3: X X a a r q Phase 2: X q Phase 1: Merge them into groups If q is accepting and q ′ is rejecting q ′ Mark ( q , q ′ ) as distinguishable (X) If ( q , q ′ ) are marked q ′ Mark ( r , r ′ ) as distinguishable (X) r ′

  17. 12/27 1 q (Phase 1) 0 1 0 1 1 0 DFA minimization: example 0 1 0 0 1 is distinguishable from all other states 1 0 q 00 q 0 q 0 q 1 q 01 q 00 q 01 q ε q 10 q 10 q 1 q 11 q 11 q ε q 0 q 1 q 00 q 01 q 10

  18. 12/27 1 (Phase 1) X X X X X X 0 1 0 DFA minimization: example 1 0 1 0 0 1 1 0 0 1 q 00 q 0 q 0 q 1 q 01 q 00 q 01 q ε q 10 q 10 q 1 q 11 q 11 q ε q 0 q 1 q 00 q 01 q 10 q 11 is distinguishable from all other states

  19. 13/27 0 (Phase 2) 1 0 X X X X X X 0 1 DFA minimization: example 1 1 0 1 0 1 0 1 1 0 0 q 00 q 0 q 0 q 1 q 01 q 00 q 01 q ε q 10 q 10 q 1 q 11 q 11 q ε q 0 q 1 q 00 q 01 q 10 Looking at ( r , r ′ ) = ( q ε , q 0 ) Neither ( q 0 , q 00 ) nor ( q 1 , q 01 ) are distinguishable

  20. 14/27 1 (Phase 2) X 1 0 X X X X X X 0 DFA minimization: example 0 1 1 0 1 0 1 0 1 0 0 1 q 00 q 0 q 0 q 1 q 01 q 00 q 01 q ε q 10 q 10 q 1 q 11 q 11 q ε q 0 q 1 q 00 q 01 q 10 Looking at ( r , r ′ ) = ( q ε , q 1 ) ( q 1 , q 11 ) is distinguishable

  21. 15/27 X DFA minimization: example X X X X X X X 1 X X X X X X (Phase 2) Afuer going through the whole table once 0 Now we make another pass 0 1 0 0 1 1 1 1 0 0 0 1 q 00 q 0 q 0 q 1 q 01 q 00 q 01 q ε q 10 q 10 q 1 q 11 q 11 q ε q 0 q 1 q 00 q 01 q 10

  22. 16/27 1 X X X X X X X X DFA minimization: example X 0 1 0 1 0 X X (Phase 2) 1 0 X X 0 1 0 1 1 0 1 0 X q 00 q 0 q 0 q 1 q 01 q 00 q 01 q ε q 10 q 10 q 1 q 11 q 11 q ε q 0 q 1 q 00 q 01 q 10 Looking at ( r , r ′ ) = ( q ε , q 0 ) Neither ( q 0 , q 00 ) nor ( q 1 , q 01 ) are distinguishable

  23. 17/27 1 X X X X X X X X DFA minimization: example X 0 1 0 1 0 X X (Phase 2) 1 0 X X 0 1 0 1 1 0 1 0 X q 00 q 0 q 0 q 1 q 01 q 00 q 01 q ε q 10 q 10 q 1 q 11 q 11 q ε q 0 q 1 q 00 q 01 q 10 Looking at ( r , r ′ ) = ( q ε , q 00 ) Neither ( q 0 , q 00 ) nor ( q 1 , q 01 ) are distinguishable

  24. 18/27 X DFA minimization: example X X X X X X X 1 X X X X X X (Phase 2) Nothing changes in the second pass 0 Ready to go to Phase 3 0 1 0 0 1 1 1 1 0 0 0 1 q 00 q 0 q 0 q 1 q 01 q 00 q 01 q ε q 10 q 10 q 1 q 11 q 11 q ε q 0 q 1 q 00 q 01 q 10

  25. 19/27 X X X X X X X X X X X DFA minimization: example X X A A A A A A B (Phase 3) X Merge states into groups (also called equivalence classes) 1 1 0 0 1 0 1 0 1 1 0 0 0 1 q 00 q 0 q 0 q 1 q 01 q 00 q 01 q ε q 10 q 10 q 1 q 11 q 11 q ε q 0 q 1 q 00 q 01 q 10

  26. 20/27 A X X X X X X X X X X X A A X A A A B Minimized DFA: q A q B q C 0 1 0 1 1 X X DFA minimization: example 1 0 0 1 1 0 1 1 0 0 1 0 0 1 0 q 00 q 0 q 0 q 1 q 01 q 00 q 01 q ε q 10 q 10 q 1 q 11 q 11 q ε q 0 q 1 q 00 q 01 q 10

  27. 21/27 Why it works X X X X X z k z k … r … q Why have we found all distinguishable pairs? Because we work backwards z k − 1 z 1 z 2 z k − 1 z 1 z 2

  28. 21/27 Why it works X X X X X z k z k … r … q Why have we found all distinguishable pairs? Because we work backwards z k − 1 z 1 z 2 z k − 1 z 1 z 2

  29. 21/27 Why it works X X X X X z k z k … r … q Why have we found all distinguishable pairs? Because we work backwards z k − 1 z 1 z 2 z k − 1 z 1 z 2

  30. 21/27 Why it works X X X X X z k z k … r … q Why have we found all distinguishable pairs? Because we work backwards z k − 1 z 1 z 2 z k − 1 z 1 z 2

  31. 22/27 Pumping Lemma

  32. 23/27 Pumping lemma Another way to show some language is irregular Example Suppose we have a DFA M for L Something must be wrong with this DFA L = { 0 n 1 n | n � 0 } is irregular We reason by contradiction: M must accept some strings outside L

  33. Since M has n states, it must revisit one of its states while reading 0 n The DFA will also accept strings that go around the loop multiple times 24/27 Towards a contradiction Imaginary DFA M with n states x 0 0 0 0 0 0 r 1 n The DFA must contain a loop with 0s But such strings have more 0s than 1s and cannot be in L What happens when M gets input x = 0 n +1 1 n +1 ? M accepts x because x ∈ L

  34. The DFA must contain a loop with 0s The DFA will also accept strings that go around the loop multiple times 24/27 Towards a contradiction Imaginary DFA M with n states 0 0 0 0 0 But such strings have more 0s than 1s and cannot be in L 0 r 1 n +1 What happens when M gets input x = 0 n +1 1 n +1 ? M accepts x because x ∈ L Since M has n states, it must revisit one of its states while reading 0 n +1

Recommend


More recommend