cs3102 theory of
play

CS3102 Theory of Computation Warm up: Whats the language of this - PowerPoint PPT Presentation

CS3102 Theory of Computation Warm up: Whats the language of this NFA? 0, final start Logistics 2 Last Time Non-determinism 3 Showing Regex FSA Show how to convert any regex into a FSA for the same language Idea: show


  1. CS3102 Theory of Computation Warm up: What’s the language of this NFA? 0, 𝜁 final start

  2. Logistics 2

  3. Last Time β€’ Non-determinism 3

  4. Showing Regex ≀ FSA β€’ Show how to convert any regex into a FSA for the same language β€’ Idea: show how to build each β€œpiece” of a regex using FSA 4

  5. Proof β€œStoryboard” = FSA Regex Computability by How to build 𝜁 , literal, FSA closed under a Regex union, concat, * Makes that easy Non- determinism 5

  6. β€œPieces” of a Regex β€’ Empty String: – Matches just the string of length 0 – Notation: 𝜁 or β€œβ€ β€’ Literal Character – Matches a specific string of length 1 – Example: the regex 𝑏 will match just the string 𝑏 β€’ Alternation/Union – Matches strings that match at least one of the two parts – Example: the regex 𝑏|𝑐 will match 𝑏 and 𝑐 β€’ Concatenation – Matches strings that can be dividing into 2 parts to match the things concatenated – Example: the regex 𝑏 𝑐 𝑑 will match the strings 𝑏𝑑 and 𝑐𝑑 β€’ Kleene Star – Matches strings that are 0 or more copies of the thing starred – Example: 𝑏 𝑐 𝑑 βˆ— will match 𝑏 , 𝑐 , or either followed by any number of 𝑑 ’s 6

  7. Non-determinism β€’ Things could get easier if we β€œrelax” our automata β€’ So far: – Must have exactly one transition per character per state – Can only be in one state at a time β€’ Non-deterministic Finite Automata: – Allowed to be in multiple (or zero) states! – Can have multiple or zero transitions for a character – Can take transitions without using a character – Models parallel computing 7

  8. Nondeterminism Driving to a friend’s house Friend forgets to mention a fork in the directions Which way do you go? Why not both? ? 8

  9. Example Non-deterministic Finite Automaton β€’ π‘‡π‘“π‘‘π‘π‘œπ‘’π‘€π‘π‘‘π‘’1 = π‘₯ ∈ 0,1 βˆ— the second from last character is a 1} 0,1 1 0,1 π‘π‘œπ‘“ π‘œπ‘“π‘¦π‘’ start 9

  10. Non-Deterministic Finite State Automaton β€’ Implementation: – Finite number of states – One start state – β€œFinal” states – Transitions: (partial) function mapping state-character (or epsilon) pairs to sets of states β€’ Execution: – Start in the initial β€œstate” – Enter every state reachable without consuming input ( 𝜻 -transitions) – Read each character once, in order (no looking back) – Transition to new states once per character (based on current states and character) – Enter every state reachable without consuming input ( 𝜻 -transitions) – Return True if any state you end is final β€’ Return False if every state you end in is non-final 10

  11. NFA = DFA β€’ DFA ≀ NFA: – Can we convert any DFA into an NFA? β€’ NFA ≀ DFA: – Can we convert any NFA into a DFA? – Strategy: NFAs can be in any subset of states, make a DFA where each state represents a set of states 11

  12. Powerset Construction 0,1 1 0,1 one next start next one start Start, One, {} next Start, Start, One, one next next 12

  13. Powerset Construction 0,1 1 0,1 one next start 0 next one start 1 Start, 1 0 One, {} next 1 Start, Start, One, one next next 0 0 1 13

  14. Powerset Construction (symbolic) β€’ NFA 𝑁 = (𝑅, Ξ£, πœ€, π‘Ÿ 0 , 𝐺) β€’ As a DFA: – 𝑁 𝐸 = (2 𝑅 , Ξ£, πœ€ 𝐸 , π‘Ÿ 𝐸 , 𝐺 𝐸 ) β€’ π‘Ÿ 𝐸 = π‘Ÿ 0 βˆͺ πœ€(π‘Ÿ 0 , 𝜁) – start state and everything reachable using empty transitions 𝐸 = 𝑑 ∈ 2 𝑅 βˆƒπ‘Ÿ ∈ 𝑑 . π‘Ÿ ∈ 𝐺} β€’ 𝐺 – All states with a start state in them β€’ πœ€ 𝐸 𝑑, 𝜏 = πœ€ 𝑑, 𝜏 π‘Ÿβˆˆπ‘‘ – Transition to the stateset of everything any current state transitions to 14

  15. Union Using Non-Determinism 0,1 Goal: Return 1 if either machine Some 0s 0 returns 1 new Strategy: Run both machines in 0 start parallel (non-deterministically) by transitioning to the start states 1 for both without using input 1 No 0s 1 0 0 Even Odd 15 1

  16. Union Using Non-Determinism 𝑁 1 0,1 Some 0s 0 e e 𝜁 new 𝑁 2 0 start 𝜁 𝑁 βˆͺ = 𝑅 1 βˆͺ 𝑅 2 βˆͺ π‘œπ‘“π‘₯ , Ξ£, πœ€ βˆͺ , π‘œπ‘“π‘₯, 𝐺 1 βˆͺ 𝐺 2 1 πœ€ βˆͺ (π‘Ÿ, 𝜏) = πœ€ 1 π‘Ÿ, 𝜏 if π‘Ÿ ∈ 𝑅 1 1 No 0s {πœ€ 2 π‘Ÿ, 𝜏 } if π‘Ÿ ∈ 𝑅 2 1 πœ€ βˆͺ π‘œπ‘“π‘₯, 𝜁 = {𝑑𝑒𝑏𝑠𝑒, π‘“π‘€π‘“π‘œ} 0 0 Even Odd 16 1

  17. Language Concatenation β€’ 𝑀 1 𝑀 2 = {π‘₯ ∈ Ξ£ βˆ— |βˆƒπ‘¦ ∈ 𝑀 1 , βˆƒπ‘§ ∈ 𝑀 2 . 𝑦𝑧 = π‘₯} β€’ The set of all strings I can create by concatenating a string from 𝑀 1 with a string from 𝑀 2 (in that order) 𝜁, 0, 10 β‹… 0,00 = {0, 00, 000, 100, 1000} β€’ 17

  18. Concatenation using NFA 𝑁 2 e 𝑁 1 e Goal: Return 1 if the input 0,1 can be broken into 2 Some 0s 0 chunks, 𝑁 1 returns 1 on the 1 first chunk, 𝑁 2 on the 0 second 0 start 0 Even Odd Strategy: Every time we enter a final state in 𝑁 1 , 1 1 non-deterministically run 1 No 0s the rest of the string on 𝑁 2 . Return 1 if 𝑁 2 does. 18

  19. Concatenation using NFA 𝑁 2 e 𝑁 1 e 𝑁 𝑑 = 𝑅 1 βˆͺ 𝑅 2 , Ξ£, πœ€ 𝑑 , π‘Ÿ 01 , 𝐺 2 πœ€ 1 π‘Ÿ, 𝜏 if π‘Ÿ ∈ 𝑅 1 βˆ’ 𝐺 1 0,1 πœ€ 1 π‘Ÿ, 𝜏 , π‘Ÿ 0,2 if π‘Ÿ ∈ 𝐺 1 πœ€ 𝑑 (π‘Ÿ, 𝜏) = Some 0s 0 {πœ€ 2 π‘Ÿ, 𝜏 } if π‘Ÿ ∈ 𝑅 2 1 0 𝜁 start 0 Even Odd 0 1 𝜁 1 1 No 0s 19

  20. Kleene Star β€’ 𝑀 βˆ— = 𝑀 0 βˆͺ 𝑀 1 βˆͺ 𝑀 2 βˆͺ β‹― β€’ 𝑀 0 = {𝜁} β€’ 𝑀 𝑙 = ( 𝑀 concatenated 𝑙 times) 00, 11 βˆ— = β€’ {𝜁, 00, 11, 0011, 1100, 0000, 1111, 110011, … } 20

  21. e Kleene Star using NFA 𝑁 1 e e Goal: Return 1 if the input can 0,1 be broken into chunks such that Some 0s 0 𝑁 1 returns 1 for every chunk Strategy: Every time we enter a 0 start final state in 𝑁 1 , non- deterministically β€œrestart” the 1 machine to run on the rest of 1 No 0s the string, make sure we return 1 on 𝜁 21

  22. e Kleene Star using NFA 𝑁 1 e e Goal: Return 1 if the input can 0,1 be broken into chunks such that Some 0s 0 𝑁 1 returns 1 for every chunk 𝜁 Strategy: Every time we enter a 0 start final state in 𝑁 1 , non- 𝜁 deterministically β€œrestart” the 𝜁 1 machine to run on the rest of 1 No 0s the string, make sure we return 1 on 𝜁 empty 22

  23. Conclusion β€’ Any language expressible as a regular expression is computable by a NFA β€’ Any language computable by a NFA is computable by a DFA β€’ NFA = Regex = DFA β€’ Call any such language a β€œregular language” 23

  24. Characterizing What’s computable β€’ Things that are computable by FSA: – Functions that don’t need β€œmemory” – Languages expressible as Regular Expressions β€’ Things that aren’t computable by FSA: – Things that require more than finitely many states – Intuitive example: Majority 24

  25. Majority with FSA? β€’ Consider an inputs with lots of 0s 000...0000 111...1111 000...0000 111...1111 000...0000 111...1111 Γ— 50,000 Γ— 50,000 Γ— 50,001 Γ— 49,999 Γ— 50,000 Γ— 50,000 β€’ Recall: we read 1 bit at a time, no going back! β€’ To count to 50,000, we'll need 50,000 states! 25

Recommend


More recommend