91 304 foundations of th theoretical computer science ti
play

91.304 Foundations of (Th (Theoretical) Computer Science ti l) C - PowerPoint PPT Presentation

91.304 Foundations of (Th (Theoretical) Computer Science ti l) C t S i Chapter 1 Lecture Notes (Section 1.2: NFAs) David Martin dm@cs uml edu dm@cs.uml.edu With some modifications by Prof. Karen Daniels Slides also added from http: /


  1. 91.304 Foundations of (Th (Theoretical) Computer Science ti l) C t S i Chapter 1 Lecture Notes (Section 1.2: NFA’s) David Martin dm@cs uml edu dm@cs.uml.edu With some modifications by Prof. Karen Daniels Slides also added from http: / / cis.k.hosei.ac.jp/ ~ yukita/ in some places. This work is licensed under the Creative Commons Attribution-ShareAlike License. To view a copy of this license, visit http: / / creativecommons.org/ licenses/ by- sa/ 2.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. 1

  2. Nondetermistic Finite Automata Nondetermistic Finite Automata � A nondeterministic finite automaton can be different from a deterministic one in that � � for any input symbol nondeterministic one can for any input symbol, nondeterministic one can transit to more than one state. epsilon transition ( ε ), which “consumes” no input � symbols symbols � NFA and DFA stand for nondeterministic finite automaton and deterministic finite automaton , respectively. � � NFAs and DFAs a e eq all po NFAs and DFAs are equally powerful, but NFA adds e f l b t NFA adds notational power that can simplify descriptions. � Example: L&P 2 variation on http: / / cis.k.hosei.ac.jp/ ~ yukita/

  3. Nondeterministic Finite Automata � Will relax two of these DFA rules: � Will relax two of these DFA rules: 1. Each (state, char) input must produce exactly one (state) output e ac y o e (s a e) ou pu 2. Must consume one character in order to advance state � The NFA accepts the input if there exists any way of reading the input that winds up in an accepting state that winds up in an accepting state at the end of the string � Otherwise it rejects the input � Otherwise it rejects the input 3

  4. Example: NFA N 2 0 1 0,1 Note: no exiting arrow for 0 or 1. 0,1 0, 1 1 q 3 q 4 q 1 q 2 Let language A consist of all strings over {0,1} containing a 1 in the third g g g { } g position from the end. N 2 recognizes A . Note: Multiple choice on input 1 from state q 1 makes this an NFA. Later we show a DFA equivalent to this NFA using construction of Thm 1 39 Later we show a DFA equivalent to this NFA using construction of Thm. 1.39. 4 variation on http: / / cis.k.hosei.ac.jp/ ~ yukita/

  5. NFA N 1 0,1 0,1 Note: no exiting Note: no exiting arrow for 0. arrow for 1. 1 0, ε 1 1 0 q 3 q 4 q 1 q 2 Now introduce ε . What language does this NFA accept? 5 variation on http: / / cis.k.hosei.ac.jp/ ~ yukita/

  6. NFA N 1 Execution on input 010110 Source: Sipser Textbook Note pictorial Note pictorial “jump” on ε to next state. This varies slightly from transition function depiction on p. 54. How does N N 1 behave b h on input 6 01001?

  7. Ways to think of NFAs � NFA � NFAs w ant to accept inputs and will t t t i t d ill always take the most advantageous alternative(s) alternative(s) � Because they will accept if there exists any way to get to an accepting state at any way to get to an accepting state at the end of the string � The quickest way there may be just one q y y j of many ways, but it doesn’t matter 7

  8. Ways to think of NFAs a a a � fork() model � fork() model � Input string is in a variable � fork() at every nondeterministic choice point � subprocess 1 (parent) follows first transition � subprocess 2 (child) follows second � subprocess 3 (child) follows third (if any), etc. p ( ) ( y), � A process that can’t follow any transition calls exit() -- and gives up its ability to accept � � A process that makes it through the whole string A process that makes it through the whole string and is in an accepting state prints out “ACCEPT” � A single ACCEPT is enough 8

  9. Parallel world and NFA reject accept p 9 variation on http: / / cis.k.hosei.ac.jp/ ~ yukita/

  10. Syntax of DFA (repeat) � � A determ inistic finite autom aton A determ inistic finite autom aton ( DFA) is a 5-tuple (Q, Σ , δ ,q 0 ,F) such that 1. Q is a finite set of states Q s a te set o states Σ is an alphabet 2. δ : Q × Σ → Q is the transition function 3. 4 4. q ∈ Q is the start state q 0 ∈ Q is the start state 5. F ⊆ Q is the set of accepting states � � Usually these names are used but others Usually these names are used, but others are possible as long as the role is clear 10

  11. Syntax of NFA � � A nondeterm inistic finite autom aton A nondeterm inistic finite autom aton ( NFA) is a 5-tuple (Q, Σ , δ ,q 0 ,F) such that 1. Q is a finite set of states Q s a te set o states Σ is an alphabet 2. δ : Q × ( Σ ∪ { ε } ) → P ( Q ) is the transition function 3. 4 4. q ∈ Q is the start state q 0 ∈ Q is the start state 5. F ⊆ Q is the set of accepting states � � Usually these names are used but others Usually these names are used, but others are possible as long as the role is clear Note: Σε = Σ U { ε } (see p. 53) 11

  12. NFA N 1 (again) p. 54 0,1 0,1 = 1 Q 1. { { , , , }, } Q q q q q 0, ε 1 1 1 2 3 4 q 3 q 4 Σ = q 1 q 2 2. { 0 , 1 } ε ε 0 0 1 1 ∅ { } { , } q q q q 1 1 1 2 δ δ ∅ ∅ 3. 3. is is given given as as { { } } { { } } q q q q q q 2 2 3 3 3 3 Note the use of ∅ ∅ { } q q sets here in 3 4 ∅ contrast to DFA. { { } } { { } } q q q q q q 4 4 4 4 4 4 4. is the start state. q 1 = 5. { }. F q 4 Board work: Resolve transition table with Figure 1.29 for ε . 12 variation on http: / / cis.k.hosei.ac.jp/ ~ yukita/

  13. The Subset Construction Th Theorem 1 .3 9 For every NFA M 1 there 1 3 9 F NFA M th exists a DFA M 2 such that L(M ) = L(M ) L(M 1 ) = L(M 2 ). Corollary 1 .4 0 A language is REGular if and only if some nondeterministic and only if some nondeterministic finite automaton recognizes it. 13

  14. The Subset Construction Proof: Let N= (Q Σ δ q 0 F) be the NFA and define the DFA (Q, Σ , δ ,q 0 ,F) be the NFA and define the DFA Proof: Let N M= (Q’, Σ , δ ’, q 0 ’,F’) as follows: 1. Q’ = P (Q). � � Each state of the DFA records the set of states that Each state of the DFA records the set of states that the NFA can simultaneously be in � Can compare DFA states for equality but also look "inside" the state name to find a set of NFA state names names 2. Define: E(R) = { q| q is reachable from R via ε arrow(s)} δ δ = ∈ ∈ δ δ ∈ ' ' ( ( R R , ) ) { { Q Q | | E E ( ( ( ( , )) )) f for some R R } } a q q r a r Go to whatever states are reachable from the states in R and reading the character a in R and reading the character a Remember: in an NFA, 14 δ : Q × Σ ε → P (Q) from def

  15. The Subset Construction 3 3. q ’ = E({ q } ) q 0 = E({ q 0 } ) 4. F’= { R ∈ Q’ | R contains an accept state of N} The effect is that the DFA knows all states that are The effe t i th t the DFA kno ll t te th t e reachable in the NFA after reading the string so far. If any one of them is accepting, then the current DFA state is accepting too, otherwise it's not. state is accepting too, otherwise it s not. If you believe this then that's all it takes to see that the construction is correct So convince yourself with an construction is correct. So, convince yourself with an example. QED 15

  16. Example: NFA N 2 (again) 0 1 0,1 0,1 0, 1 1 q 3 q 4 q 1 q 2 Let language A consist of all strings over {0,1} containing a 1 in the third g g g { } g position from the end. N 2 recognizes A . No ε ’s in this example. 16 variation on http: / / cis.k.hosei.ac.jp/ ~ yukita/

  17. A DFA equivalent to N 2 0 0 0 0 q 010 q q 110 q q 000 q q 100 q 1 0 1 1 0 0 1 0 1 1 1 q 011 q 111 q 001 q 101 1 Board work: Start with all 16 17 states, including unreachables. Variation on http: / / cis.k.hosei.ac.jp/ ~ yukita/

  18. Example 1.41 NFA N 4 to DFA 1 b a ε ε a 3 2 a,b 4 = δ Given {{ 1 , 2 , 3 }, { , }, , 1 , { 3 }} , we want to construct N a b an an equivalent equivalent DFA DFA . ' s s state state set set may may be be expressed expressed as as D D D D = ∅ { 1 , 2 , 3 } 2 { , { 1 }, { 2 }, { 3 }, { 1 , 2 }, { 1 , 3 }, { 2 , 3 }, { 1 , 2 , 3 }}. 18 variation on http: / / cis.k.hosei.ac.jp/ ~ yukita/

  19. The state diagram of D unreachable unreachable a,b a b φ φ {1,2} {2} {1} a,b b b a b a a a a { , } {2,3} {1,2,3} { } {3} {3} {1,3} {1 3} a b b Done in textbook. D i b k 19 variation on http: / / cis.k.hosei.ac.jp/ ~ yukita/

  20. Subset construction conclusion � Adding nondeterminism makes programs � Adding nondeterminism makes programs shorter but not able to do new things � Remember: regular languages are defined to be those "recognized by a DFA" to be those recognized by a DFA � We now have a result that says that every language that is recognized by an NFA is regular too l t � So if you are asked to show that a language is regular, you can exhibit a DFA or NFA for it and rely on the subset construction theorem rely on the subset construction theorem � Sometimes questions are specifically about DFAs or NFAs, though... pay attention to the precise wording g 20

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