Finit Automt Bsic id: FA is mchin tht chngs stts whil procssing symols, on t tim. Finit st of stts: Q = {q 0, q 1, q 3,..., q k } Trnsition function: Initil stt: Finl stts: d: Q S Q q 0 Q F Q Finit utomton is M=(Q, S, d, q 0, F) q 1 q i q 0 q k q j Ex: n FA tht ccpts ll odd-lngth strings of zros: 0 q 0 q 1 M=({q 0,q 1 }, {0}, {((q 0,0),q 1 ), ((q 1,0),q 0 )}, q 0, {q 1 }) 0
Finit Automt FA oprtion: consum string w S * on symol t tim whil chnging stts Accptnc: nd up in finl stt Rjction: nything ls (including hng-up / crsh) Ex: FA tht ccpts ll strings of form = () * M M=({q 0,q 1 }, {,}, {((q 0,),q 1 ), ((q 1,),q 0 )}, q 0, {q 0 }) q 0 q 2 q 1 But M crshs on input string! Solution: dd dd-nd stt to fully spcify M M, M =({q 0,q 1,q 2 }, {,}, {((q 0,),q 1 ), ((q 1,),q 0 ), ((q 0,),q 2 ), ((q 1,),q 2 ). ((q 2,),q 2 ), ((q 2,),q 2 ) }, q 0, {q 0 })
Finit Automt Trnsition function d xtnds from symols to strings: d:q S* Q d(q 0,wx) = d(d(q 0,w),x) whr d(q i,) = q i Lngug of M is L(M)={w S* d(q 0,w) F} Dfinition: A lngug is rgulr iff it is ccptd y som FA. L is rgulr iff thr is FA M whr L(M)=L Equivlntly: A lngug is rgulr iff it cn dscrid y rgulr xprssion (proof nxt tim)
Giv Rgulr Exprssion for th following lngugs ovr Σ={,} 1. L={w w dos not contin th lttr } 2. L={w w is odd} + + + 3. L={w w hs n odd numr of s followd y n vn numr of s}
Giv FA for th following lngugs ovr Σ={,} 1. L={w w dos not contin th lttr } 2. L={w w is odd} vn s,, s odd, ( s, s, Σ, { s,, s, s,, s, ( s,, s), ( s,, s)}, s, { s}) ( vn, odd, Σ, { vn,, odd, vn,, odd, ( odd,, vn), ( odd,, vn)}, vn, {odd}) 3. L={w w hs n odd numr of s thn n vn numr of s}, E s fil O s O s E s
Closur proprtis of Rgulr Lngugs An oprtion prsrvs rgulrity if: Givn ll input lngugs r rgulr Th output lngug must rgulr Th rgulr lngugs r closd undr: Union:L 1 + L 2 or L 1 L 2 Conctntion: L 1 L 2 or L 1 L 2 Kln closur: L Rvrsl: L R = w w R L} Complmnt: L or L c Intrsction: L 1 L 2 Sutrction: L 1 L 2 Among mny othr things (s prolm sts)
Prolm: dsign DFA tht ccpts ll strings ovr {,} whr ny s prcd ny s. Id: skip ovr ny contiguous s, thn skip ovr ny s, nd thn ccpt iff th nd is rchd., q 0 q 1 q 2 L = ** Q: Wht is th complmnt of L?
Prolm: wht is th complmnt of L = **? Id: writ rgulr xprssion nd thn simplify. L = (+)* + (+)* + (+)* = (+)*(+)*(+)* = (+)* + (+)* = (+)*(+)* = * + (+)*, q 0 q 1 q 2
Thorm: Complmnt Prsrvrs Rgulrity. Proof: Givn FSA for lngug L (cll it M), construct FSA for th lngug L (cll it M ). From th mchin M to uild M convrt vry finl stt to non-finl stt, vry non-finl stt to finl stt. L={w w is odd} L ={w w is vn} vn,, odd vn,, odd M = ( vn, odd, Σ, { vn,, odd, vn,, odd, ( odd,, vn), ( odd,, vn)}, vn, {odd}) M = ( vn, odd, Σ, { vn,, odd, vn,, odd, ( odd,, vn), ( odd,, vn)}, vn, {vn}) M = Q, Σ, δ, q 0, F M = (Q, Σ, δ, q 0, F)
Thorm: Union Prsrvrs Rgulrity. Proof: Cross Product Construction Simult oth mchins in prlll Lt ch stt in th nw mchin pir of stts. Trnsitions occur s if ch mchin rn individully. Accpt if ndd in finl stt for ithr mchin. To union rgulr lngugs L 1 nd L 2 : (FSA M 1 = Q 1, Σ, δ 1, q 1, F 1, M 2 = Q 2, Σ, δ 2, q 2, F 2 rspctivly) M 1 2 = Q 1 Q 2, Σ, δ 1 2, q 1, q 2, F 1 2 Whr: s s, {w w dos not contin th lttr } vn,, odd {w w is odd} δ 1 2 q i, q j, σ = δ 1 q i, σ, δ 2 q j, σ, F 1 2 = {(q i, q j ) q i F 1 q j F 2 } E O E, O, {w w is odd or contins no s}
Thorm: Intrsction Prsrvrs Rgulrity. Proof: L 1 L 2 = L 1 L 2 To intrsct rgulr lngugs L 1 nd L 2 : (FSA M 1 = Q 1, Σ, δ 1, q 1, F 1, M 2 = Q 2, Σ, δ 2, q 2, F 2 rspctivly) M 1 2 = Q 1 Q 2, Σ, δ 1 2, q 1, q 2, F 1 2 Whr: Cross Product Construction! δ 1 2 q i, q j, σ = δ 1 q i, σ, δ 2 q j, σ, F 1 2 = {(q i, q j ) q i F 1 q j F 2 }
Thorm: Sutrction Prsrvrs Rgulrity. Proof: L 1 L 2 = L 1 L 2 To sutrct rgulr lngug L 2 from L 1 : (FSA M 1 = Q 1, Σ, δ 1, q 1, F 1, M 2 = Q 2, Σ, δ 2, q 2, F 2 rspctivly) M 1 2 = Q 1 Q 2, Σ, δ 1 2, q 1, q 2, F 1 2 Whr: Cross Product Construction! δ 1 2 q i, q j, σ = δ 1 q i, σ, δ 2 q j, σ, F 1 2 = {(q i, q j ) q i F 1 q j F 2 }
Prolm:?
Finit Automt Non-dtrminism: gnrlizs dtrminism, whr mny nxt movs r llowd t ch stp: Old Nw d:q S Q d:2 Q S 2 Q Computtion coms tr. Accptnc: $ pth from root (strt stt) to som lf ( finl stt) Ex: non-dtrministiclly ccpt ll strings whr th 7 th symol for th nd is :,,,,,, q 0 q 1 q 2 q 3 q 4 q 5 q 6 q 7, Input: Accpt!
Finit Automt Thorm: Non-dtrminism in FAs dosn t incrs powr. Proof: y simultion: Construct ll supr-stts, on pr ch stt sust. Nw supr-trnsition function jumps mong supr-stts, simulting old trnsition function Initil supr stt r thos contining old initil stt. Finl supr stts r thos contining old finl stts. Rsulting DFA ccpts th sm lngug s originl NFA, ut cn hv xponntilly mor stts.
Finit Automt Not: Powrst construction gnrlizs th cross-product construction. Mor gnrl constructions r possil. EC: Lt HALF(L)={v $ v,w S * ' v = w nd vw L} Show tht HALF prsrvs rgulrity. A two wy FA cn mov its hd ckwrds on th input: d:q S Q {lft,right} EC: Show tht two-wy FA r not mor powrful thn ordinry on-wy FA. -trnsitions: q i q j q i q j On supr-stt! Thorm: -trnsitions don t incrs FA rcognition powr. Proof: Simult -trnsitions FA without using -trnsitions. i.., considr -trnsitions to form of non-dtrminism.
Th movi Nxt (2007) Bsd on th scinc fiction story Th Goldn Mn y Philip Dick Prmis: mn with th supr powr of non-dtrminism! At ny givn momnt his rlity rnchs into multipl dirctions, nd h cn choos th rnch tht h prfrs! Trnsition function!
Top-10 Rsons to Study Non-dtrminism 1. Hlps us undrstnd th uiquitous concpt of prlllism / concurrncy; 2. Illumints th structur of prolms; 3. Cn hlp sv tim & ffort y solving intrctl prolms mor fficintly; 4. Enls vst, dp, nd gnrl studis of compltnss thoris; 5. Hlps xplin why vrifying proofs & solutions sms to sir thn constructing thm;
Why Study Non-dtrminism? 6. Gv ris to nw nd novl mthmticl pprochs, proofs, nd nlyss; 7. Roustly dcoupls / strcts complxity from undrlying computtionl modls; 8. Givs disciplind tchniqus for idntifying hrdst prolms / lngugs; 9. Forgd nw unifictions twn computr scinc, mth & logic; 10. Non-dtrminism is intrsting fun, nd cool!
Rgulr Exprssions Rgulr xprssions r dfind rcursivly s follows: Ø mpty st q 0 {} trivil lngug {x} " x S singlton lngug q 0 q 0 x q 1 Inductivly, if R nd S r rgulr xprssions, thn so r: (R+S) union M 1 RS conctntion M 2 M 2 M 1 Compositions! R * Kln closur Exmpls: (+) * (+) * (+) * (+) * Thorm: Any rgulr xprssion is ccptd y som FA. M
Rgulr Exprssions A FA for rgulr xprssions cn uilt y composition: Ex: ll strings ovr S={,} whr $ prcding n (+) * (+) * (+) * = (+) * (+) * Why? Rmov prvious strt/finl stts
FA Minimiztion Id: Equivlnt stts cn mrgd:,,,,,,
FA Minimiztion Thorm [Hopcroft 1971]: th numr N of stts in FA cn minimizd within tim O(N log N). Bsd on rlir work [Huffmn 1954] & [Moor 1956]. Conjctur: Minimizing th numr of stts in nondtrministic FA cn not don in polynomil tim. Thorm: Minimizing th numr of stts in pushdown utomton (or TM) is undcidl. Projct id: implmnt finit utomton minimiztion tool. Try to dsign it to run rsonly fficintly. Considr lso including: A rgulr-xprssion-to-fa trnsformr, A non-dtrministic-to-dtrministic FA convrtr.
FAs nd Rgulr Exprssions Thorm: Any FA ccpts lngug dnotd y som RE. Proof: Us gnrlizd finit utomt whr trnsition cn rgulr xprssion (not just symol), nd: Only 1 supr strt stt nd 1 (sprt) supr finl stt. Ech stt hs trnsitions to ll othr stts (including itslf), xcpt th supr strt stt, with no incoming trnsitions, nd th supr finl stt, which hs no outgoing trnsitions. M M Ø Ø Ø Ø Ø M Ø Ø Ø Ø Originl FA M Gnrlizd FA (GFA) M
FAs nd Rgulr Exprssions Now rduc th siz of th GFA y on stt t ch stp. A trnsformtion stp is s follows: q i P q j q i P q j q i P + RS * T q j R S q T RS * T Such trnsformtion stp is lwys possil, until th GFA hs only two stts, th supr-strt nd supr-finl stts: M P Ll of lst rmining trnsition is th rgulr xprssion corrsponding to th lngug of th originl FA! Corollry: FAs nd REs dnot th sm clss of lngugs.
R+S = S+R R(ST) = (RS)T Rgulr Exprssions Idntitis R(S+T) = RS+RT (R+S)T = RT+ST Ø * = * = R+Ø = Ø+R = R R = R = R (R * ) * = R * ( + R) * = R * (R * S * ) * = (R+S) * R+ R RØ R
Dcidl Finit Automt Prolms Df: A prolm is dcidl if $ n lgorithm which cn dtrmin (in finit tim) th corrct nswr for ny instnc. Givn finit utomt M 1 nd M 2 : Q 1 : Is L(M 1 ) = Ø? Hint: grph rchility Q 2 : Is L(M 2 ) infinit? Hint: cycl dtction Q 3 : Is L(M 1 ) = L(M 2 )? Hint: considr L 1 -L 2 nd L 2 -L 1 M M $? $? S * -{} Ø Ø
Giv FA nd rgulr xprssion for th following lngug ovr th Ssm Strt Alpht: L = {w w stisfis i for xcpt ftr c } This mns w wnt ny string whr n i dos not immditly succd n, unlss w s c, in which cs n my not succd n i. Accptd words: liv, firc, rcipt Rjctd words: siz, thir, scinc
L = {w w stisfis i for xcpt ftr c } Σ {c, } sf c c c i c ci i c fil ( Σ c, + Σ c, i, + c + Σ c, i + c + i Σ, c + ε ) + + c + + c + i + ε Σ