Forml Lnguge nd Automt Forml Lnguge nd Automt Theory (CS21004) Khrgpur Khrgpur Khrgpur Forml Lnguge nd Automt
Tle of Contents Forml Lnguge nd Automt Khrgpur 1 2 3 Khrgpur Forml Lnguge nd Automt
Forml Lnguge nd Automt Khrgpur The slide is just short summry Follow the discussion nd the ordwork Solve prolems (prt from those we dish out in clss) Khrgpur Forml Lnguge nd Automt
Tle of Contents Forml Lnguge nd Automt Khrgpur 1 2 3 Khrgpur Forml Lnguge nd Automt
A finite utomt is mthemticl model of system with discrete inputs nd outputs system cn hve finite no. of internl configs / sttes Simple Ex : Elevtor controller : does not rememer requests tht re lredy serviced. Rememers 1) current floor, 2) current direction of motion, 3) set of requests to e serviced Complex Ex: digitl computer infinite memory version is the Turing mchine Dy to dy use y you : think of text editor progrm (modes of opertion : sve file, open file, updte user input with file in memory) Forml Lnguge nd Automt Khrgpur Khrgpur Forml Lnguge nd Automt
Forml Lnguge nd Automt Khrgpur M = Q,Σ,δ,q,F Q : finite set of internl sttes Σ : finite set of input lphet δ : Q Σ Q : is the trnsition function q Q : initil stte F Q is the set of finl/ccept sttes Khrgpur Forml Lnguge nd Automt
FA exmple Forml Lnguge nd Automt Khrgpur, 1 2 3 4 Figure: A smple FA Σ = {,}, Q = {1,2,3,4}, q = 1 δ(1,) = 2,δ(1,) = 1,δ(2,) = 3, i/p is processed left to right Khrgpur Forml Lnguge nd Automt
Acceptnce y FA Given δ : Q Σ Q, define ˆδ : Q Σ Q inductively s follows ˆδ(q,λ) = q For x Σ, Σ, ˆδ(q,x) = δ(ˆδ(q,x),) ˆδ is nothing ut the multistep version of δ Forml Lnguge nd Automt Khrgpur A string σ is ccepted y M = Q,Σ,δ,q 0,F, if ˆδ(q,σ) F L(M) = {σ Σ ˆδ(q,σ) F} A lnguge A is regulr iff it is ccepted y some FA Regulr sets re closed under,,,, Khrgpur Forml Lnguge nd Automt
Product Mchines Given M 1 = Q 1,Σ,δ 1,q 1,F 1, M 2 = Q 2,Σ,δ 2,q 2,F 2 let M 3 = Q 3,Σ,δ 3,q 3,F 3 e defined s follows. Q 3 = Q 1 Q 2, δ 3 : Q 3 Σ Q 3 where δ 3 ((p,q),) = (δ 1 (p,),δ 2 (q,)). F 3 = F 1 F 2 q 3 = (q 1,q 2 ) L(M 3 ) = L(M 1 ) L(M 2 ) : Prove tht σ Σ, (p,q) Q 3, ˆδ 3 ((p,q),σ) = (ˆδ 1 (p,σ),ˆδ 2 (q,σ)) y induction on length of input string σ Σ. Use ˆδ 3 to define L(M 3 ) s desired. With F 3 = (F 1 Q 2 ) (Q 1 F 2 ), we hve n utomt for Forml Lnguge nd Automt Khrgpur Khrgpur Forml Lnguge nd Automt
Product Exmple Forml Lnguge nd Automt s0 t0 Khrgpur s1 t2 t1 s0t0 s1t0 s0t2 s0t1 s1t2 s1t1 Figure: M 1 : even no. of, M 2 : no of is 3n. Techniclly they re sensitive to different lphets, self loops highlight tht Khrgpur Forml Lnguge nd Automt
DFA for L = {w w {,} } Forml Lnguge nd Automt q 0 q 2 q 3 Khrgpur q 1 ; Khrgpur Forml Lnguge nd Automt
DFA for L 2 With L = {w w {,} }, L 2 = {w 1 w 2 w 1,w 2 {,} } Forml Lnguge nd Automt Khrgpur q 1 q 0 ; q 2 q 3 q 5 q 4 L n = {(w i ) n w 1,,w n {,} } Khrgpur Forml Lnguge nd Automt
DFA for L Forml Lnguge nd Automt Khrgpur q 0 q 2 q 3 q 1 ; q 4 Khrgpur Forml Lnguge nd Automt
Smller DFA for L Forml Lnguge nd Automt q 0 q 2 q 3 Khrgpur q 1 ; Why? Note L n L n 1 L 3 L 2 L. So, L = L 0 L 1 L 2 = L 0 L = {ǫ} L. Just mke initil stte s ccept stte in mchine for L Khrgpur Forml Lnguge nd Automt
Tle of Contents Forml Lnguge nd Automt Khrgpur 1 2 3 Khrgpur Forml Lnguge nd Automt
NFA Forml Lnguge nd Automt Khrgpur DFA is deterministic y construction since δ is function, (for ll situtions/sttes, how the mchine will exctly rect is uniquely specified) My e cumersome to specify for complex systems My even e unknown NFA provides nice wy of strction of informtion - concept pplied in so mny spects of computing Khrgpur Forml Lnguge nd Automt
NFA Consider L = {x {0,1} 2nd symol from the right is 1} 0, 1 1 0, 1 s 1 s 2 f Figure: NFA for L Forml Lnguge nd Automt Khrgpur the movement from s 1 when input is 1 is nondeterministic For n input string, NFA will crete computtion tree rther thn computtion sequence in cse of DFA An NFA ccepts string if ny one of the pths in the tree leds to some ccept stte Khrgpur Forml Lnguge nd Automt
Computtion tree for σ = 11010 s 1 1 1 Forml Lnguge nd Automt Khrgpur s 2 1 s 1 s 2 s 1 1 1 f 0 0 0? f s 1 1 1? s 2 0 f Khrgpur Forml Lnguge nd Automt
NFA to DFA Compute ll possile susets : {{},{s 1 },{s 2 },{f},{s 1,s 2 },{s 2,f},{s 1,f},{s 1,s 2,f}} compute single step rechility mong susets for i/p-s 0,1 with sme initil stte δ 0 1 {} {} {} {s 1 } {s 1 } {s 1,s 2 } {s 2 } {f} {f} {f} {} {} {s 1,s 2 } {s 1,f} {s 1,s 2,f} {s 1,f} {s 1 } {s 1,s 2 } {s 2,f} {f} {f} {s 1,s 2,f} {s 1,f} {s 1,s 2,f} Forml Lnguge nd Automt Khrgpur Sttes {s 2,f}, {s 2 }, {f}, {}, re unrechle Khrgpur Forml Lnguge nd Automt
NFA to DFA Reduced trnsition tle with unrechle sttes removed δ 0 1 {s 1 } {s 1 } {s 1,s 2 } {s 1,s 2 } {s 1,f} {s 1,s 2,f} {s 1,f} {s 1 } {s 1,s 2 } {s 1,s 2,f} {s 1,f} {s 1,s 2,f} Forml Lnguge nd Automt Khrgpur DFA should hve 4 sttes : { 1, 2, 3, 4 } = {{s 1 },{s 1,s 2 },{s 1,f},{s 1,s 2,f}} Initil stte is sme. Khrgpur Forml Lnguge nd Automt
NFA to DFA δ 0 1 {s 1 } {s 1 } {s 1,s 2 } {s 1,s 2 } {s 1,f} {s 1,s 2,f} {s 1,f} {s 1 } {s 1,s 2 } {s 1,s 2,f} {s 1,f} {s 1,s 2,f} Forml Lnguge nd Automt Khrgpur δ 0 1 1 1 2 2 3 4 3 1 2 4 3 4 Khrgpur Forml Lnguge nd Automt
NFA to DFA Forml Lnguge nd Automt δ 0 1 1 1 2 2 3 4 3 1 2 4 3 4 Khrgpur 0 1 2 1 1 1 0 1 4 0 0 3 Khrgpur Forml Lnguge nd Automt
NFA forml definition (Q,Σ,,S,F) Q : set of sttes Σ : Alphet : trnsition reltion (function) defined s Forml Lnguge nd Automt Khrgpur : Q 2 Q 2 Q = {A A Q} : cptures multiple possile rections to n input S Q : set of initil sttes Khrgpur Forml Lnguge nd Automt