DFA RE NFA DFA -NFA REX GNFA Definition GNFA A generlize noneterministic finite utomton (GNFA) is grph whose eges re lele y regulr expressions, with unique strt stte with in-egree, n unique finl stte with out-egree. A string u is si to lel pth in GNFA, if it is n element of the lnguge generte y the regulr expression which is gotten y conctenting ll lels of eges trverse in the pth. The lnguge ccepte y GNFA consists of ll the ccepte strings of the GNFA. GNFA GNFA 2 ( )* q S q f c * * This is GNFA ecuse eges re lele y REX s, strt stte hs no in-eges, n the unique finl stte hs no out-eges. Q: Is ccepte 2 GNFA A: is ccepte. The pth given y c λ proves this fct. (The lst lel results from ( )* ) ( )* c Definition GNFA A Generlize noneterministic finite utomton (GNFA) is efine y M=(Q, S,, q strt, q finl ) with Q finite set of sttes S the input lphet q strt the strt stte with in-egree q finl the ccept stte with out-egree :(Q\{q finl }) (Q\{q strt }) Ρ the trnsition function (Ρ is the set of regulr expressions over S)
Theorem DFA GNFA For every DFA M, there exist n equivlent GNFA M DFA GNFA Remove Internl stte of GNFA If the GNFA M hs more thn 2 sttes, rip internl q rip to get equivlent GNFA M y: - Removing stte q rip : Q =Q\{q rip } - Chnging the trnsition function y (q i,q j ) = (q i,q j ) ((q i,q rip )((q rip,q rip ))*(q rip,q j )) for every q i Q \{q finlt } n q j Q \{q strt } R q rip R 2 q i R 3 = q i R 4 (R R 2 *R 3 ) q j R 4 q j GNFA RE R Ripping out GNFA RE Ripping out is one s follows. If you wnt to rip the mile stte v out of: u r r 2 v r 3 w q s * * e q f then you ll nee to recrete ll the lost possiilities from u to w. I.e., to the current REX lel r 4 of the ege (u,w) you shoul the conctention of the (u,v ) lel r followe y the (v,v )-loop lel r 2 repete ritrrily, followe y the (v,w ) lel r 3.. The new (u,w ) sustitute woul therefore e: r 4 u r 4 r (r 2 )*r 3 w Theorem For every (NFA) DFA M, there exist n equivlent RE R, with L(M)=L(R) Proof ie:. Trnsform n NFA into n equivlent GNFA 2. Trnsform the GNFA into regulr expression y removing sttes n releling the rrows with regulr expressions Proof ie:. NFA GNFA NFA A unique n istinct strt stte with in-egree n finl stte with out-egree, then connect them to the NFA with 2. GNFA RE While mchine hs more thn 2 sttes: Pick n internl stte, rip it out n re-lel the rrowswith regulr expressions to ccount for the missing stte For : * 2 2
2, *(*)( )* q q q R(q, ) = (*)( )* 3 4 2 2 ( )* = R(q,q ) q q ( )* 5 6 GNFA RE GNFA RE Strt with: This is not GNFA ecuse finl stte, though unique, hs nonzero out-egree. First we nee to convert this into GNFA. Strt stte hs zero in-egree, so is oky. 7 Just e n ccept stte y connecting vi from the ol ccept stte. Since the lels re single letters, they re utomticlly regulr expressions so this is GNFA An we re rey to strt ripping out interior sttes. 8 3
3 3 Now, let s rip out. A: (,c ): CD*A A2: (c,c ): CD*A Q: Wht will e the lel of (,c ) Next, rip out c. Q2: Wht will e the lel of (c,c ) Q: Wht will e the lel of (, ) 9 2 3 3 A: B (CD*A)(CD*A)*B which simplifies to B (CD*A) + B Next, rip out. Finlly, rip out : 2 22 3 Exercise Convert the following NFA into regulr expression The resulting REX Is the unique lel (A D(B (CD*A) + B)) + q, ( )*(*)* ( )* ( )*(*)* * 23 24 4
Answer (( )*(*)*)* (( )*(*)*)*( )*(*)* Algorithm Next we stuy the Algorithm 25 26 Algorithm: A q strt n q finl to crete G Run CONVERT(G): If #sttes = 2 If #sttes return the > 2 expression on the rrow going from q strt to q finl Algorithm: Run CONVERT(G): A q strt n q finl to crete G If #sttes > 2 select q rip Q ifferent from q strt n q finl efine Q = Q {q rip } efine R s: R (q i,q j ) = R(q i,q rip )R(q rip,q rip )*R(q rip,q j ) R(q i,q j ) return CONVERT(G ) 27 28 Algorithm: CONVERT(G) is equivlent to G Proof y inuction on k (numer of sttes in G) Bse Cse: k = 2 Inuctive Step: Assume clim is true for k- sttes We first note tht G n G re equivlent But, y the inuction hypothesis, G is equivlent to CONVERT(G ) 29 3 5
Strings over {,} with even numer of s Σ* Strings over {,} with even numer of s Σ* E O E O E O E O [E,E] [O,E] [E,O] [O,O] [E] [O] 3 32 Oservtion The sttes mong the stte sets {[E,E], [E,O]} n {[O,E], [O,O]} iffer on spect immteril for the prolem t hn. Why not collpse these stte sets into one stte ech, to get smller DFA Definition Equivlent or Inistinguishle Sttes Recll tht DFA stte summrizes the sustring consume so fr (tht is, the pst history). Two sttes q i n q j re equivlent or (inistinguishle), if, when strte in these sttes, every string cuses the mchine to either en up in finl stte for oth or en up in non-ccepting stte for oth. Two sttes q i n q k re equivlent (or inistinguishle), if for ll strings w S* (q i, w) F (q k, w) F Two sttes q i n q k re istinguishle, if for some string w S* (q i, w) F (q k, w) ˇ F 33 34 Min Ie q i q j q m q n q q4 DFA q q2,, q5 q7 q3 If q m n q n re istinguishle, then so re q i n q j ( u )( u *) q6, 35 36 6
Refinement of Stte Prtitions { {q,q7}, {q,q2,q3,q4,q5,q6} } { {q},{q7}, {q,q2,q3,q4,q5,q6} } On ny trnsition { {q},{q7}, {q,q2,q3,q4,q5,q6} } { {q},{q7}, {q,q4}, {q2,q3,q5,q6} } On trnsition { {q},{q7}, {q,q4}, {q2,q5},{q3,q6} } On trnsition Showing equivlent sttes in DFA q q q2,, q4 q5 q7 q6 ( u )( u *), q3 37 38 Minimum DFA q,, q,q4 q2,q5 q7 Equivlent Sttes Consier the ccept sttes c n g. They re oth sinks mening tht ny string which ever reches them is gurntee to e ccepte lter. Q: Do we nee oth sttes,, c ( u )( u *) q3,q6, 39 f e, g 4 A: No, they cn e unifie s illustrte elow. Q: Cn ny other sttes e unifie ecuse ny susequent string suffixes prouce ienticl results Joining Equivlent Sttes e,, cg A: Yes, n f. Notice tht if you re in or f then:. if string ens, reject in oth cses 2. if next chrcter is, forever ccept in oth cses 3. if next chrcter is, forever reject in oth cses So unify with f. Equivlent Sttes e,, cg f 4 f 42 7
Intuitively two sttes re equivlent if ll susequent ehvior from those sttes is the sme. Q: Come up with forml chrcteriztion of stte equivlence. Joining Equivlent Sttes e,, cg Finishing the Q: Any other wys to simplify the utomton e,, cg, f 43, f 44 Useless Sttes A: Get ri of. Getting ri of unrechle useless sttes oesn t ffect the ccepte lnguge. Definition An utomton is irreucile if it contins no useless sttes, n no two istinct sttes re equivlent. e,, cg Gols of the Minimiztion Algorithm The gol of minimiztion lgorithm is to crete irreucile utomt from ritrry ones., f 45 The lgorithm ctully prouces smllest possile DFA for the given lnguge, hence the nme minimiztion. 46 Minimiztion Algorithm First Prt: Prtition DFA minimize(dfa (Q, Σ, δ, q, F ) ) remove ny stte q unrechle from q Prtition P = {F, Q - F } oolen Consistent = flse while( Consistent == flse ) Consistent = true for(every Set S P, symol Σ, Set T P ) Set temp = {q T δ(q,) S } if (temp!= Ø && temp!= T ) Consistent = flse P = (P T ) {temp,t temp} return efineminimizor( (Q, Σ, δ, q, F ), P ) 47 Minimiztion Algorithm DFA efineminimizor (DFA (Q, Σ, δ, q, F ), Prtition P ) Set Q =P Stte q = the set in P which contins q F = { S P S F } for (ech S P, Σ) efine δ (S,) = the set T P which contins the sttes δ (S,) return (Q, Σ, δ, q, F ) Secon Prt: Minimiztion 48 8
Minimiztion Minimiztion Miniture version à Strt with DFA 49 5 Minimiztion Minimiztion Split into two prts. ACCEPT vs. REJECT -lel oesn t split 5 52 Minimiztion -lel splits up REJECT's Minimiztion No further splits. HALT! 53 54 9
En Result Sttes of the miniml utomt re remining. Minimiztion. Compre 55 56 Minimiztion. Compre Minimiztion. Compre 57 58 Minimiztion. Compre Minimiztion. Compre 59 6
Minimiztion. Compre Minimiztion. Compre 6 62 Minimiztion. Compre Minimiztion. Compre 63 64 Minimiztion. Compre Minimiztion. Compre ACCEPTED. 65 66
Minimiztion. Compre Minimiztion. Compre 67 68 Minimiztion. Compre Minimiztion. Compre 69 7 Minimiztion. Compre Miniml Automton Previous lgorithm gurntee to prouce n irreucile FA. Why shoul tht FA e the smllest possile FA for its ccepte lnguge REJECT. 7 72 2
Theorem Proof Miniml Automton (Myhill-Neroe): The minimiztion lgorithm prouces the smllest possile utomton for its ccepte lnguge. Show tht ny irreucile utomton is the smllest for its ccepte lnguge L: We sy tht two strings u,v Σ* re inistinguishle if for ll suffixes x, ux is in L exctly when vx is. Notice tht if u n v re istinguishle, the pth from their pths from the strt stte must hve ifferent enpoints. 73 Proof (cont.) Consequently, the numer of sttes in ny DFA for L must e s gret s the numer of mutully istinguishle strings for L. But n irreucile DFA hs the property tht every stte gives rise to nother mutully istinguishle string! Therefore, ny other DFA must hve t lest s mny sttes s the irreucile DFA 74 Quiz IS ITS THIS MINIMAL DFA MINIMAL DFA NO IS Quiz IS THIS DFA MINIMAL q, q 75 76 Definition For DFA M = (Q, S,, q, F), let p, q, r Q Definition: p ~ q iff p is inistinguishle (equivlent) from q p ~ / q iff p is istinguishle from q Proposition: ~ is n equivlence reltion p ~ p (reflexive) p ~ q p ~ q n q ~ r q ~ p (symmetric) p ~ r (trnsitive) Definition: so p ~ ~ prtitions q iff p is the inistinguishle set of sttes of from M into q isjoint equivlence clsses p ~ / q iff p is istinguishle from q [q] = { p p ~ q } Proposition: ~ is n equivlence reltion p ~ p (reflexive) Q q p ~ q q ~ p (symmetric) q Definition For DFA M = (Q, S,, q, F), let p, q, r Q p ~ q n q ~ r p ~ r (trnsitive) 77 78 3
Algorithm Algorithm MINIMIZE Input: DFA M Output: DFA M MIN such tht: M M MIN M MIN hs no inccessile sttes M MIN is irreucile sttes of M MIN re pirwise istinguishle Theorem: M MIN is the unique minimum 79 Ie: Sttes of M MIN will e locks of equivlent sttes of M 8 Algorithm TABLE-FILLING ALGORITHM Input: DFA M = (Q, S,, q, F) Output: () D M = { (p,q) p,q Q n p ~ / q } (2) E M = { [q] q Q } q q q q Bse Cse: p ccepts n q rejects p ~ / q q i Recursion: p p q n ~/ q q q q q i q n p ~ / q 8 q q, q q 82 q q q q Algorithm Algorithm MINIMIZE Input: DFA M Output: DFA M MIN () Remove ll inccessile sttes from M (2) Apply Tle-Filling lgorithm to get E M = { [q] q is n ccessile stte of M } M MIN = (Q MIN, S, MIN, q MIN, F MIN ) Q MIN = E M, q MIN = [q ], F MIN = { [q] q F } q q 83 MIN ( [q],s ) = [ ( q,s ) ] 84 4
MINIMIZE q q Exercise Minimize the following DFA q q, q 4, q 5 85 86 q q q 4, q q, q 5 q 4 q 5 q q q 4 q 5 87 5