
Algorithms & Models of Computation CS/ECE 374, Fall 2017 Part I Non-deterministic Finite Automata (NFAs) NFA Introduction Lecture 4 Thursday, September 7, 2017 Sariel Har-Peled (UIUC) CS374 1 Fall 2017 1 / 39 Sariel Har-Peled (UIUC) CS374 2 Fall 2017 2 / 39 Non-deterministic Finite State Automata (NFAs) NFA behavior 0,1 0,1 0 0 1 qε q0 q00 qp ε Differences from DFA Machine on input string w from state q can lead to set of states From state q on same letter a 2 Σ multiple possible states (could be empty) No transitions from q on some letters From q" on 1 "-transitions! From q" on 0 Questions: From q0 on " Is this a \real" machine? From q" on 01 What does it do? From q00 on 00 Sariel Har-Peled (UIUC) CS374 3 Fall 2017 3 / 39 Sariel Har-Peled (UIUC) CS374 4 Fall 2017 4 / 39 NFA acceptance: informal NFA acceptance: example Is 01 accepted? Informal definition: An NFA N accepts a string w iff some accepting state is reached by N from the start state on input w. Is 001 accepted? Is 100 accepted? The language accepted (or recognized) by a NFA N is denote by Are all strings in 1∗01 accepted? L(N) and defined as: L(N) = fw j N accepts wg: What is the language accepted by N? Comment: Unlike DFAs, it is easier in NFAs to show that a string is accepted than to show that a string is not accepted. Sariel Har-Peled (UIUC) CS374 5 Fall 2017 5 / 39 Sariel Har-Peled (UIUC) CS374 6 Fall 2017 6 / 39 Simulating NFA Formal Tuple Notation Example the first a,b 0,1 0,1 a,b Definition A non-deterministic finite automata ( ) N = (Q; Σ; δ; s; A) is 0 0 1 NFA qε a q0 b q00 a qp b a five tuple where (N1) A B ε C D E Q is a finite set whose elements are called states, Run it on input ababa. Σ is a finite set called the input alphabet, Idea: Keep track of the states where the NFA might be at any given δ : Q × Σ [ f"g ! P(Q) is the transition function (here time. a,b a,b P(Q) is the power set of Q), t =0: s 2 Q is the start state, a b a b A ⊆ Q is the set of accepting/final states. A B C D E Remaining input: ababa. δ(q; a) for a 2 Σ [ f"g is a subset of Q | a set of states. a,b a,b t =1: a b a b A B C D E Sariel Har-Peled (UIUC) CS374 7 Fall 2017 7 / 39 Sariel Har-Peled (UIUC) CS374 8 Fall 2017 8 / 39 Remaining input: baba. a,b a,b t =2: a b a b A B C D E Remaining input: aba. a,b a,b t =3: a b a b A B C D E Remaining input: ba. a,b a,b t =4: a b a b A B C D E Remaining input: a. a,b a,b t =5: a b a b A B C D E Remaining input: ". Accepts: ababa. Reminder: Power set Example For a set Q its power set is: P(Q) = 2Q = fX j X ⊆ Qg is the set of all subsets of Q. Example Q = f1; 2; 3; 4g Q = fq"; q0; q00; qpg 8 9 Σ = f0; 1g > f1; 2; 3; 4g ; > > > δ <> f2; 3; 4g ; f1; 3; 4g ; f1; 2; 4g ; f1; 2; 3g ; => P(Q) = f1; 2g ; f1; 3g ; f1; 4g ; f2; 3g ; f2; 4g ; f3; 4g ; s = q" > > > f1g ; f2g ; f3g ; f4g ; > A = fqpg :> fg ;> Sariel Har-Peled (UIUC) CS374 9 Fall 2017 9 / 39 Sariel Har-Peled (UIUC) CS374 10 Fall 2017 10 / 39 Example Extending the transition function to strings Transition function in detail... 0,1 0,1 1 NFA N = (Q; Σ; δ; s; A) 2 δ(q; a): set of states that N can go to from q on reading 0 0 1 qε q0 q00 qp ε a 2 Σ [ f"g. 3 Want transition function δ∗ : Q × Σ∗ !P(Q) 4 δ∗(q; w): set of states reachable on input w starting in state q. δ(q0;") = fq0; q00g δ(q";") = fq"g δ(q0; 0) = fq00g δ(q"; 0) = fq"; q0g δ(q0; 1) = fg δ(q"; 1) = fq"g δ(q00;") = fq00g δ(qp;") = fqpg δ(q00; 0) = fg δ(qp; 0) = fqpg δ(q00; 1) = fqpg δ(qp; 1) = fqpg Sariel Har-Peled (UIUC) CS374 11 Fall 2017 11 / 39 Sariel Har-Peled (UIUC) CS374 12 Fall 2017 12 / 39 Models of Computation Lecture : Nondeterministic Automata [Fa’] the NFA somehow chose a path to an accept state still exist. One slight disadvantage of this metaphor is that if an NFA reads a string that is not in its language, it destroys all universes. Proofs/oracles. Finally, we can treat NFAs not as a mechanism for computing something, but as a mechanism for verifying proofs. If we want to prove that a string w contains one of the suffixes 00 or 11, it suffices to demonstrate a single walk in our example NFA that starts at s and ends at c, and whose edges are labeled with the symbols in w. Equivalently, whenever the NFA faces a nontrivial choice, the prover can simply tell the NFA which state to move to next. This intuition can be formalized as follows. Consider a deterministic finite state machine whose input alphabet is the product ⌃ ⌦ of an input alphabet ⌃ and an oracle alphabet ⌦. Equivalently, we can imagine that this DFA⇥ reads simultaneously from two strings of the same length: the input string w and the oracle string !. In either formulation, the transition function has the form δ: Q (⌃ ⌦) Q. As usual, this DFA accepts the pair (w, !) (⌃ ⌦)⇤ if and ⇥ ⇥ ! 2 ⇥ only if δ⇤(s, (w, !)) A. Finally, M nondeterministically accepts the string w ⌃⇤ if there is 2 2 an oracle string ! ⌦⇤ with ! = w such that (w, !) L(M). 2 | | | | 2 . "-Transitions It is fairly common for NFAs to include so-called "-transitions, which allow the machine to change stateExtending without reading the an transition input symbol. function An NFA with to" strings-transitions accepts a string w Extending the transition function to strings a1 a2 a3 a` if and only if there is a sequence of transitions s q1 q2 q` where the final ! ! ! ··· ! state q` isDefinition accepting, each ai is either " or a symbol in ⌃, and a1a2 a` = w. Definition ··· For example,For NFA considerN = the (Q following; Σ; δ; s; NFAA) and withq"-transitions.2 Q the reach (For this(q) example,is the set we indicate For NFA N = (Q; Σ; δ; s; A) and q 2 Q the reach(q) is the set the "-transitionsof all states using large that redq can arrows; reach we using won’t only normally"-transitions. do that.) This NFA deliberately has of all states that q can reach using only "-transitions. more "-transitions than necessary. 0 0 Definition a b c ∗ ∗ ε Inductive definition of δ : Q × Σ !P(Q): ε ∗ 1,0 s ε ε g 1,0 if w = ", δ (q; w) = reach(q) ε ε if w = a where a 2 Σ d e f δ∗(q; a) = [ ([ reach(r)) 1 1 p2reach(q) r2δ(p;a) An NFA with "-transitions if w = ax, ∗ ∗ δ (q; w) = [p2reach(q)([r2δ(p;a)δ (r; x)) The NFA starts as usual in state s. If the input string is 100111, the the machine might non-deterministically choose the following transitions and then accept. 1 " " 0 0 " 1 1 " 1 " " s Sariels Har-Peledd (UIUC) a b cCS374d 13e f e f Fall 2017c 13g / 39 Sariel Har-Peled (UIUC) CS374 14 Fall 2017 14 / 39 ! ! ! ! ! ! ! ! ! ! ! ! More formally, the transition function in an NFA with "-transitions has a slightly larger Q domain δ: Q (⌃ " ) 2 . The "-reach of a state q Q consists of all states r that satisfy one of theFormal following⇥ [ conditions:{definition} ! of language accepted2 by N Example • either r = q, Definition • or r δ(q0, ") for some state q0 in the "-reach∗ of q. A2 string w is accepted by NFA N if δN (s; w) \ A 6= ;. In other words, r is in the "-reach of q if there is a (possibly empty) sequence of "-transitions leading fromDefinitionq to r. For example, in the example NFA above, the "-reach of state f is a, c, d, f , g . { } The language L(N) accepted by a NFA N = (Q; Σ; δ; s; A) is What is: fw 2 Σ∗ j δ∗(s; w) \ A 6= ;g: δ∗(s; ) δ∗(s; 0) Important: Formal definition of the language of NFA above uses δ∗ δ∗(c; 0) and not δ. As such, one does not need to include "-transitions ∗ closure when specifying δ, since δ∗ takes care of that. δ (b; 00) Sariel Har-Peled (UIUC) CS374 15 Fall 2017 15 / 39 Sariel Har-Peled (UIUC) CS374 16 Fall 2017 16 / 39 Another definition of computation Why non-determinism? Definition Non-determinism adds power to the model; richer programming w language and hence (much) easier to \design" programs q −!N p: State p of NFA N is reachable from q on w () Fundamental in theory to prove many theorems there exists a sequence of states r0; r1;:::; rk and a sequence x1; x2;:::; xk where xi 2 Σ [ f"g, for each i, such that: Very important in practice directly and indirectly r0 = q, Many deep connections to various fields in Computer Science and Mathematics for each i, ri+1 2 δ(ri ; xi+1), rk = p, and Many interpretations of non-determinism.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages10 Page
-
File Size-