Nondeterministi Finite utomt The Power of Guessing Tuesdy, Otoer 4, 2 Reding: Sipser.2 (first prt); Stoughton 3.3 3.5 S235 Lnguges nd utomt eprtment of omputer Siene Wellesley ollege Finite utomton (F) Finite utomt (F) re generlized Fs in whih trnsitions my e leled with ny string (inluding ). n edge with ommseprted strings P, Q Strt is n revition for multiple edges P F Q Nondeterministi Finite utomt 5-2 Leled Pths leled pth in n F is ny pth in whih eh edge is leled y the string Strt on the trnsition tken. The lel of pth is the ontention of ll the edge strings. Some leled pths nd their lels in F : Nondeterministi Finite utomt 5-3 " " " " " ; lel of this pth is " " " ; lel of this pth is ; lel of this pth is F Nondeterminism in Fs In F, there is unique pth with lel s from every stte. This is why they re deterministi. Strt ut in n F, there my e ny numer (inluding ) pths with lel s from stte. This mkes them nondeterministi..g., pths with lel strting t : " " " " " " " " " " " Nondeterministi Finite utomt 5-4 F
epted Strings in n F Prtiing eptne n F epts string s if there is some* leled pth with lel s from its strt stte to finl stte. F Whih of the following strings re epted y F? F * The some is required y the nondeterminism of Fs. Strt Strt F epts vi " " " " F does not ept F epts vi: () " " " " (2) " " " " " " (3) " " " " ut not vi " " " " " " Nondeterministi Finite utomt 5-5 Nondeterministi Finite utomt 5-6 n eptne lgorithm y xmple Is epted y F? Form leled grph in whih. Root node is (, ) 2. For eh node (Q, s pre @ s rest ) nd F trnsition s pre Q Q there s n edge leled s pre to node (Q, s rest ) Strt F More eptne xmples Run the eptne lgorithm on the following exmples: Strt F 3. ept if rete node (Q finl,) for some finl stte Q finl ; (, ) otherwise rejet. This lgorithm is gurnteed to terminte. Why? Nondeterministi Finite utomt 5-7 Nondeterministi Finite utomt 5-8
The Lnguge of n F The lnguge of n F is the set of ll strings it epts. F Relting Fs nd Fs lerly, Fs n speify ny lnguge tht Fs n. ut n Fs speify more lnguge thn Fs? Is there lnguge tht Fs n speify ut Fs nnot? Strt Wht is lnguge(f ) in nglish? Surprisingly, the nswer is no: oth Fs nd Fs desrie extly the sme lnguges = regulr lnguges. We ll prove this in next leture y showing how to trnsform Fs to equivlent Fs. For the rest of this leture, we ll fous on. How to design Fs 2. How to formlize Fs 3. How to use Fs in Forln Nondeterministi Finite utomt 5-9 Nondeterministi Finite utomt 5- The Power of Fs If Fs n t speify more lnguges thn Fs, why do we re out them? euse they re usully more onvenient Whih of the following would you rther speify? eterministi Finite utomton Nondeterministi Finite utomton esigning Finite utomt esign Fs for eh of the following lnguges in {} * :. ll strings ontining. 2. ll strings ontining,, or. 3. ll strings with penultimte. 4. ll strings omposed out of loks of nd (inluding ) 5. ll strings in whih ppers somewhere fter. 6. ll strings denoting integers tht re multiples of 3 or 5. Nondeterministi Finite utomt 5- Nondeterministi Finite utomt 5-2
reful with omplements Unlike with Fs, omplementing n F does not neessrily omplement the epted lnguge Why? xmple: Wht lnguges re epted y these Fs? Formlizing Finite utomt F Strt n F is quintuple (Q, #, T, s, F). Q is finite set of sttes ( {,,,,}, 2. # is n lphet {, }, 3. T is trnsition reltion $ Q x #* x Q see next slide, 4. s in Q is strt stte, 5. F $ Q is set of finl sttes {,,}) Nondeterministi Finite utomt 5-3 Nondeterministi Finite utomt 5-4 Speifying n F Trnsition Reltion T F in Forln Syntx T $ Q x #* x Q egin stte string end stte Strt Trnsition reltion T for F : { (,, ), (,, ), (,, ), (,, ), (,, ), (,, ), (,,), (,, ), (,, ), (,, ) } F ontents of file f.f {sttes},,,, {strt stte} Strt {epting sttes},, {trnsitions}, -> ;, % -> ;, -> ;, -> ;, -> ;, -> ;, -> ; F, -> ;, -> Nondeterministi Finite utomt 5-5 Nondeterministi Finite utomt 5-6
Testing eptne in Forln onfusing Terminology - vl f = F.input("f.f"); vl f = - : f - F.epted; vl it = fn : f -> str -> ool Strt - F.epted f (Str.fromString ""); vl it = true : ool - F.epted f (Str.fromString ""); vl it = flse : ool F We ll use Stoughton s terminology for lssifying utomt, whih differs from Sipser s. (There s no generl greement.) Stoughton F (Finite utomton); Uses % in ple of. F (mpty-string Finite utomton) NF (Nondeterministi Finite utomton) F (eterministi Finite utomton Trnsition funtion or reltion T Stoughton $ Q x #* x Q T Stoughton $ Q x (# U ) x Q % Sipser & Q x (# U ) ' P(Q) T Stoughton $ Q x # x Q Sipser oesn t onsider this. lls this NF; Uses # for (# U ) oesn t onsider this. % Stoughton, Sipser & Q x # ' Q lls this F. Nondeterministi Finite utomt 5-7 Nondeterministi Finite utomt 5-8 Trnsition Reltions vs. Trnsition Funtions lssifition xmples: F, F, NF, or F? Stoughton uses trnsition reltion to speify F trnsitions: T Stoughton $ Q x #* x Q egin stte string end stte Sipser uses trnsition funtion to speify NF trnsitions: % Sipser & Q x (# U {}) ' P(Q) stte symol or empty string set of sttes F G H T Stoughton = { (R,, R), (R,, S), (S,, R), (S,, R),} R, S % Sipser = { ((R, ), {R}), ((R, ), {}) ((R, ), {R,S}), ((S, ), {R,S}), ((S, ), {R}), ((S, ), {}) } euse reltions re esier to mnipulte (e.g, ompose, invert), we ll use Stoughton s reltions rther thn Sipser s funtions for Fs. I J K L, M N O,, P Nondeterministi Finite utomt 5-9 Nondeterministi Finite utomt 5-2
onverting etween utomt in Forln F.injToF: ef -> f NF.injToF: nf -> ef F.injToNF: df -> nf F F NF F ftof: f -> ef eftonf: ef -> nf nftof: nf -> df Forln lso provides: F.injToF: df -> f Next leture we ll study how the red onversions work We n esily define: vl ftof = nftof o eftonf o ftof Other Forln F Opertions - vl renmesttes : f * sym_rel -> f - vl renmesttesnonilly : f -> f - vl isomorphism : f * f * sym_rel -> ool (* s for F *) - vl findisomorphism : f * f -> sym_rel - vl isomorphi : f * f -> ool - vl simplify : f -> f (* remove ded nd unrehle sttes* ) - vl union : f * f -> f (* union of two Fs *) - vl ont : f * f -> f (* ontention of two Fs *) - vl losure : f -> f (* Kleene str of n F *) - vl rev : f -> f (* Reversl of n F (PS6) *) o F does not provide omplement nd intersetion These re defined only for the F module. o ut F does provide the union opertor missing for F. Nondeterministi Finite utomt 5-2 Nondeterministi Finite utomt 5-22 esigning Fs nd Fs in Forln zero.f one.f Given Forln files with the ove two Fs, use Forln to onstrut n F nd F for the following lnguge: ll inry strings tht either () ontin only s or (2) onsist of ny numer of s Nondeterministi Finite utomt 5-23