![]() |
![]() |
|
TODO: Examples of NFA - first example: missing-letter-language (but NO epsilon-transitions) [leave it on board to come back to!] - second example: a?aab* - put up the parallel definitions with color-difference: DFSM,NDFSM [leave δ on board]; config, ⊢, computation, accepts. - then add in epsilon-transitions: go back to missing-letter-language, then def'n - emulating NDFSM: - threads -- each move in parallel on reading an input-char (Cf. unix `fork`) - backtracking - keep track of *all* possible states you might be in, after each input-char (our proof will use this approach) - [skip for now; it requires DFSM = NDFSM anyway] Show: regular languages closed under union Let L1, L2 be reg.langs; we show L1 ∪ L2 is regular. - without loss of generality, L1,L2 have same alphabet - because L1,L2 regular, there exist DFMs M1,M2 which accept them. - We construct M' such that L(M') = L(M1 ∪ M2): K' = Σ (already presumed same) s = Δ' = ... (here's the sticky part!) ... A' = ---- examples of *building* a NDFSM: handy for pattern-matching: - All strings which contain 'ababb' in them. First, as a DFSM. Now, as a NDFSM. - strings containing "ababb" *or* containing "abaa". eps: KM → P(KM). We define eps(q), where q is some state in M, to be the set of states of M that are reachable from q by following zero or more -transitions. Formally: eps(q) = {p K : (q, w) |-M* (p, w)}. Alternatively, eps(q) is the closure of {q} under the relation {(p, r) : there is a transition (p, , r) }. The following algorithm computes eps: eps(q: state) = 1. result = {q}. 2. While there exists some p result and some r result and some transition (p, , r) do: Insert r into result. 3. Return result. This algorithm is guaranteed to halt because, each time through the loop, it adds an element to result. It must halt when there are no elements left to add. Since there are only a finite n Book 5.4.4: equivalence of DFSM, NDFSM (!) Two directions. - one trivial - other: Given a NDFSM M=<>, we construct a DFSM M'=<...> where: K' = Σ' = s' = δ' = A' = Example: - p.56 (Example 5.20); this is in ppts slides OR - give a DFA for: L1= (ab)* [DFA as good as NFA] - give a DFA for: L2= (aba)+ [DFA as good as NFA] - give a NDFSM for: L1 ∪ L2 - convert this to a DFSM, using subset-construction: [be sure to view table this in a mono-width font!] megastate Q | eps(Q) | eps(δ(Q,a)) | eps(δ(Q,b)) | ------------+---------+---------------+--------------+ {0} | {0,1,3} | {2,4} | φ | Proof of correctness of construct: - Lemma: a NDFSM w/ eps can turned into one w/o eps Given a NDFSM M: for every a transition <p,ε,q> ∈ Δ, then for every <eps(q),c,r> ∈ Δ, then add the direct edge <p,c,r>. [ian: rephrase the above a bit?] Proof left to the reader [formalizing it needs to be more precise about eps(q) being transitive-closure of eps-transits-from-q]. (this is also in Appendix B (p. 627 = 643-15), slightly different presentation) Put on board: Reminder: M -- the NONeterministic machine; M' -- the deterministic one we built - Note the key element of construction of M': δ(P,c) = union_p∈P {r : Δ(p,c,r)} review subset-constr-equiv proof: - PROOF: Show L(M) = L(M') - L(M) ⊆ L(M') induction on |w| straightforward: Let Goal(k) be “for any string w with |w|=k: if <p,w> |-* <q,ε> in the NDFSM M, then <P,w> |-* <Q,ε> where P is *any* mega-state including p, and Q is *some* mega-state involving q” (Note: if q happens to is accepting in M, then Q is accepting in M'.) - base case Goal(0) trivial: p=q,w=ε: then let P be any state in M' with p ∈ P. <P,ε> ⊢* <P,ε> , which is a state containing q=p∈P. - induct step: Goal(k-1)⇒Goal(k): Let w = cx, so |x|=k-1. By def'n of w∈L(M), we know (nondeterm.) there's *some* sequence <p,cx> |- <r,x> |-* <q,ε> (where q accepts in M) [Note: that first step consumes a char becase no more eps-transits by our lemma above]. By construction, we know (determ.) that <P,cx> |- <R,x>, where r∈R. [Recall how we defined δ above.] By inductive hyphothesis (Goal(k-1)): since <r,x> |-* <q,ε>, then we know that: <R,x> |-* <Q,ε> (since R is "any state including r"). If w∈L(M), then q was an accepting state in M, then (by construction) Q is an accepting state in M', so we have <P,w> |- <Q,ε>, meaning w∈L(M'). - L(M') ⊆ L(M) That is: if <P,w> |-* <Q,ε> in M', then for all q in Q, there is some p in P: <p,w> |-* <q,ε> in the NDFSM M ** This step is a bit trickier (?). Induct on |w|: Let Goal(k) be “for any string w with |w|=k: if <P,w> |-* <Q,ε> in the DFSM M', then for all q in Q, there is some p in P: <p,w> |-* <q,ε> in the NDFSM M.” (harder because each step of computation in M' involves many states of M; we have to "pick out" the specific path in M that makes it all the way from p to q.) - base case still easy; - induct step: Let w = cx, where |x|=k. We know: <P,cx> |- <R,x> |-* <Q,ε> where R is: all states M could reach from any p on c: R = union_p∈P {r : Δ(p,c,r)} We want to show that <p,w> |-* <q,ε> in M (for *all* q∈Q) By induct hyp, for every q∈Q there's some r∈R such that: <r,x> |-* <q,ε> in M By def'n of δ, we know [ R = union_p∈P {r : (p,c,r)∈Δ}.], so there is *some* p in P where (p,c,r) was in M's Δ. Thus: there's some p in P <p,cx> |- <r,x> |-* <q,e> <P,cx> |- <R,x> means that for every p in P: <p,cx> |- <r,x> (for some r in R) and for that r <r,x> |-* <q,ε> for some q in Q But then <p,cx> |- <r,x> |-* <q,ε>,which is what we want to show! [Note: book's appendix B "lemma",p.627 made me unsure for a moment: it talks of eps(q) for any q in M, but is eps(q) even a state we constructed in M'? Ah, okay: I guess we do define *all* those states; some might be unreachable but that doesn't hurt their proof.]
This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |