Non-determinism Automt Theory nd Forml Lnguges Professor Leslie Lnder Leture # 3 Septemer 6, 2 To hieve our gol, we need the onept of Non-deterministi Finite Automton with -moves (NFA) An NFA is tuple M = (Q, Σ,, δ, F), where δ is modified to e funtion δ : Q (Σ { }) P(Q) There re two spets to non-determinism: one-to-mny trnsitions spontneous trnsitions CLASS 3-7 one-to-mny trnsitions where do we go from stte? For n NFA, δ(, ) is n element of P(Q ), i.e. suset of Q, for exmple δ(, ) = {,, 3, 4 } If we re in stte nd the input is, we n hoose to move to ny one of,, 3 or 4 4 3 Of ourse, if there is no input, we n lso hoose to sty t stte Thus, if we reh stte while proessing n input string, then the next trnsition ould e from ny of the sttes,, or 3 3 CLASS 3-8 CLASS 3-9
-losure of stte First we define the -losure of stte: (i) is in -los() (ii) if -los() nd δ (, ) then -los() Thus -los() hs nd ll the sttes tht n e rehed from y seuenes of -trnsitions Exmple The sttes olored gry re ll in the set -los() CLASS 3- CLASS 3- -losure of set of sttes We n extend the definition of -los() to -los(s) for set of sttes S. -los(s) onsists of S nd ll sttes rehle from stte in S y -trnsitions -los(s) = U -los() S Extending δ We n modify δ to δ* in three steps s follows: Define δ*:q Σ P(Q) y δ*(, ) = -los(δ(, )) Next we extend s follows: δ*:p(q) Σ P(Q) y defining δ*(s, ) = U δ*(, ) S Finlly we extend to strings in Σ* CLASS 3-2 CLASS 3-3
The lnguge of n NFA Define δ*:p(q) Σ* P(Q) y δ*(s, ) = -los(s) δ*(s, w ) = δ*(δ*(s, w ), ) Rememer tht every pplition of δ*lwys dds the -losure to the set of points rehed y trnsition For n NFA lled M, the lnguge of M is denoted L(M ). L(M ) = {w Σ * : δ*(-los( ),w) F Ø} Definition of the lnguge of n NFA L(M ) = {w Σ * : δ*(-los( ),w) F Ø} Exmple: -los( ) = {, }, -los( 3 ) = {, 3 }, 3, CLASS 3-4 CLASS 3-5 Exmple-I Exmple-II δ*(-los( ), ) = δ*({, }, ) = -los(δ(, )) -los(δ(, )) = -los(ø) -los({, })={,, }, 3 δ*(-los( ), ) = δ*(δ*(-los( ),), ) = δ*({,, }, ) = -los({, 3 }) = {,, 3 }, so is epted, 3,, CLASS 3-6 CLASS 3-7
CLASS 3-8 Exmple-III δ*(-los( ), )= δ*(δ*(-los( ), ),) = δ*({,, 3 }, ) = -los({,, 3 }) = {,,, 3 }, so is epted, 3, CLASS 3-9 Wht is going on? The definition of eptne y n NFA is sutle nd hidden y ll the forml definitions Given string w = 2... n, it is epted if you n strt t nd finish t finl stte, possily using -trnsitions long the wy So we my relly e using trnsitions leled something like,,, 2,,,,, n, one pth to finl stte mens eptne Further, there my e lternte rnhes with the sme lels tht led to non-finl stte or tht go nowhere (with or without -trnsitions) The point is: n you mke the right hoie of edges nd intermedite uses of to get from to finl stte? Why non-determinism? We will see in our exmples tht n NFA n e more ompt nd intuitive thn DFA for the sme lnguge However, we hve to show tht they reognize the sme lss of lnguges, i.e. ll n NFA n do is reognize regulr lnguge ONE suh pth mens eptne of w CLASS 3-2 CLASS 3-2
CLASS 3-22 Exmple The following is one of mny NFA s tht reognize ** + ** 5 3 4 6 Converting n NFA to n euivlent DFA Given lnguge L, espeilly one desried y regulr expression, it is usully esiest to onstrut n NFA M tht reognizes the lnguge However, DFA M 2 would e esier to write progrm for, for exmple Hene we re interested in onverting M to M 2 ut ensuring L = L(M ) = L(M 2 ) CLASS 3-23 CLASS 3-24 The trik The trik is simply to onsider susets of Q, i.e. the elements of P(Q) to e sttes of new utomton Given n NFA M = (Q, Σ,, δ, F ), onsider the utomton: M 2 = (P(Q), Σ, -los( ), δ 2, F 2 ), where δ 2 = δ*: P(Q) Σ P(Q) nd F 2 is the olletion of ll susets of Q tht ontin n element of F M 2 IS DFA susets re elements of nother universe Rell tht δ*:p(q) Σ* P(Q) nd so we n restrit the funtion to words of length to otin funtion δ*:p(q) Σ P(Q) This lst δ* is deterministi euse it tkes n element of P(Q) nd symol in Σ to nother element of P(Q) Now, P(Q) is ig: if Q hs 8 elements, P(Q) hs 2 8 = 256 elements, whih is lot of sttes CLASS 3-25
Get resonle We will give onstrutive method tht only puts the rehle sttes into M 2, whih is often more mngele However, we wnt L(M ) = L(M 2 ) First, it is tedious symol-dense exerise to hek tht δ 2 * = δ*:p(q) Σ + P(Q) so eptne of w y M 2 reuires Symol-dense verifition By definition δ 2 = δ*:p(q) Σ P(Q), so onsider S in P(Q) (i.e. S Q), so δ 2 * = δ* gree on string of length We proeed y indution, suppose δ 2 * = δ* gree on ll strings of length up to n Pik string w = w, where w =n + nd so w =n δ*(-los( ), w) F 2 CLASS 3-26 CLASS 3-27 CLASS 3-28 Symol-dense verifition - 2 From slide 2-34 δ 2 *(S, w) = δ 2 *(S, w ) = δ 2 (δ 2 *(S, w ), ) = δ*(δ 2 *(S, w ), ), sine δ 2 (..., ) = δ*(..., ) y definition By the indutive hypothesis δ 2 *(S, w ) = δ*(s, w ) Therefore δ 2 *(S, w) = δ*(δ*(s, w ), ) = δ*(s, w ) = δ*(s, w) CLASS 3-29 Symol-dense verifition - 3 Also, look t the definition of δ 2 * (for deterministi trnsition funtion) δ 2 *(S, ) = S (see slide 2-34) while δ*(s, ) = -los(s) (from 3-4) These two expressions oinide if S = -los( ) sine -los(-los( )) Altogether, δ 2 *(-los( ), w) = δ*(-los( ), w)
Euivlene is esy Look t the definition of F 2 ; it tells us tht δ*(-los( ), w) is n element of F 2 preisely when δ*(-los( ), w) ontins n element of F, i.e. δ*(-los( ),w) F Ø This seond riterion defines the eptne of w y M The lnguge of the NFA is the lnguge of the DFA Prtil onversion NFA to DFA Suppose we hve n NFA trnsition tle Ø { 4 } { } { 5 } { } Ø { 3 } Ø { 5 } 3 Ø {, 4 } { } 4 Ø { 6 } { } 5 6 Ø { 6 } Ø Ø { } { } CLASS 3-3 CLASS 3-3 Trnsition grph DFA: initil stte Trnsition grph 5, 3 4 6 CLASS 3-32 The initil stte is -los{ } = {, } We fill in the δ*-trnsitions from this initil stte (so we lwys dd the -losure) {, } {,, 5 } {,,, 4, 5 } This is unwieldy, so we revite s follows:.,..5,..2.4.5, et. CLASS 3-33
CLASS 3-34 Keep dding rehle sttes Every stte we reh gets dded to the left-hnd olumn:...5..2.4.5..5..5..2.4.5..2.4.5 *..2.3.5..2.4.5.6..2.3.5 *..2.3.5..2.4.5..2.4.5.6 *..2.3.5.6..2.4.5.6..2.3.5.6 *..2.3.5.6..2.4.5 * finl sttes The DFA is smller (unusul)! The onverted DFA The finl DFA:...2.4.5.6..5..2.4.5..2.3.5 CLASS 3-35..2.3.5.6 CLASS 3-36 Notes DFA finl sttes re those ontining one of the finl sttes of the NFA A seond exmple is provided on the ourse we pges In tht exmple, there is stte Ø, whih is ded stte: one you enter ded stte you n never reh finl stte ny string tht tkes to ded stte in DFA n never e epted getting n NFA from regulr expression-i If we hve regulr expression r, we need to onstrut n NFA M so tht L(M ) = L(r ) A regulr expression whih represents lnguge with only one element denotes the lnguge epted y n NFA with liner seuene of sttes: Regulr expression NFA (in ft DFA): CLASS 3-37
getting n NFA from regulr expression-ii Finite lnguges, whih re not singletons, re lso esy: + Kleene losure - I The Kleene losure is often simple: onsider r *r 2, where r nd r 2 re regulr expressions grph for r grph for r 2 CLASS 3-38 CLASS 3-39 Kleene losure - II Kleene losure - III Next onsider r ()*r 2, where r nd r 2 re regulr expressions The following is n NFA for (++)* grph for r CLASS 3-4 grph for r 2 It is not uniue The next slide hs n lterntive CLASS 3-4
Kleene losure - IV Euivlent full-dfa (++)* The following slides hve full-dfa nd DFA with the ded stte removed. 3,,,,,,,, CLASS 3-42 CLASS 3-43 Euivlent DFA A simple sum This seond DFA should demonstrte tht the grphi is lerer without the ded sttes showing. 3 The NFA for + ould e either of the following, mong others CLASS 3-44 CLASS 3-45
A simple ontention The NFA for * ould e the following, mong others Euivlent DFA The following is the DFA derived from the previous NFA CLASS 3-46 CLASS 3-47 The stndrd onstrution NFA s for the si regulr expressions We wnt to show tht ny regulr expression hs n NFA We do this y lwys reting NFA s tht hve SINGLE FINAL STATE tht is different from We show how to omine them to uild lrger regulr expressions The si regulr expressions re,, nd nd the simplest NFA s with single initil nd finl stte re: NOTE: the following is simpler for ut does not fit the seprte initil/finl sttes property: CLASS 3-48 CLASS 3-49
The NFA for sum of regulr expressions Grph for the sum If we hve onstruted the NFA s (eh with single finl stte) for two regulr expressions r nd r 2 then the NFA for r +r 2 is shown next grph for r The two finl sttes from r nd r 2 re no longer finl. A new single finl stte is dded with -trnsitions from the old finl stte grph for r 2 CLASS 3-5 CLASS 3-5 The NFA for sum of regulr expressions - II Wht were finl sttes in the grphs of r nd r 2 re no longer finl sttes (they re shown with dotted lines round them There is only one finl stte The NFA for ontention of reg. expr. If we hve onstruted the NFA s (eh with single finl stte) for two regulr expressions r nd r 2 then the NFA for r r 2 is shown next CLASS 3-52 CLASS 3-53
Grph for the ontention The NFA for the Kleene losure of reg. expr. grph for r If we hve onstruted the NFA (eh with single finl stte) for the regulr expression r then the NFA for r * is shown next grph for r 2 grph for r CLASS 3-54 CLASS 3-55