15 251 great theoretical ideas in computer science
play

15-251 Great Theoretical Ideas in Computer Science Lecture 4: - PowerPoint PPT Presentation

15-251 Great Theoretical Ideas in Computer Science Lecture 4: Deterministic Finite Automaton (DFA), Part 2 January 26th, 2017 Formal definition: DFA A deterministic finite automaton (DFA) is a 5-tuple M M = ( Q, , , q 0 , F ) Q


  1. 15-251 Great Theoretical Ideas in Computer Science Lecture 4: Deterministic Finite Automaton (DFA), Part 2 January 26th, 2017

  2. Formal definition: DFA A deterministic finite automaton (DFA) is a 5-tuple M M = ( Q, Σ , δ , q 0 , F ) Q = { q 0 , q 1 , q 2 , q 3 } Σ = { 0 , 1 } δ : Q × Σ → Q δ 1 0 q 0 q 0 q 1 q 1 q 2 q 2 q 2 q 3 q 2 q 3 q 0 q 2 q 0 is the start state F = { q 1 , q 2 }

  3. Formal definition: DFA accepting a string Let be a DFA. M = ( Q, Σ , δ , q 0 , F ) For , q ∈ Q, w ∈ Σ ∗ δ ( q, w ) = state we end up in when we start at q and read . w accepts if δ ( q 0 , w ) ∈ F. M w Otherwise rejects . M w

  4. Definition: Regular languages Let be a DFA. M We let denote the set of strings that accepts . L ( M ) M Definition: A language is called regular if L for some DFA . L = L ( M ) M

  5. Non-regular languages Theorem: L = { 0 n 1 n : n ∈ N } The language is not regular. Theorem: { a 2 n : n ∈ N } The language is not regular. L =

  6. The big picture All languages P ( Σ ∗ ) Regular languages { 0 n 1 n : n ∈ N } { a 2 n : n ∈ N } . . . . . .

  7. Regular languages Questions: 1 . Are all languages regular? (Are all decision problems computable by a DFA?) 2 . Are there other ways to tell if a language is regular?

  8. Closure properties of regular languages

  9. Closed under complementation Proposition: Let be some finite alphabet. Σ If is regular, then so is . L = Σ ∗ \ L L ⊆ Σ ∗ Proof: If is regular, then there is a DFA L M = ( Q, Σ , δ , q 0 , F ) recognizing . Then L M 0 = ( Q, Σ , δ , q 0 , Q \ F ) recognizes . So is regular. L L

  10. Closed under complementation Closure properties can be used to show languages are not regular. Corollary: If is non -regular, then so is . L ⊆ Σ ∗ L Proof: By contrapositive: If is regular, then by the previous Proposition L is regular. L = L Examples: { 0 , 1 } ∗ \{ 0 n 1 n : n ∈ N } are non-regular. { a } ∗ \{ a 2 n : n ∈ N }

  11. Closed under union Theorem: Let be some finite alphabet. Σ If and are regular, then so is . L 2 ⊆ Σ ∗ L 1 ⊆ Σ ∗ L 1 ∪ L 2 Proof: Let be a DFA deciding M = ( Q, Σ , δ , q 0 , F ) L 1 M 0 = ( Q 0 , Σ , δ 0 , q 0 and be a DFA deciding . 0 , F 0 ) L 2 We construct a DFA M 00 = ( Q 00 , Σ , δ 00 , q 00 0 , F 00 ) that decides , as follows: L 1 ∪ L 2 . . .

  12. The mindset Imagine yourself as a DFA. Rules: 1) Can only scan the input once, from left to right. 2) Can only remember “constant” amount of information. should not change based on input length

  13. Step 1 : Imagining ourselves as a DFA

  14. Closed under union M 1 Example strings with even 0 q even L 1 = number of 1’s 1 1 strings with length L 2 = divisible by 3. 0 q odd 0 , 1 M 2 p 0 p 2 p 1 0 , 1 0 , 1

  15. Closed under union M 1 Input: 101001 0 q even 1 1 0 q odd 0 , 1 M 2 p 0 p 2 p 1 0 , 1 0 , 1

  16. Closed under union M 1 Input: 101001 0 q even 1 1 0 q odd 0 , 1 M 2 p 0 p 2 p 1 0 , 1 0 , 1

  17. Closed under union M 1 Input: 101001 0 q even 1 1 0 q odd 0 , 1 M 2 p 0 p 2 p 1 0 , 1 0 , 1

  18. Closed under union M 1 Input: 101001 0 q even 1 1 0 q odd 0 , 1 M 2 p 0 p 2 p 1 0 , 1 0 , 1

  19. Closed under union M 1 Input: 101001 0 q even 1 1 0 q odd 0 , 1 M 2 p 0 p 2 p 1 0 , 1 0 , 1

  20. Closed under union M 1 Input: 101001 0 q even 1 1 0 q odd 0 , 1 M 2 p 0 p 2 p 1 0 , 1 0 , 1

  21. Closed under union M 1 Input: 101001 0 q even 1 1 0 q odd 0 , 1 M 2 p 0 p 2 p 1 0 , 1 0 , 1

  22. Closed under union M 1 Input: 101001 0 q even 1 1 0 q odd 0 , 1 M 2 p 0 p 2 p 1 0 , 1 0 , 1

  23. Closed under union M 1 Input: 101001 0 q even 1 1 Accept 0 q odd 0 , 1 M 2 p 0 p 2 p 1 0 , 1 0 , 1

  24. Closed under union Main idea: M 1 Construct a DFA that keeps track of both at once. 0 q even 1 1 0 q odd 0 , 1 M 2 p 0 p 2 p 1 0 , 1 0 , 1

  25. Closed under union Main idea: Construct a DFA that keeps track of both at once. q even q even q even p 0 p 1 p 2 q odd q odd q odd p 0 p 1 p 2

  26. Closed under union Main idea: Construct a DFA that keeps track of both at once. q even q even q even p 0 p 1 p 2 0 ? q odd q odd q odd p 0 p 1 p 2

  27. Closed under union Main idea: Construct a DFA that keeps track of both at once. 0 q even q even q even p 0 p 1 p 2 q odd q odd q odd p 0 p 1 p 2

  28. Closed under union Main idea: Construct a DFA that keeps track of both at once. 0 q even q even q even p 0 p 1 p 2 1 ? q odd q odd q odd p 0 p 1 p 2

  29. Closed under union Main idea: Construct a DFA that keeps track of both at once. 0 q even q even q even p 0 p 1 p 2 1 q odd q odd q odd p 0 p 1 p 2

  30. Closed under union Main idea: Construct a DFA that keeps track of both at once. 0 q even q even q even p 0 p 1 p 2 1 ? 0 q odd q odd q odd p 0 p 1 p 2

  31. Closed under union Main idea: Construct a DFA that keeps track of both at once. 0 q even q even q even p 0 p 1 p 2 1 0 q odd q odd q odd p 0 p 1 p 2

  32. Closed under union Main idea: Construct a DFA that keeps track of both at once. 0 q even q even q even p 0 p 1 p 2 1 ? 1 0 q odd q odd q odd p 0 p 1 p 2

  33. Closed under union Main idea: Construct a DFA that keeps track of both at once. 0 q even q even q even p 0 p 1 p 2 1 1 0 q odd q odd q odd p 0 p 1 p 2

  34. Closed under union Main idea: Construct a DFA that keeps track of both at once. 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1

  35. Closed under union Input: 101001 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1

  36. Closed under union Input: 101001 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1

  37. Closed under union Input: 101001 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1

  38. Closed under union Input: 101001 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1

  39. Closed under union Input: 101001 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1

  40. Closed under union Input: 101001 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1

  41. Closed under union Input: 101001 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1

  42. Closed under union Input: 101001 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1

  43. Closed under union Input: 101001 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1

  44. Closed under union Input: 101001 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1

  45. Closed under union Input: 101001 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1

  46. Closed under union Input: 101001 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1

  47. Closed under union Input: 101001 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1

  48. Closed under union Input: 101001 Decision: Accept 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1

  49. Step 2 : Formally defining the DFA

  50. Closed under union Proof: Let be a DFA deciding M = ( Q, Σ , δ , q 0 , F ) L 1 M 0 = ( Q 0 , Σ , δ 0 , q 0 and be a DFA deciding . 0 , F 0 ) L 2 We construct a DFA M 00 = ( Q 00 , Σ , δ 00 , q 00 0 , F 00 ) that decides , as follows: L 1 ∪ L 2 - Q 00 = Q × Q 0 = { ( q, q 0 ) : q ∈ Q, q 0 ∈ Q 0 } - δ 00 (( q, q 0 ) , a ) = ( δ ( q, a ) , δ 0 ( q 0 , a )) - q 00 0 = ( q 0 , q 0 0 ) - F 00 = { ( q, q 0 ) : q ∈ F or q 0 ∈ F 0 } It remains to show that . L ( M 00 ) = L 1 ∪ L 2 L ( M 00 ) ⊆ L 1 ∪ L 2 : . . . L 1 ∪ L 2 ⊆ L ( M 00 ) : . . .

  51. Closed under intersection Corollary: Let be some finite alphabet. Σ If and are regular, then so is . L 2 ⊆ Σ ∗ L 1 ⊆ Σ ∗ L 1 ∩ L 2 Proof: Follows from: - L 1 ∩ L 2 = L 1 ∪ L 2 - regular languages are closed under complementation - regular languages are closed under union

  52. Closed under intersection Closure properties can be used to show languages are not regular. Example: Let be the language consisting of all words L ⊆ { 0 , 1 } ∗ with an equal number of 0’s and 1’s. We claim is not regular. Suppose it was regular. L { 0 n 1 m : n, m ∈ N } { 0 n 1 n : n ∈ N } ∩ L = regular regular regular contradiction

Recommend


More recommend