regular languages and finite state automata
play

Regular Languages and Finite State Automata Data structures and - PowerPoint PPT Presentation

Regular Languages and Finite State Automata Data structures and algorithms for Computational Linguistics III ar ltekin ccoltekin@sfs.uni-tuebingen.de University of Tbingen Seminar fr Sprachwissenschaft Winter Semester


  1. Introduction DFA NFA Regular languages Minimization Regular expressions Dealing with non-determinism Ç. Çöltekin, SfS / University of Tübingen WS 19–20 12 / 56 • Follow one of the links, store alternatives, and backtrack on failure • Follow all options in parallel • Use dynamic programming (e.g., as in chart parsing)

  2. Introduction 4. At the end of input a Agenda 2. Take the next input, place all possible actions to an agenda 3. Get the next action from the agenda, act Accept if in an accepting state DFA Reject not in accepting state & agenda empty Backtrack otherwise Ç. Çöltekin, SfS / University of Tübingen WS 19–20 b a Input: 0 NFA Regular languages Minimization Regular expressions NFA recognition as search (with backtracking) 1 a,b 2 a,b a,b a,b a a 13 / 56 1. Start at q 0

  3. Introduction 4. At the end of input a Agenda 2. Take the next input, place all possible actions to an agenda 3. Get the next action from the agenda, act Accept if in an accepting state a Reject not in accepting state & agenda empty Backtrack otherwise Ç. Çöltekin, SfS / University of Tübingen WS 19–20 DFA b Input: 1 NFA Regular languages Minimization Regular expressions NFA recognition as search (with backtracking) 0 2 a,b a,b a,b a,b a a 13 / 56 ( q 0 , 1 ) ( q 1 , 1 ) 1. Start at q 0

  4. Introduction 4. At the end of input a Agenda 2. Take the next input, place all possible actions to an agenda 3. Get the next action from the agenda, act Accept if in an accepting state a Reject not in accepting state & agenda empty Backtrack otherwise Ç. Çöltekin, SfS / University of Tübingen WS 19–20 DFA b Input: 1 NFA Regular languages Minimization Regular expressions NFA recognition as search (with backtracking) 0 2 a,b a,b a,b a,b a a 13 / 56 ( q 0 , 1 ) ( q 1 , 1 ) 1. Start at q 0

  5. Introduction 4. At the end of input a Agenda 2. Take the next input, place all possible actions to an agenda 3. Get the next action from the agenda, act Accept if in an accepting state a Reject not in accepting state & agenda empty Backtrack otherwise Ç. Çöltekin, SfS / University of Tübingen WS 19–20 DFA b Input: 2 NFA Regular languages Minimization Regular expressions NFA recognition as search (with backtracking) 0 1 a,b a,b a,b a,b a a 13 / 56 ( q 0 , 2 ) ( q 1 , 2 ) 1. Start at q 0 ( q 1 , 1 )

  6. Introduction 4. At the end of input a Agenda 2. Take the next input, place all possible actions to an agenda 3. Get the next action from the agenda, act Accept if in an accepting state a Reject not in accepting state & agenda empty Backtrack otherwise Ç. Çöltekin, SfS / University of Tübingen WS 19–20 DFA b Input: 2 NFA Regular languages Minimization Regular expressions NFA recognition as search (with backtracking) 0 1 a,b a,b a,b a,b a a 13 / 56 ( q 0 , 2 ) ( q 1 , 2 ) 1. Start at q 0 ( q 1 , 1 )

  7. Introduction 4. At the end of input DFA Agenda 2. Take the next input, place all possible actions to an agenda 3. Get the next action from the agenda, act Accept if in an accepting state a Reject not in accepting state & agenda empty Backtrack otherwise Ç. Çöltekin, SfS / University of Tübingen WS 19–20 b a Input: 2 NFA Regular languages Minimization Regular expressions NFA recognition as search (with backtracking) 0 1 a,b a,b a,b a,b a a 13 / 56 ( q 0 , 3 ) ( q 1 , 3 ) 1. Start at q 0 ( q 1 , 2 ) ( q 1 , 1 )

  8. Introduction 4. At the end of input DFA Agenda 2. Take the next input, place all possible actions to an agenda 3. Get the next action from the agenda, act Accept if in an accepting state a Reject not in accepting state & agenda empty Backtrack otherwise Ç. Çöltekin, SfS / University of Tübingen WS 19–20 b a Input: 2 NFA Regular languages Minimization Regular expressions NFA recognition as search (with backtracking) 0 1 a,b a,b a,b a,b a a 13 / 56 ( q 0 , 3 ) ( q 1 , 3 ) 1. Start at q 0 ( q 1 , 2 ) ( q 1 , 1 )

  9. Introduction 4. At the end of input a Agenda 2. Take the next input, place all possible actions to an agenda 3. Get the next action from the agenda, act Accept if in an accepting state a Reject not in accepting state & agenda empty Backtrack otherwise Ç. Çöltekin, SfS / University of Tübingen WS 19–20 DFA b Input: 2 NFA Regular languages Minimization Regular expressions NFA recognition as search (with backtracking) 0 1 a,b a,b a,b a,b a a 13 / 56 ( q 1 , 3 ) ( q 1 , 2 ) 1. Start at q 0 ( q 1 , 1 )

  10. Introduction 4. At the end of input a Agenda 2. Take the next input, place all possible actions to an agenda 3. Get the next action from the agenda, act Accept if in an accepting state a Reject not in accepting state & agenda empty Backtrack otherwise Ç. Çöltekin, SfS / University of Tübingen WS 19–20 DFA b Input: 2 NFA Regular languages Minimization Regular expressions NFA recognition as search (with backtracking) 0 1 a,b a,b a,b a,b a a 13 / 56 ( q 1 , 3 ) ( q 1 , 2 ) 1. Start at q 0 ( q 1 , 1 )

  11. Introduction 4. At the end of input a Agenda 2. Take the next input, place all possible actions to an agenda 3. Get the next action from the agenda, act Accept if in an accepting state a Reject not in accepting state & agenda empty Backtrack otherwise Ç. Çöltekin, SfS / University of Tübingen WS 19–20 DFA b Input: 1 NFA Regular languages Minimization Regular expressions NFA recognition as search (with backtracking) 0 2 a,b a,b a,b a,b a a 13 / 56 ( q 1 , 2 ) ( q 1 , 1 ) 1. Start at q 0

  12. Introduction 4. At the end of input a Agenda 2. Take the next input, place all possible actions to an agenda 3. Get the next action from the agenda, act Accept if in an accepting state a Reject not in accepting state & agenda empty Backtrack otherwise Ç. Çöltekin, SfS / University of Tübingen WS 19–20 DFA b Input: 1 NFA Regular languages Minimization Regular expressions NFA recognition as search (with backtracking) 0 2 a,b a,b a,b a,b a a 13 / 56 ( q 1 , 2 ) ( q 1 , 1 ) 1. Start at q 0

  13. Introduction 4. At the end of input a Agenda 2. Take the next input, place all possible actions to an agenda 3. Get the next action from the agenda, act Accept if in an accepting state a Reject not in accepting state & agenda empty Backtrack otherwise Ç. Çöltekin, SfS / University of Tübingen WS 19–20 DFA b Input: 2 NFA Regular languages Minimization Regular expressions NFA recognition as search (with backtracking) 0 1 a,b a,b a,b a,b a a 13 / 56 ( q 2 , 3 ) ( q 1 , 3 ) 1. Start at q 0 ( q 1 , 1 )

  14. Introduction 4. At the end of input a Agenda 2. Take the next input, place all possible actions to an agenda 3. Get the next action from the agenda, act Accept if in an accepting state a Reject not in accepting state & agenda empty Backtrack otherwise Ç. Çöltekin, SfS / University of Tübingen WS 19–20 DFA b Input: 2 NFA Regular languages Minimization Regular expressions NFA recognition as search (with backtracking) 0 1 a,b a,b a,b a,b a a 13 / 56 ( q 2 , 3 ) ( q 1 , 3 ) 1. Start at q 0 ( q 1 , 1 )

  15. Introduction 4. At the end of input a Agenda 2. Take the next input, place all possible actions to an agenda 3. Get the next action from the agenda, act Accept if in an accepting state a Reject not in accepting state & agenda empty Backtrack otherwise Ç. Çöltekin, SfS / University of Tübingen WS 19–20 DFA b Input: 1 NFA Regular languages Minimization Regular expressions NFA recognition as search (with backtracking) 0 2 a,b a,b a,b a,b a a 13 / 56 ( q 1 , 3 ) ( q 1 , 1 ) 1. Start at q 0

  16. Introduction summary WS 19–20 SfS / University of Tübingen Ç. Çöltekin, DFA – Complexity is worse if we want to enumerate all derivations NFA recognition as search Regular expressions Minimization Regular languages NFA 14 / 56 • Worst time complexity is exponential • We used a stack as agenda , performing a depth-fjrst search • A queue would result in breadth-fjrst search • If we have a reasonable heuristic A* search may be an option • Machine learning methods may also guide fjnding a fast or the best solution

  17. Introduction Input: WS 19–20 SfS / University of Tübingen Ç. Çöltekin, fjnite-state . Note: the process is deterministic , and of the input, accept 3. If an accepting state is marked at the end next states 2. Take the next input, mark all possible b a b a a,b DFA 0 NFA Regular languages Minimization Regular expressions NFA recognition parallel version 1 a 2 a,b a,b a,b a 15 / 56 1. Start at q 0

  18. Introduction Input: WS 19–20 SfS / University of Tübingen Ç. Çöltekin, fjnite-state . Note: the process is deterministic , and of the input, accept 3. If an accepting state is marked at the end next states 2. Take the next input, mark all possible b a b a a,b DFA 0 NFA Regular languages Minimization Regular expressions NFA recognition parallel version 1 a 2 a,b a,b a,b a 15 / 56 1. Start at q 0

  19. Introduction Input: WS 19–20 SfS / University of Tübingen Ç. Çöltekin, fjnite-state . Note: the process is deterministic , and of the input, accept 3. If an accepting state is marked at the end next states 2. Take the next input, mark all possible b a b a a,b DFA 0 NFA Regular languages Minimization Regular expressions NFA recognition parallel version 1 a 2 a,b a,b a,b a 15 / 56 1. Start at q 0

  20. Introduction Input: WS 19–20 SfS / University of Tübingen Ç. Çöltekin, fjnite-state . Note: the process is deterministic , and of the input, accept 3. If an accepting state is marked at the end next states 2. Take the next input, mark all possible b a b a a,b DFA 0 NFA Regular languages Minimization Regular expressions NFA recognition parallel version 1 a 2 a,b a,b a,b a 15 / 56 1. Start at q 0

  21. Introduction Input: WS 19–20 SfS / University of Tübingen Ç. Çöltekin, fjnite-state . Note: the process is deterministic , and of the input, accept 3. If an accepting state is marked at the end next states 2. Take the next input, mark all possible b a b a a,b DFA 0 NFA Regular languages Minimization Regular expressions NFA recognition parallel version 1 a 2 a,b a,b a,b a 15 / 56 1. Start at q 0

  22. Introduction Input: WS 19–20 SfS / University of Tübingen Ç. Çöltekin, fjnite-state . Note: the process is deterministic , and of the input, accept 3. If an accepting state is marked at the end next states 2. Take the next input, mark all possible b a b a a,b DFA 0 NFA Regular languages Minimization Regular expressions NFA recognition parallel version 1 a 2 a,b a,b a,b a 15 / 56 1. Start at q 0

  23. Introduction DFA: WS 19–20 SfS / University of Tübingen Ç. Çöltekin, b a b a a b 2 1 0 b DFA a a,b 2 1 0 NFA: An exercise Regular expressions Minimization Regular languages NFA 16 / 56 Construct an NFA and a DFA for the language over Σ = { a , b } where all sen- tences end with ab .

  24. Introduction DFA: WS 19–20 SfS / University of Tübingen Ç. Çöltekin, b a b a a b 2 1 0 b DFA a a,b 2 1 0 NFA: An exercise Regular expressions Minimization Regular languages NFA 16 / 56 Construct an NFA and a DFA for the language over Σ = { a , b } where all sen- tences end with ab .

  25. Introduction a WS 19–20 SfS / University of Tübingen Ç. Çöltekin, a b b a a 2 1 0 b DFA a 2 1 0 Regular expressions Minimization Regular languages NFA 17 / 56 One more complication: ϵ transitions • An extension of NFA, ϵ -NFA, allows moving without consuming an input symbol, indicated by an ϵ -transition (sometimes called a λ -transition) • Any ϵ -NFA can be converted to an NFA ϵ

  26. Introduction a WS 19–20 SfS / University of Tübingen Ç. Çöltekin, a b b a a 2 1 0 b DFA a 2 1 0 Regular expressions Minimization Regular languages NFA 17 / 56 One more complication: ϵ transitions • An extension of NFA, ϵ -NFA, allows moving without consuming an input symbol, indicated by an ϵ -transition (sometimes called a λ -transition) • Any ϵ -NFA can be converted to an NFA ϵ

  27. Introduction b WS 19–20 SfS / University of Tübingen Ç. Çöltekin, work on this automaton? b a a DFA a 4 3 2 1 0 Regular expressions Minimization Regular languages NFA 18 / 56 ϵ -transitions need attention ϵ b, ϵ • How does the (depth-fjrst) NFA recognition algorithm we described earlier • Can we do without ϵ transitions?

  28. Introduction a 0 1 2 a b a a arc(s) to all states in the -closure of b b a Ç. Çöltekin, SfS / University of Tübingen WS 19–20 the state Replace each arc to each state with DFA ) = NFA Regular languages Minimization Regular expressions all states – -closure( ) = – -closure( ) = – -closure( 19 / 56 ϵ removal • We start with fjnding the ϵ -closure of ϵ

  29. Introduction the state WS 19–20 SfS / University of Tübingen Ç. Çöltekin, a b b a a a b a 2 1 0 arc(s) to all states in the -closure of DFA Replace each arc to each state with NFA Regular languages Minimization Regular expressions all states 19 / 56 – -closure( ) = – -closure( ) = ϵ removal • We start with fjnding the ϵ -closure of – ϵ -closure( q 0 ) = { q0 } ϵ

  30. Introduction 0 WS 19–20 SfS / University of Tübingen Ç. Çöltekin, a b b a a a b a 2 1 the state DFA arc(s) to all states in the -closure of NFA Regular languages Minimization Regular expressions all states 19 / 56 – -closure( ) = Replace each arc to each state with ϵ removal • We start with fjnding the ϵ -closure of – ϵ -closure( q 0 ) = { q0 } – ϵ -closure( q 1 ) = { q1 , q2 } ϵ

  31. Introduction 1 WS 19–20 SfS / University of Tübingen Ç. Çöltekin, a b b a a a b a 2 0 DFA the state arc(s) to all states in the -closure of Replace each arc to each state with all states Regular expressions Minimization Regular languages NFA 19 / 56 ϵ removal • We start with fjnding the ϵ -closure of – ϵ -closure( q 0 ) = { q0 } – ϵ -closure( q 1 ) = { q1 , q2 } ϵ – ϵ -closure( q 2 ) = { q2 }

  32. Introduction 1 WS 19–20 SfS / University of Tübingen Ç. Çöltekin, a b b a a a b a 2 0 DFA the state all states Regular expressions Minimization Regular languages NFA 19 / 56 ϵ removal • We start with fjnding the ϵ -closure of – ϵ -closure( q 0 ) = { q0 } – ϵ -closure( q 1 ) = { q1 , q2 } ϵ – ϵ -closure( q 2 ) = { q2 } • Replace each arc to each state with arc(s) to all states in the ϵ -closure of

  33. Introduction 3 1 3 1,3 2 3 * 3 3 1 0 1 2 a DFA b a b a b b a,b a,b Ç. Çöltekin, SfS / University of Tübingen WS 19–20 1,3 0,3 0 symbol NFA Regular languages Minimization Regular expressions a(nother) solution with the transition table transition table symbol 0 0 1 0,1,2 state 1 1,3 2 1,2 2 3 2 * 3 3 1 3 20 / 56 ϵ removal ϵ ϵ

  34. Introduction 1 symbol 0 0,3 1,3 1 3 1,3 2 3 * 3 3 1 0 2 DFA 3 a b a b a b b a,b a,b Ç. Çöltekin, SfS / University of Tübingen WS 19–20 3 20 / 56 1 1 a(nother) solution with the transition table transition table symbol 0 3 1 Regular expressions state 0,1,2 Minimization NFA 2 1,2 2 3 Regular languages * 3 1,3 2 ϵ removal ϵ a b ϵ ϵ → 0 ∅ ∅ ∅ ∅ ∅

  35. Introduction 1 symbol 0 0,3 1,3 1 3 1,3 2 3 * 3 3 1 0 2 DFA 3 a b a b a b b a,b a,b Ç. Çöltekin, SfS / University of Tübingen WS 19–20 3 20 / 56 1 state NFA Regular languages Minimization Regular expressions a(nother) solution with the transition table transition table symbol 3 1 0,1,2 0 1 2 * 3 2 3 1,2 2 1,3 ϵ removal ϵ a b ϵ ϵ ∗ ϵ → 0 ∅ ∅ ∅ ∅ ∅

  36. Introduction 1 symbol 0 0,3 1,3 1 3 1,3 2 3 * 3 3 1 0 2 DFA 3 a b a b a b b a,b a,b Ç. Çöltekin, SfS / University of Tübingen WS 19–20 3 20 / 56 1 state NFA Regular languages Minimization Regular expressions a(nother) solution with the transition table transition table symbol 3 1 0,1,2 0 1 2 * 3 2 3 1,2 2 1,3 ϵ removal ϵ a b ϵ ϵ ∗ ϵ → 0 ∅ ∅ ∅ ∅ ∅

  37. Introduction 1 symbol 0 0,3 1,3 1 3 1,3 2 3 * 3 3 1 0 2 DFA 3 a b a b a b b a,b a,b Ç. Çöltekin, SfS / University of Tübingen WS 19–20 3 20 / 56 1 state NFA Regular languages Minimization Regular expressions a(nother) solution with the transition table transition table symbol 3 1 0,1,2 0 1 2 * 3 2 3 1,2 2 1,3 ϵ removal ϵ a b ϵ ϵ ∗ ϵ → 0 ∅ ∅ ∅ ∅ ∅

  38. Introduction 1 symbol 0,3 1,3 1 3 1,3 2 3 * 3 3 1 0 2 1 3 a b a b a b b a,b a,b Ç. Çöltekin, SfS / University of Tübingen WS 19–20 DFA 3 3 1 NFA Regular languages Minimization Regular expressions a(nother) solution with the transition table transition table symbol 0 * 3 0,1,2 state 1 1,3 3 2 20 / 56 2 1,2 2 ϵ removal ϵ a b ϵ ϵ ∗ a b ϵ → 0 → 0 ∅ ⇒ ∅ ∅ ∅ ∅

  39. Introduction 1 symbol 0,3 1,3 1 3 1,3 2 3 * 3 3 1 0 2 1 3 a b a b a b b a,b a,b Ç. Çöltekin, SfS / University of Tübingen WS 19–20 DFA 3 3 1 NFA Regular languages Minimization Regular expressions a(nother) solution with the transition table transition table symbol 0 * 3 0,1,2 state 1 1,3 3 2 20 / 56 2 1,2 2 ϵ removal ϵ a b ϵ ϵ ∗ a b ϵ → 0 → 0 ∅ ⇒ ∅ ∅ ∅ ∅

  40. Introduction 1 symbol 0,3 1,3 1 3 1,3 2 3 * 3 3 1 0 2 1 3 a b a b a b b a,b a,b Ç. Çöltekin, SfS / University of Tübingen WS 19–20 DFA 3 3 1 NFA Regular languages Minimization Regular expressions a(nother) solution with the transition table transition table symbol 0 * 3 0,1,2 state 1 1,3 3 2 20 / 56 2 1,2 2 ϵ removal ϵ a b ϵ ϵ ∗ a b ϵ → 0 → 0 ∅ ⇒ ∅ ∅ ∅ ∅

  41. Introduction 1 symbol 0,3 1,3 1 3 1,3 2 3 * 3 3 1 0 2 1 3 a b a b a b b a,b a,b Ç. Çöltekin, SfS / University of Tübingen WS 19–20 DFA 3 3 1 NFA Regular languages Minimization Regular expressions a(nother) solution with the transition table transition table symbol 0 * 3 0,1,2 state 1 1,3 3 2 20 / 56 2 1,2 2 ϵ removal ϵ a b ϵ ϵ ∗ a b ϵ → 0 → 0 ∅ ⇒ ∅ ∅ ∅ ∅

  42. Introduction 1 symbol 0,3 1,3 1 3 1,3 2 3 * 3 3 1 0 2 1 3 a b a b a b b a,b a,b Ç. Çöltekin, SfS / University of Tübingen WS 19–20 DFA 3 3 1 NFA Regular languages Minimization Regular expressions a(nother) solution with the transition table transition table symbol 0 * 3 0,1,2 state 1 1,3 3 2 20 / 56 2 1,2 2 ϵ removal ϵ a b ϵ ϵ ∗ a b ϵ → 0 → 0 ∅ ⇒ ∅ ∅ ∅ ∅

  43. Introduction 1 symbol 0,3 1,3 1 3 1,3 2 3 * 3 3 1 0 2 1 3 a b a b a b b a,b a,b Ç. Çöltekin, SfS / University of Tübingen WS 19–20 DFA 3 3 1 NFA Regular languages Minimization Regular expressions a(nother) solution with the transition table transition table symbol 0 * 3 0,1,2 state 1 1,3 3 2 20 / 56 2 1,2 2 ϵ removal ϵ a b ϵ ϵ ∗ a b ϵ → 0 → 0 ∅ ⇒ ∅ ∅ ∅ ∅

  44. Introduction 1 DFA symbol 0,3 1,3 1 3 1,3 2 3 * 3 3 1 0 2 1 3 a b a b a b b a,b a,b Ç. Çöltekin, SfS / University of Tübingen WS 19–20 3 20 / 56 3 1 NFA Regular languages Minimization Regular expressions a(nother) solution with the transition table transition table symbol 0 0,1,2 state 1 1,3 * 3 2 1,2 2 2 3 ϵ removal ϵ a b ϵ ϵ ∗ a b ϵ → 0 → 0 ∅ ⇒ ∅ ∅ ∅ ∅ ∅

  45. Introduction 1 DFA symbol 0,3 1,3 1 3 1,3 2 3 * 3 3 1 0 2 1 3 a b a b a b b a,b a,b Ç. Çöltekin, SfS / University of Tübingen WS 19–20 3 20 / 56 3 1 NFA Regular languages Minimization Regular expressions a(nother) solution with the transition table transition table symbol 0 0,1,2 state 1 1,3 * 3 2 1,2 2 2 3 ϵ removal ϵ a b ϵ ϵ ∗ a b ϵ → 0 → 0 ∅ ⇒ ∅ ∅ ∅ ∅ ∅

  46. Introduction 1 DFA symbol 0,3 1,3 1 3 1,3 2 3 * 3 3 1 0 2 1 3 a b a b a b b a,b a,b Ç. Çöltekin, SfS / University of Tübingen WS 19–20 3 20 / 56 3 1 NFA Regular languages Minimization Regular expressions a(nother) solution with the transition table transition table symbol 0 0,1,2 state 1 1,3 * 3 2 1,2 2 2 3 ϵ removal ϵ a b ϵ ϵ ∗ a b ϵ → 0 → 0 ∅ ⇒ ∅ ∅ ∅ ∅ ∅

  47. Introduction 1 DFA symbol 0,3 1,3 1 3 1,3 2 3 * 3 3 1 0 2 1 3 a b a b a b b a,b a,b Ç. Çöltekin, SfS / University of Tübingen WS 19–20 3 20 / 56 3 1 NFA Regular languages Minimization Regular expressions a(nother) solution with the transition table transition table symbol 0 0,1,2 state 1 1,3 * 3 2 1,2 2 2 3 ϵ removal ϵ a b ϵ ϵ ∗ a b ϵ → 0 → 0 ∅ ⇒ ∅ ∅ ∅ ∅ ∅

  48. Introduction DFA NFA Regular languages Minimization Regular expressions NFA–DFA equivalence Ç. Çöltekin, SfS / University of Tübingen WS 19–20 21 / 56 • The language recognized by every NFA is recognized by some DFA • The set of DFA is a subset of the set of NFA (a DFA is also an NFA) • The same is true for ϵ -NFA • All recognize/generate regular languages • NFA can automatically be converted to the equivalent DFA

  49. Introduction 0 WS 19–20 SfS / University of Tübingen Ç. Çöltekin, 2. Construct a DFA for the same language a,b a,b a,b a a,b 4 3 2 1 symbol from the end is an DFA , such that 4th 1. Construct (draw) an NFA for the language over – and a not-so-quick one A quick exercise expressions – Some representations are easy to convert to NFA rather than DFA, e.g., regular – Intuitive for humans (cf. earlier exercise) Why do we use an NFA then? Regular expressions Minimization Regular languages NFA 22 / 56 • NFA (or ϵ -NFA) are often easier to construct • NFA may require less memory (fewer states)

  50. Introduction 0 WS 19–20 SfS / University of Tübingen Ç. Çöltekin, 2. Construct a DFA for the same language a,b a,b a,b a a,b 4 3 2 1 22 / 56 DFA – and a not-so-quick one A quick exercise expressions – Some representations are easy to convert to NFA rather than DFA, e.g., regular – Intuitive for humans (cf. earlier exercise) Why do we use an NFA then? Regular expressions Minimization Regular languages NFA • NFA (or ϵ -NFA) are often easier to construct • NFA may require less memory (fewer states) 1. Construct (draw) an NFA for the language over Σ = { a , b } , such that 4th symbol from the end is an a

  51. Introduction 0 WS 19–20 SfS / University of Tübingen Ç. Çöltekin, 2. Construct a DFA for the same language a,b a,b a,b a a,b 4 3 2 1 22 / 56 DFA – and a not-so-quick one A quick exercise expressions – Some representations are easy to convert to NFA rather than DFA, e.g., regular – Intuitive for humans (cf. earlier exercise) Why do we use an NFA then? Regular expressions Minimization Regular languages NFA • NFA (or ϵ -NFA) are often easier to construct • NFA may require less memory (fewer states) 1. Construct (draw) an NFA for the language over Σ = { a , b } , such that 4th symbol from the end is an a

  52. Introduction 1 WS 19–20 SfS / University of Tübingen Ç. Çöltekin, 2. Construct a DFA for the same language a,b a,b a,b a a,b 4 3 2 0 DFA A quick exercise – and a not-so-quick one expressions – Some representations are easy to convert to NFA rather than DFA, e.g., regular – Intuitive for humans (cf. earlier exercise) Why do we use an NFA then? Regular expressions Minimization Regular languages NFA 22 / 56 • NFA (or ϵ -NFA) are often easier to construct • NFA may require less memory (fewer states) 1. Construct (draw) an NFA for the language over Σ = { a , b } , such that 4th symbol from the end is an a

  53. Introduction Intuition: remember the parallel NFA recognition. We can consider an NFA WS 19–20 SfS / University of Tübingen Ç. Çöltekin, intuition to convert an NFA to a DFA DFA 23 / 56 the subset construction Determinization Regular expressions Minimization Regular languages NFA being a deterministic machine which is at a set of states at any given time. • Subset construction (sometimes called power set construction) uses this • The algorithm can be modifjed to handle ϵ -transitions (or we can eliminate ϵ ’s as a preprocessing step)

  54. Introduction a,b WS 19–20 SfS / University of Tübingen Ç. Çöltekin, DFA symbol transition table with subsets a,b a a 24 / 56 a,b a,b 2 1 0 by example The subset construction Regular expressions NFA Regular languages Minimization a b ∅ ∅ ∅ → { 0 } { 0 , 1 } { 0 , 1 } { 1 } { 1 , 2 } { 1 } * { 2 } { 0 , 2 } { 0 } { 0 , 1 } { 0 , 1 , 2 } { 0 , 1 } * { 0 , 2 } { 0 , 1 , 2 } { 0 , 1 } * { 1 , 2 } { 0 , 1 , 2 } { 0 , 1 } * { 0 , 1 , 2 } { 0 , 1 , 2 } { 0 , 1 }

  55. Introduction a,b WS 19–20 SfS / University of Tübingen Ç. Çöltekin, DFA symbol transition table with subsets a,b a a 24 / 56 a,b a,b 2 1 0 by example The subset construction Regular expressions NFA Regular languages Minimization a b ∅ ∅ ∅ → { 0 } { 0 , 1 } { 0 , 1 } { 1 } { 1 , 2 } { 1 } * { 2 } { 0 , 2 } { 0 } { 0 , 1 } { 0 , 1 , 2 } { 0 , 1 } * { 0 , 2 } { 0 , 1 , 2 } { 0 , 1 } * { 1 , 2 } { 0 , 1 , 2 } { 0 , 1 } * { 0 , 1 , 2 } { 0 , 1 , 2 } { 0 , 1 }

  56. Do you remember the set of states marked during parallel NFA recognition? Introduction DFA WS 19–20 SfS / University of Tübingen Ç. Çöltekin, a b a b a,b 012 01 0 25 / 56 The subset construction NFA Regular languages Minimization Regular expressions symbol transition table without useless/inaccessible states by example: the resulting DFA a b → { 0 } { 0 , 1 } { 0 , 1 } { 0 , 1 } { 0 , 1 , 2 } { 0 , 1 } * { 0 , 1 , 2 } { 0 , 1 , 2 } { 0 , 1 }

  57. Introduction DFA WS 19–20 SfS / University of Tübingen Ç. Çöltekin, Do you remember the set of states marked during parallel NFA recognition? a b a b a,b 012 01 0 25 / 56 The subset construction NFA Regular languages Minimization Regular expressions symbol transition table without useless/inaccessible states by example: the resulting DFA a b → { 0 } { 0 , 1 } { 0 , 1 } { 0 , 1 } { 0 , 1 , 2 } { 0 , 1 } * { 0 , 1 , 2 } { 0 , 1 , 2 } { 0 , 1 }

  58. Introduction a,b WS 19–20 SfS / University of Tübingen Ç. Çöltekin, What language do they recognize? a b a b a,b 2 1 0 DFA a DFA a a,b a,b a,b 2 1 0 NFA by example: side by side The subset construction Regular expressions Minimization Regular languages NFA 26 / 56

  59. Introduction DFA WS 19–20 SfS / University of Tübingen Ç. Çöltekin, a b a b a,b 2 1 0 DFA a,b a a a,b a,b a,b 2 1 0 NFA by example: side by side The subset construction Regular expressions Minimization Regular languages NFA 26 / 56 • What language do they recognize?

  60. Introduction DFA WS 19–20 SfS / University of Tübingen Ç. Çöltekin, a,b a,b a,b a a,b 4 3 2 1 0 are often similar wrapping up The subset construction Regular expressions Minimization Regular languages NFA 27 / 56 • In worst case, resulting DFA has 2 n nodes • Worst case is rather rare, number of nodes in an NFA and the converted DFA • In practice, we do not need to enumerate all 2 n subsets • We’ve already seen a typical problematic case: • We can also skip the unreachable states during subset construction

  61. Introduction 1 WS 19–20 SfS / University of Tübingen Ç. Çöltekin, b a a,b 2 0 DFA NFA: Determinize the following automaton Yet another exercise Regular expressions Minimization Regular languages NFA 28 / 56

  62. Introduction DFA WS 19–20 SfS / University of Tübingen Ç. Çöltekin, Right regular Left regular 29 / 56 Minimization Regular languages: defjnition NFA Regular languages Regular expressions A regular grammar is a tuple G = ( Σ , N , S , R ) where Σ is an alphabet of terminal symbols N are a set of non-terminal symbols S is a special ‘start’ symbol ∈ N R is a set of rewrite rules following one of the following patterns ( A , B ∈ N , a ∈ Σ , ϵ is the empty string) 1. A → a 1. A → a 2. A → Ba 2. A → aB 3. A → ϵ 3. A → ϵ

  63. Introduction DFA WS 19–20 SfS / University of Tübingen Ç. Çöltekin, DFA 30 / 56 A language is regular if there is an FSA that recognizes it Regular languages: another defjnition Regular expressions Minimization Regular languages NFA • We denote the language recognized by a fjnite state automaton M , as L ( M ) • The above defjnition reformulated: if a language L is regular, there is a DFA M , such that L ( M ) = L • Remember: any NFA (with or without ϵ transitions) can be converted to a

  64. Introduction DFA WS 19–20 SfS / University of Tübingen Ç. Çöltekin, Regular languages are closed under all of these operations. 31 / 56 Some operations on regular languages (and FSA) Regular expressions Minimization Regular languages NFA L 1 L 2 Concatenation of two languages L 1 and L 2 : any sentence of L 1 followed by any sentence of L 2 L ∗ Kleene star of L : L concatenated by itself 0 or more times L R Reverse of L : reverse of any string in L L − L ) L Complement of L : all strings in Σ ∗ L except the ones in L ( Σ ∗ L 1 ∪ L 2 Union of languages L 1 and L 2 : strings that are in any of the languages L 1 ∩ L 2 Intersection of languages L 1 and L 2 : strings that are in both languages

  65. Introduction DFA WS 19–20 SfS / University of Tübingen Ç. Çöltekin, We will use these languages and automata for demonstration. . ’s over Odd number of a b b a 1 0 . ’s over Odd number of what languages do they accept? NFA Regular languages Minimization Regular expressions Two example FSA 0 1 b a a b 32 / 56 L 2 = L ( M 2 ) L 1 = L ( M 1 ) M 2 M 1

  66. Introduction b WS 19–20 SfS / University of Tübingen Ç. Çöltekin, We will use these languages and automata for demonstration. a b b a 1 0 DFA 32 / 56 a Regular expressions NFA Regular languages b 1 0 a what languages do they accept? Two example FSA Minimization L 2 = L ( M 2 ) L 1 = L ( M 1 ) M 2 M 1 Odd number of a ’s over { a , b } . Odd number of b ’s over { a , b } .

  67. Introduction a 0 1 2 3 b a b DFA a b b a Ç. Çöltekin, SfS / University of Tübingen WS 19–20 a b b a NFA Regular languages Minimization Regular expressions Concatenation 0 1 b a a b 0 1 33 / 56 L 1 L 2 L 1 L 2 ϵ

  68. Introduction DFA WS 19–20 SfS / University of Tübingen Ç. Çöltekin, What if there were more than one accepting states? b a a b 1 0 34 / 56 b a a b 1 0 Kleene star Regular expressions Minimization Regular languages NFA L ∗ L 1 1 ϵ

  69. Introduction b WS 19–20 SfS / University of Tübingen Ç. Çöltekin, b a a b 1 0 DFA 34 / 56 a a b 1 0 Kleene star Regular expressions Minimization Regular languages NFA L ∗ L 1 1 ϵ • What if there were more than one accepting states?

  70. Introduction DFA WS 19–20 SfS / University of Tübingen Ç. Çöltekin, b a a b 1 0 b a a b 1 0 Reversal Regular expressions Minimization Regular languages NFA 35 / 56 L R L 1 1

  71. Introduction b WS 19–20 SfS / University of Tübingen Ç. Çöltekin, b a a b 1 0 a DFA a b 1 0 Complement Regular expressions Minimization Regular languages NFA 36 / 56 L 1 L 1

  72. Introduction a WS 19–20 SfS / University of Tübingen Ç. Çöltekin, a b b a b DFA a b 0’ Union Regular expressions Minimization Regular languages NFA 37 / 56 L 1 ∪ L 2 ϵ 0 1 1 1 ϵ 0 2 1 2

  73. Introduction b 00 01 10 11 b b b a b a a a …or Ç. Çöltekin, SfS / University of Tübingen WS 19–20 a b DFA a NFA Regular languages Minimization Regular expressions Intersection 0 1 b a a b 0 1 38 / 56 L 2 L 1 L 1 ∩ L 2

  74. Introduction b 00 01 10 11 b b b a DFA a a a …or Ç. Çöltekin, SfS / University of Tübingen WS 19–20 a b b 0 NFA Regular languages Minimization Regular expressions Intersection a 38 / 56 1 b a a b 0 1 L 2 L 1 L 1 ∩ L 2 = L 1 ∪ L 2 L 1 ∩ L 2

  75. Introduction – Kleene star WS 19–20 SfS / University of Tübingen Ç. Çöltekin, – Intersection – Union – Complement – Reversal – Concatenation DFA closed under Closure properties of regular languages Regular expressions Minimization Regular languages NFA 39 / 56 • Since results of all the operations we studied are FSA: Regular languages are

  76. Introduction DFA NFA Regular languages Minimization Regular expressions Is a language regular? — or not recognizes it. Ç. Çöltekin, SfS / University of Tübingen WS 19–20 40 / 56 • To show that a language is regular, it is suffjcient to fjnd an FSA that • Showing that a language is not regular is more involved • We will study a method based on pumping lemma

  77. Introduction DFA WS 19–20 SfS / University of Tübingen Ç. Çöltekin, ’ above) same substring (‘ Part of every string longer than some number will include repetition of the recursive rule(s) in the grammar) Any FSA generating an infjnite language has to have a loop (application of 41 / 56 intuition Pumping lemma Regular expressions Minimization Regular languages NFA l m k a b c d e • What is the length of longest string generated by this FSA?

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend