CS3102 Theory of Computation Warm up: Whatβs 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 how to build each βpieceβ of a regex using FSA 4
Proof βStoryboardβ = FSA Regex Computability by How to build π , literal, FSA closed under a Regex union, concat, * Makes that easy Non- determinism 5
β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
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
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
Example Non-deterministic Finite Automaton β’ πππππππππ‘π’1 = π₯ β 0,1 β the second from last character is a 1} 0,1 1 0,1 πππ πππ¦π’ start 9
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
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
Powerset Construction 0,1 1 0,1 one next start next one start Start, One, {} next Start, Start, One, one next next 12
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
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
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
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
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
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
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
Kleene Star β’ π β = π 0 βͺ π 1 βͺ π 2 βͺ β― β’ π 0 = {π} β’ π π = ( π concatenated π times) 00, 11 β = β’ {π, 00, 11, 0011, 1100, 0000, 1111, 110011, β¦ } 20
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
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
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
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
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