Automt nd Lnguges Prof. Mohmed Hmd Softwre Engineering L. The University of Aizu Jpn
Tody s Topics DFA to Regulr Expression GFNA DFAèGNFA GNFA è RE DFA è RE Exmples 2
DFA è RE NFA DFA -NFA REX GNFA 3
Definition GNFA A generlized nondeterministic finite utomton (GNFA) is grph whose edges re leled y regulr expressions, with unique strt stte with in-degree 0, nd unique finl stte with out-degree 0. A string u is sid to lel pth in GNFA, if it is n element of the lnguge generted y the regulr expression which is gotten y conctenting ll lels of edges trversed in the pth. The lnguge ccepted y GNFA consists of ll the ccepted strings of the GNFA. 4
GNFA Exmple 1 0110 0 q S q f 01* 0* 11 5
GNFA Exmple 2 000 0 (0110 1001)* c This is GNFA ecuse edges re leled y REX s, strt stte hs no in-edges, nd the unique finl stte hs no out-edges. Q: Is 000000100101100110 ccepted? 6
GNFA Exmple 2 000 0 (0110 1001)* c A: 000000100101100110 is ccepted. The pth given y c 000 000 100101100110 proves this fct. (The lst lel results from 100101100110 (0110 1001)* ) 7
GNFA Definition A Generlized nondeterministic finite utomton (GNFA) is defined y M=(Q, Σ, δ, q strt, q finl ) with Q finite set of sttes Σ the input lphet q strt the strt stte with 0 in-degree q finl the ccept stte with 0 out-degree δ:(q\{q finl }) (Q\{q strt }) R the trnsition function (R is the set of regulr expressions over Σ) 8
DFAèGNFA Theorem For every DFA M, there exist n equivlent GNFA M 9
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 } nd q j Q \{q strt } R 1 q rip R 2 q i R 3 = q i R 4 (R 1 R 2 *R 3 ) q j R 4 q j 10
Exmple GNFAèRE 0110 0 R q s q f 01* ε 0* 11 11
Ripping out GNFAèRE Ripping out is done s follows. If you wnt to rip the middle stte v out of: r 2 u r 1 v r 3 w r 4 then you ll need to recrete ll the lost possiilities from u to w. I.e., to the current REX lel r 4 of the edge (u,w) you should dd the conctention of the (u,v ) lel r 1 followed y the (v,v )-loop lel r 2 repeted ritrrily, followed y the (v,w ) lel r 3.. The new (u,w ) sustitute would therefore e: u r 4 r 1 (r 2 )*r 3 w 12
Theorem For every (NFA) DFA M, there exist n equivlent RE R, with L(M)=L(R) Proof ide: 1. Trnsform n NFA into n equivlent GNFA 2. Trnsform the GNFA into regulr expression y removing sttes nd releling the rrows with regulr expressions 13
Proof ide: NFA 1. NFAèGNFA Add unique nd distinct strt stte with 0 in-degree nd finl stte with 0 out-degree, then connect them to the NFA with 2. GNFAèRE While mchine hs more thn 2 sttes: Pick n internl stte, rip it out nd re-lel the rrows with regulr expressions to ccount for the missing stte For Exmple: 0 0 01*0 1 14
Exmple 1, q 0 q 1 q 2 q 3 15
Exmple 1, * q 0 q 2 q 3 16
Exmple 1 (*)( )* q 0 q 3 R(q 0,q 3 ) = (*)( )* 17
Exmple 2 q 1 q 2 q 3 18
Exmple 2 q 1 q 2 q 3 19
Exmple 2 q 1 q 2 q 3 20
Exmple 2 q 1 q 2 21
Exmple 2 q 1 q 2 22
Exmple 2 q 1 + q 2 23
Exmple 2 q 1 + q 2 24
Exmple 2 q 1 + 25
Exmple 2 + ( + )* q 1 + 26
Exmple 2 + ( + )* q 1 + ( + )* 27
Exmple 2 + ( + )* + ( + )* 28
Exmple 2 [ + ( + )*]* [ + ( + )*] 29
Exmple 3 Strt with: This is not GNFA ecuse finl stte, though unique, hs nonzero out-degree. First we need to convert this into GNFA. Strt stte hs zero in-degree, so is oky. 30
Exmple 3 Just dded n ccept stte y connecting vi from the old ccept stte. Since the lels re single letters, they re utomticlly regulr expressions so this is GNFA And we re redy to strt ripping out interior sttes. 31
Exmple 3 Now, let s rip out d. Q1: Wht will e the lel of (,c )? Q2: Wht will e the lel of (c,c )? 32
Exmple 3 A1: (,c ): CD*A A2: (c,c ): CD*A Next, rip out c. Q: Wht will e the lel of (, )? 33
Exmple 3 A: B (CD*A)(CD*A)*B which simplifies to B (CD*A) + B Next, rip out. 34
Exmple 3 Finlly, rip out : 35
Exmple 3 The resulting REX Is the unique lel (A D(B (CD*A) + B)) + 36
Exmple 4 Convert the following NFA into regulr expression? q 1, q 2 q 3 37
Exmple 4 Convert the following NFA into regulr expression? q 1, q 2 q 3 38
Exmple 4 Convert the following NFA into regulr expression? q 1, q 2 q 3 39
Exmple 4 Convert the following NFA into regulr expression? q 1, q 3 40
Exmple 4 Convert the following NFA into regulr expression? q 1 ( + )* q 3 41
Exmple 4 Convert the following NFA into regulr expression? q 1 ( + )* * q 3 42
Exmple 4 Convert the following NFA into regulr expression? q 1 ( + )* * 43
Exmple 4 Convert the following NFA into regulr expression? q 1 ( + )* ( + )*(*)* * 44
Exmple 4 Convert the following NFA into regulr expression? q 1 ( + )*(*)* ( + )*(*)* 45
Exmple 4 Convert the following NFA into regulr expression? ( + )*(*)* ( + )*(*)* 46
Exmple 4 Convert the following NFA into regulr expression? [( + )*(*)*]* ( + )*(*)* 47
Algorithm Next we study the Algorithm 48
Algorithm Add q strt nd q finl to crete G Run CONVERT(G): If #sttes = 2 return the expression on the rrow going from q strt to q finl If #sttes > 2 select q rip Q different from q strt nd q finl define Qʹ = Q {q rip } define 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ʹ) 49
Algorithm CONVERT(G) is equivlent to G Proof y induction on k (numer of sttes in G) Bse Cse: ü k = 2 Inductive Step: Assume clim is true for k-1 sttes We first note tht G nd Gʹ re equivlent But, y the induction hypothesis, Gʹ is equivlent to CONVERT(Gʹ) 50
Exercise q 1 q 2 q 3 51