advertisement

Formal Definition of a Nondeterministic Finite Automaton Formal Definition of a Nondeterministic Finite Automaton – p.1/28 A comment first The formal definition of an NFA is similar to that of a DFA. Both have states, an alphabet, transition function, one start state, and a collection of accept states Formal Definition of a Nondeterministic Finite Automaton – p.2/28 A comment first The formal definition of an NFA is similar to that of a DFA. Both have states, an alphabet, transition function, one start state, and a collection of accept states Differ in one essential way: the transition functions: Formal Definition of a Nondeterministic Finite Automaton – p.2/28 A comment first The formal definition of an NFA is similar to that of a DFA. Both have states, an alphabet, transition function, one start state, and a collection of accept states ; In a DFA transition function is Differ in one essential way: the transition functions: Formal Definition of a Nondeterministic Finite Automaton – p.2/28 A comment first The formal definition of an NFA is similar to that of a DFA. Both have states, an alphabet, transition function, one start state, and a collection of accept states ; In a DFA transition function is In an NFA it is Differ in one essential way: the transition functions: Formal Definition of a Nondeterministic Finite Automaton – p.2/28 A comment first The formal definition of an NFA is similar to that of a DFA. Both have states, an alphabet, transition function, one start state, and a collection of accept states is the collection of subsets of power set of ; called the - where In a DFA transition function is In an NFA it is Differ in one essential way: the transition functions: Formal Definition of a Nondeterministic Finite Automaton – p.2/28 for we write For any alphabet Notation Formal Definition of a Nondeterministic Finite Automaton – p.3/28 NFA formal definition (Def. 1.37) A nondeterministic finite automaton (NFA) is a 5-tuple where: Formal Definition of a Nondeterministic Finite Automaton – p.4/28 NFA formal definition (Def. 1.37) A nondeterministic finite automaton (NFA) is a 5-tuple where: is a finite set of states Formal Definition of a Nondeterministic Finite Automaton – p.4/28 NFA formal definition (Def. 1.37) is a finite set of states A nondeterministic finite automaton (NFA) is a 5-tuple where: is a finite alphabet Formal Definition of a Nondeterministic Finite Automaton – p.4/28 NFA formal definition (Def. 1.37) is a finite alphabet is a finite set of states A nondeterministic finite automaton (NFA) is a 5-tuple where: is the transition function Formal Definition of a Nondeterministic Finite Automaton – p.4/28 NFA formal definition (Def. 1.37) is a finite alphabet is a finite set of states A nondeterministic finite automaton (NFA) is a 5-tuple where: is the transition function is the start state Formal Definition of a Nondeterministic Finite Automaton – p.4/28 NFA formal definition (Def. 1.37) is the start state is the transition function is a finite alphabet is a finite set of states A nondeterministic finite automaton (NFA) is a 5-tuple where: is the set of accept states Formal Definition of a Nondeterministic Finite Automaton – p.4/28 Example NFA (Example 1.38) , Figure 1: 1 ,0 1 0,1 0,1 Figure 1: Nondeterministic Finite Automaton Recall the NFA Formal Definition of a Nondeterministic Finite Automaton – p.5/28 where: is given in the table: 3. 2. 1. The formal definition of 1 is the start set; 5. 4. 0 Formal Definition of a Nondeterministic Finite Automaton – p.6/28 a string over . be an NFA and accepts if: Let We say that Computation performed by an NFA Formal Definition of a Nondeterministic Finite Automaton – p.7/28 , , as We can write a string over . be an NFA and accepts if: Let We say that Computation performed by an NFA Formal Definition of a Nondeterministic Finite Automaton – p.7/28 exists in , A sequence of states , as We can write a string over . be an NFA and accepts if: Let We say that Computation performed by an NFA s.t: Formal Definition of a Nondeterministic Finite Automaton – p.7/28 exists in , s.t: A sequence of states 1. , as We can write a string over . be an NFA and accepts if: Let We say that Computation performed by an NFA Formal Definition of a Nondeterministic Finite Automaton – p.7/28 exists in , s.t: , for A sequence of states 2. , as We can write 1. a string over . be an NFA and accepts if: Let We say that Computation performed by an NFA Formal Definition of a Nondeterministic Finite Automaton – p.7/28 exists in s.t: , for , 3. A sequence of states 2. , as We can write 1. a string over . be an NFA and accepts if: Let We say that Computation performed by an NFA Formal Definition of a Nondeterministic Finite Automaton – p.7/28 Interpretation Condition 1 says that the machine starts its computation in the start state Formal Definition of a Nondeterministic Finite Automaton – p.8/28 Interpretation Condition 1 says that the machine starts its computation in the start state Condition 2 says that state is one of the allowable . Note new states when is in state and reads is a set that Formal Definition of a Nondeterministic Finite Automaton – p.8/28 Interpretation Condition 1 says that the machine starts its computation in the start state Condition 2 says that state is one of the allowable . Note new states when is in state and reads is a set that Condition 3 says that the machine accepts the input if the last state is in the accept state set. Formal Definition of a Nondeterministic Finite Automaton – p.8/28 An important property Any NFA can be converted to an equivalent NFA has a single accept state that Formal Definition of a Nondeterministic Finite Automaton – p.9/28 An important property that be any NFA. Then Proof: by construction. Let where: Any NFA can be converted to an equivalent NFA has a single accept state Formal Definition of a Nondeterministic Finite Automaton – p.9/28 An important property that be any NFA. Then where 1. Proof: by construction. Let where: Any NFA can be converted to an equivalent NFA has a single accept state is a new state Formal Definition of a Nondeterministic Finite Automaton – p.9/28 An important property that be any NFA. Then where is a new state 2. 1. Proof: by construction. Let where: Any NFA can be converted to an equivalent NFA has a single accept state Formal Definition of a Nondeterministic Finite Automaton – p.9/28 An important property that be any NFA. Then where is a new state 3. 2. 1. Proof: by construction. Let where: Any NFA can be converted to an equivalent NFA has a single accept state Formal Definition of a Nondeterministic Finite Automaton – p.9/28 An important property that be any NFA. Then is a new state where 3. 2. 1. Proof: by construction. Let where: Any NFA can be converted to an equivalent NFA has a single accept state ; or . and if if 4. Formal Definition of a Nondeterministic Finite Automaton – p.9/28 An important property that be any NFA. Then is a new state where 3. 2. 1. Proof: by construction. Let where: Any NFA can be converted to an equivalent NFA has a single accept state . and if ; 5. or if 4. Formal Definition of a Nondeterministic Finite Automaton – p.9/28 Equivalence of NFA and DFA DFAs and NFAs recognize the same class of languages Formal Definition of a Nondeterministic Finite Automaton – p.10/28 Equivalence of NFA and DFA DFAs and NFAs recognize the same class of languages This equivalence is both surprising and useful Formal Definition of a Nondeterministic Finite Automaton – p.10/28 Equivalence of NFA and DFA DFAs and NFAs recognize the same class of languages This equivalence is both surprising and useful 1. It is surprising because NFAs appears to have more power than DFA, so we might expect that NFA recognizes more languages Formal Definition of a Nondeterministic Finite Automaton – p.10/28 Equivalence of NFA and DFA DFAs and NFAs recognize the same class of languages This equivalence is both surprising and useful 1. It is surprising because NFAs appears to have more power than DFA, so we might expect that NFA recognizes more languages 2. It is useful because describing an NFA for a given language sometimes is much easier than describing a DFA Formal Definition of a Nondeterministic Finite Automaton – p.10/28 Theorem 1.39 Every nondeterministic finite automation (NFA) has an equivalent deterministic finite automaton (DFA). Proof idea: Convert NFA recognizing a language into a DFA that recognizes the same language by simulating the NFA Formal Definition of a Nondeterministic Finite Automaton – p.11/28 Theorem 1.39 Every nondeterministic finite automation (NFA) has an equivalent deterministic finite automaton (DFA). Proof idea: Convert NFA recognizing a language into a DFA that recognizes the same language by simulating the NFA Formal Definition of a Nondeterministic Finite Automaton – p.11/28 More on proof idea The approach is to pretend to be an DFA simulating an NFA. Questions to be answered: Formal Definition of a Nondeterministic Finite Automaton – p.12/28 More on proof idea The approach is to pretend to be an DFA simulating an NFA. Questions to be answered: How would you simulate an NFA if you were pretending to be a DFA? Formal Definition of a Nondeterministic Finite Automaton – p.12/28 More on proof idea The approach is to pretend to be an DFA simulating an NFA. Questions to be answered: How would you simulate an NFA if you were pretending to be a DFA? What does one need to keep track of as the input is processed? Formal Definition of a Nondeterministic Finite Automaton – p.12/28 Note In the examples of NFA we kept track of various branches of the computation by placing tokens on each state that could be activated at given points in the input Formal Definition of a Nondeterministic Finite Automaton – p.13/28 Note In the examples of NFA we kept track of various branches of the computation by placing tokens on each state that could be activated at given points in the input Tokens were updated by moving, adding, and removing them according to the way NFA operates Formal Definition of a Nondeterministic Finite Automaton – p.13/28 Note In the examples of NFA we kept track of various branches of the computation by placing tokens on each state that could be activated at given points in the input Tokens were updated by moving, adding, and removing them according to the way NFA operates Hence, all we needed to keep track of was the set of states with tokens on them. Formal Definition of a Nondeterministic Finite Automaton – p.13/28 An NFA with states has Conclusion subsets of states Formal Definition of a Nondeterministic Finite Automaton – p.14/28 An NFA with states has Conclusion subsets of states Each subset corresponds to one of the possibilities that DFA must remember. So, the DFA simulating an NFA with states has states Formal Definition of a Nondeterministic Finite Automaton – p.14/28 An NFA with states has Conclusion subsets of states Each subset corresponds to one of the possibilities that DFA must remember. So, the DFA simulating an NFA with states has states The only thing we need now is to figure out which are the start state, the accept states, and transition function Formal Definition of a Nondeterministic Finite Automaton – p.14/28 guage Let The formal proof be the NFA recognizing the lan- . We construct the DFA recognizing . Be- fore doing the full construction, consider first the easier case has no transitions. when Formal Definition of a Nondeterministic Finite Automaton – p.15/28 1. ; every state of Constructing is a set of states of Formal Definition of a Nondeterministic Finite Automaton – p.16/28 is a set of states of let and 2. For ; every state of 1. Constructing Formal Definition of a Nondeterministic Finite Automaton – p.16/28 let is a set of states of - Note: and 2. For ; every state of 1. Constructing Formal Definition of a Nondeterministic Finite Automaton – p.16/28 let is a set of states of ; starts computing in the same state as 3. - Note: and 2. For ; every state of 1. Constructing Formal Definition of a Nondeterministic Finite Automaton – p.16/28 let 4. starts computing in the same state as is a set of states of ; 3. - Note: and 2. For ; every state of 1. Constructing Formal Definition of a Nondeterministic Finite Automaton – p.16/28 let - that is, the machine accepts if one of the possible states that could be in at this point is an accept state 4. starts computing in the same state as is a set of states of ; 3. - Note: and 2. For ; every state of 1. Constructing Formal Definition of a Nondeterministic Finite Automaton – p.16/28 Consider the transitions Notation: for any define to be the collection of states that can be reached from by going only along transitions, including the members of themselves. Formally: Formal Definition of a Nondeterministic Finite Automaton – p.17/28 Consider the transitions Notation: for any define to be the collection of states that can be reached from by going only along transitions, including the members of themselves. Formally: Formal Definition of a Nondeterministic Finite Automaton – p.17/28 Consider the transitions Notation: for any define to be the collection of states that can be reached from by going only along transitions, including the members of themselves. Formally: Note: any can be reached from by traveling along 0 or more arrows. Formal Definition of a Nondeterministic Finite Automaton – p.17/28 Modifications Modify to place additional tokens on all states that can be reached by going along arrows after every by step. This effect is achieved by replacing in definition of . That is Formal Definition of a Nondeterministic Finite Automaton – p.18/28 Modifications Modify to place additional tokens on all states that can be reached by going along arrows after every by step. This effect is achieved by replacing in definition of . That is Formal Definition of a Nondeterministic Finite Automaton – p.18/28 Modifications Modify to place additional tokens on all states that can be reached by going along arrows after every by step. This effect is achieved by replacing in definition of . That is Modify the start state of to put tokens initially on all states that can be reached from along transitions, i.e., Formal Definition of a Nondeterministic Finite Automaton – p.18/28 Note thus constructed obviously simulates Formal Definition of a Nondeterministic Finite Automaton – p.19/28 Note thus constructed obviously simulates At every step in the computation of it clearly enters a state that corresponds to the subset of states that could be in at that point Formal Definition of a Nondeterministic Finite Automaton – p.19/28 Conclusion Since every NFA can be converted into a DFA by the procedure discussed above, NFA provides an alternative way of characterizing regular sets Formal Definition of a Nondeterministic Finite Automaton – p.20/28 Corollary 1.40 A language is regular iff some NFA recognizes it Formal Definition of a Nondeterministic Finite Automaton – p.21/28 Corollary 1.40 A language is regular iff some NFA recognizes it Proof: Formal Definition of a Nondeterministic Finite Automaton – p.21/28 Corollary 1.40 A language is regular iff some NFA recognizes it Proof: If a language is recognized by an NFA then the DFA equivalent, hence, is regular is recognized by Formal Definition of a Nondeterministic Finite Automaton – p.21/28 Corollary 1.40 A language is regular iff some NFA recognizes it Proof: If a language is recognized by an NFA then the DFA equivalent, hence, is regular is recognized by If a language is regular, it means that it is recognized by a DFA. But any DFA is also an NFA hence, the language is recognized by an NFA Formal Definition of a Nondeterministic Finite Automaton – p.21/28 described in Figure 2: b a a,b a Figure 2: The NFA Consider the NFA Example conversion NFA to DFA Formal Definition of a Nondeterministic Finite Automaton – p.22/28 where b a is given in the table: Formal description of Formal Definition of a Nondeterministic Finite Automaton – p.23/28 ’s set of states is ) Since Construction of Formal Definition of a Nondeterministic Finite Automaton – p.24/28 ’s set of states is ) : the set of states reachable from 1 ) traveling by : The start state of (the start state of Since Construction of Formal Definition of a Nondeterministic Finite Automaton – p.24/28 ’s set of states is ) : the set of states reachable from 1 ) traveling by : that The accept state of : are those states of contain the accept states of : i.e., The start state of (the start state of Since Construction of Formal Definition of a Nondeterministic Finite Automaton – p.24/28 we have and , where for each Transition function Formal Definition of a Nondeterministic Finite Automaton – p.25/28 , i.e., on both State : goes to ’s transitions Constructing Formal Definition of a Nondeterministic Finite Automaton – p.26/28 and to on on : goes to , i.e., on both State State : goes to ’s transitions Constructing Formal Definition of a Nondeterministic Finite Automaton – p.26/28 on and to on on and to : goes to on , i.e., on both : goes to State State State : goes to ’s transitions Constructing Formal Definition of a Nondeterministic Finite Automaton – p.26/28 on and to on on and to on on : goes to : goes to and to , i.e., on State State on both : goes to State State : goes to ’s transitions Constructing Formal Definition of a Nondeterministic Finite Automaton – p.26/28 on and to on on and to on on : goes to : goes to and to , i.e., on State State on both : goes to State State : goes to ’s transitions Constructing And so on, for each state Formal Definition of a Nondeterministic Finite Automaton – p.26/28 b a equivalent to NFA DFA a equivalent to NFA Figure 3: a b b a a b a,b a b b a,b Figure 3 shows the resulting DFA Putting all together Formal Definition of a Nondeterministic Finite Automaton – p.27/28 Simplifying a,b b a a The automaton may be simplified by observing that no and . Removing these arrows point at the states states we obtain the automaton in Figure 4 a b The simplified version of Figure 4: a a b b b Formal Definition of a Nondeterministic Finite Automaton – p.28/28