CSCI 340: Computtionl Models Kleene s Theorem Chpter 7 Deprtment of Computer Science
Unifiction In 1954, Kleene presented (nd proved) theorem which (in our version) sttes tht if lnguge cn e defined y ny one of the three wys, then it cn e defined y the other two. All three of these methods of defining lnguges re equivlent. Theorem Any lnguge tht cn e defined y: regulr expression, or finite utomton, or trnsition grph cn e defined y ll three methods. 1 / 26
How do we prove this theorem? This theorem is the most importnt nd fundmentl result in the theory of finite utomt We need to crefully prove tht it is correct We will do so y introducing four lgorithms tht enle us to construct the corresponding mchines nd expressions The generl logic of this proof is s follows: 1 Show tht the set of ll FAs cn e defined y set of TGs 2 Show tht the set of ll TGs cn e defined y set of REs 3 Show tht the set of ll REs cn e defined y set of FAs Mthemticlly: [FA TG RE FA] [FA = TG = RE] 2 / 26
Forml Proof of Kleene s Theorem Proof. The three sections of our proof will e: 1 Every lnguge tht cn e defined y finite utomton cn lso e defined y trnsition grph 2 Every lnguge tht cn e defined y trnsition grph cn lso e defined y regulr expression 3 Every lnguge tht cn e defined y regulr expression cn lso e defined y finite utomton When we hve proven these three prts, we hve finished our theorem Proof of Prt 1: FA TG. Every finite utomton is itself lredy trnsition grph. Therefore, ny lnguge tht hs een defined y finite utomton hs lredy een defined y trnsition grph. 3 / 26
Proof of Prt 2: TG RE We will prove prt 2 y constructive lgorithm Present procedure tht tkes TG nd yields n RE which defines the sme lnguge It must work for every conceivle TG It must gurntee to finish its jo in finite time It does not hve to e good lgorithm it just hs to work How We Wish It Could Work Look t the mchine, figure out its lnguge, nd write down n equivlent regulr expression people re not s relily cretive s they re relile drones we don t wnt to wit for DVinci to e in the suitle mood ll cleverness should e incorported into the lgorithm 4 / 26
Proof of Prt 2: TG RE Algorithm 1 Crete unique, un-enterle finl stte nd unique, un-levele initil stte 2 One-y-one, in ny order, ypss nd eliminte ll the non-initil or finl sttes in the TG. A stte is ypssed y connecting ech incoming edge with ech outgoing edge. The lel of ech resultnt edge is the conctention of the lel on the incoming edge with the lel on the loop edge (if there is one) nd the lel on the outgoing edge 3 When two sttes re joined y more thn one edge going in the sme direction, unify them y dding their lels 4 Finlly, when ll tht remins is one edge from initil to finl, the lel on tht edge is regulr expression tht genertes the sme lnguge s wht ws recognized y the originl mchine 5 / 26
Exmple for Prt 2: TG RE q 2 q λ 0 q 1 q 4 q 3 λ Eliminting sttes in the order: q 1, q 2, q 3 6 / 26
Exmple for Prt 2: TG RE q 2 q 0 q 4 q 3 λ After eliminting q 1 6 / 26
Exmple for Prt 2: TG RE q 0 q 3 q 4 + λ + + After eliminting q 2 6 / 26
Exmple for Prt 2: TG RE + [ + ][ + ] [λ + ] q 0 q 4 After eliminting q 3 Yielding: + [ + ][ + ] [λ + ] 6 / 26
Exmple for Prt 2: TG RE q 2 q λ 0 q 1 q 4 q 3 λ Eliminting sttes in the order: q 3, q 2, q 1 7 / 26
Exmple for Prt 2: TG RE + q λ 0 q + 1 q + 2 q 4 After eliminting q 3 7 / 26
Exmple for Prt 2: TG RE q λ [ + ][ + ] [ + ] 0 q 1 q 4 After eliminting q 2 7 / 26
Exmple for Prt 2: TG RE + [ + ][ + ] [ + ] q 0 q 4 After eliminting q 1 Yielding: + [ + ][ + ] [ + ] 7 / 26
Proof of Prt 3: RE FA Proof. 1 There is n FA tht ccepts ny prticulr letter of the lphet. There is n FA tht ccepts only the word λ. 2 If there is n FA clled FA 1 tht ccepts the lnguge defined y the regulr expression r 1, nd there is n FA clled FA 2 tht ccepts the lnguge defined y the regulr expression r 2, then there is n FA (clled FA 3 ) tht ccepts the lnguge defined y (r 1 + r 2 ), the sum lnguge. 3 If there is n FA 1 tht ccepts the lnguge defined y regulr expression r 1 nd n FA 2 tht ccepts the lnguge defined y regulr expression r 2, then there is n FA 3 tht ccepts the lnguge defined y the conctention r 1 r 2, the product lnguge. 4 If r is regulr expression nd FA 1 ccepts lnguge (r), then there exists FA 2 where it ccepts the lnguge (r ) [Kleene Str]. 8 / 26
Proof of Prt 3 Rule 1 Rule 1 There is n FA tht ccepts ny prticulr letter of the lphet. There is n FA tht ccepts only the word λ. x e Σ q 0 q 1 e Σ e x q 2 e Σ q ll Σ 0 q 1 ll Σ 9 / 26
Proof of Prt 3 Rule 2 Rule 2 If FA 1 ccepts lnguge(r 1 ) nd FA 2 ccepts lnguge(r 2 ) then n FA 3 exists nd ccepts lnguge(r 1 + r 2 ) The generl description is s follows: FA 1 hs sttes x 1, x 2, x 3,... FA 2 hs sttes y 1, y 2, y 3,... We will construct FA 3 with sttes z 1, z 2, z 3,... ech z k is of the form x i or y j x strt or y strt is the strt stte of FA 3 z k (= x i or y j ) is finl stte IFF x i is finl or y j is finl 10 / 26
Exmple for Prt 3 Rule 2 FA 1 x 1 x 2 x 3, FA 2 y 1 y 2 Reminder of Exercise on Chlkord (show (L 1 + L 2 )) 11 / 26
Proof of Prt 3 Rule 3 Rule 3 If FA 1 ccepts lnguge(r 1 ) nd FA 2 ccepts lnguge(r 2 ), then n FA 3 exists nd ccepts lnguge(r 1 r 2 ) Mke z-stte for every non-finl x-stte in FA 1, reched efore ever hitting finl stte on FA 1 For ech finl stte in FA 1, we estlish z-stte tht expresses either (1) we re continuing on FA 1 or eginning on FA 2. Initil sttes re the initil sttes from FA 1 Finl sttes re the z-sttes tht represent the disjunction of ny finl stte from FA 2 12 / 26
Exmple of Prt 3 Rule 3 FA 1 x 1 x 2 x 3, FA 2, y 1 y 2, Reminder of Exercise on Chlkord (show L 1 L 2 ) 13 / 26
Proof of Prt 3 Rule 4 Rule 4 If r is regulr expression nd FA 1 ccepts lnguge (r), then there exists FA 2 where it ccepts lnguge (r ) (.k.. the Kleene Str) Crete stte for every suset of x s. Cncel ny suset tht contins finl x-stte, ut does not contin the strt stte. For ll remining non-empty sttes, drw n -edge nd -edge to the collection of x-sttes rechle in the originl FA from the component x s y - nd -edges, respectively. Cll the null suset initil-nd-finl stte nd connect it to whtever sttes the originl strt stte is connect to y - nd -edges (even the strt stte) Finlly, mrk sttes s finl if the contin n x-component tht is finl stte of the originl FA 14 / 26
Exmple of Prt 3 Rule 4 FA 1 y 1 y 2 Reminder of Exercise on Chlkord (show L 1 ) 15 / 26
Prt 3 Recp 1 There is n FA tht ccepts ny letter or λ 2 If FA 1 ccepts r 1 nd FA 2 ccepts r 2, then there exists FA 3 ccepting r 1 r 2 3 If FA 1 ccepts r 1 nd FA 2 ccepts r 2, then there exists FA 3 ccepting r 1 + r 2 4 If FA 1 ccepts r 1 then there exists FA 2 ccepting r 1 We cn construct ny regulr expression through repplictions of the following four rules ove. Therefore, ny RE cn e converted into n FA. 16 / 26
Nondeterministic Finite Automt Finite Automt introduced up to this point hve ll een deterministic Trnsition Grphs re non-deterministic y defult ut cn lso e much more complicted. Mye there exists hppy medium etween the two? 17 / 26
Nondeterministic Finite Automt Finite Automt introduced up to this point hve ll een deterministic Trnsition Grphs re non-deterministic y defult ut cn lso e much more complicted. Mye there exists hppy medium etween the two? NFA is type of Trnsition Grph which hs unique strt stte where ech edge hs single lphet letter nd where mny - nd -edges could come out of ech stte Invented y Rin nd Scott in 1959 17 / 26
Exmples of NFAs,, x 1 y 0 y 1 y 1 x 0 x 2, x 3 x 4 z 0 z 1, z 3 z 2 18 / 26
Eliminte ll Loop Sttes r 1 r 2 α β γ χ s ω ψ t 1 t 2 r 3 t 3 Mye it would e cool if we could remove ll loops? 19 / 26
Eliminte ll Loop Sttes r 1 t 1 r 2 α β s χ ψ t 2 r 3 γ s ω t 3 duplicte the stte 19 / 26
Eliminte ll Loop Sttes r 1 t 1 α s χ r 2 β ψ t 2 r 3 γ s ω t 3 remove loop nd dd trnsitions 19 / 26
Eliminte ll Loop Sttes r 1 χ t 1 α s χ ψ r 2 β ψ t 2 r 3 γ s ω ω t 3 copy ll outgoing trnsitions to new stte 19 / 26
Exmple All strings with triple followed y triple. Should we ccept? 20 / 26
Theorems nd Proofs of NFAs Theorem For every NFA, there is some FA (DFA) tht ccepts exctly the sme lnguge Proof. 1 Using Prt 2 from efore, convert the NFA into n RE 2 Using the four rules from Prt 3 from efore, construct n FA tht ccepts the RE generted in (1) 3 Becuse we proved ech prt of the proof prior, we re done 21 / 26
Theorems nd Proofs of NFAs Theorem For every NFA, there is some FA (DFA) tht ccepts exctly the sme lnguge Proof. 1 Using Prt 2 from efore, convert the NFA into n RE 2 Using the four rules from Prt 3 from efore, construct n FA tht ccepts the RE generted in (1) 3 Becuse we proved ech prt of the proof prior, we re done Wit... isn t tht crzy complicted nd orderline cheting? 21 / 26
NFA to DFA Algorithm The Big Picture: Rememer Rule 4 from Prt 3 which tells us to represent new sttes s choice of x-sttes All sttes in the (D)FA we will produce will lso e the collections of sttes from the originl NFA. Every time we encounter trnsition, we must follow tht trnsition for ech stte in where we were Every time we try to tke n - or -trnsition which does not collectively exist cross ll NFA sttes in our current collection, we go to common hell stte of which there is never ny escpe 22 / 26
NFA to DFA Trp Stte q 1 q 0 q 3 q 2 At q0 we hve exctly one -trnsition nd one -trnsition. Next! 23 / 26
NFA to DFA Trp Stte q 1 q 0, q 3 q 2 At q1 we hve one -trnsition BUT no -trnsition. We must (1) crete trp stte nd (2) mke n -trnsition to it 23 / 26
NFA to DFA Trp Stte q 1 q 0, q 3 q 2 23 / 26
NFA to DFA Trp Stte q 1 q 0, q 3 q 2 At q2 we hve one -trnsition BUT no -trnsition. We must mke n -trnsition from q2 to the trp stte 23 / 26
NFA to DFA Trp Stte q 1 q 0,, q 3 q 2 At q3 we hve no trnsitions, so we must crete trnsition for nd to the trp stte 23 / 26
Adding NFAs to Kleene s Theorem Proof. 1 The following NFAs cn ccept {}, {} nd {λ} respectively 2 Becuse of our theorem For every NFA there is some FA tht ccepts exctly the sme lnguge, there is n equivlent TG nd RE for given NFA 24 / 26
Simplifying the cretion of FA 1 + FA 2 Algorithm 1 Introduce new nd unique stte stte with two outgoing -edges nd two outgoing -edges 2 Connect ech of the edges to the sttes tht follow the strt of oth FA 1 nd FA 2. 3 Remove the strt mrkers for the sttes which hd originlly strted FA 1 nd FA 2 4 Using the lgorithm provided erlier, convert the NFA into n FA 25 / 26
Exmple, y 1 x 0 x 1 y 0 y 2 y 3 26 / 26
Exmple, y 1 x 0 x 1 y 0 y 2 y 3 Introduce new nd unique strt stte 26 / 26
Exmple, y 1 x 0 x 1 y 0 y 2 y 3 Add outgoing -trnsitions to the follow sttes of ech FA 26 / 26
Exmple, y 1 x 0 x 1 y 0 y 3 y 2 Add outgoing -trnsitions to the follow sttes of ech FA 26 / 26
Exmple, y 1 x 0 x 1 y 0 y 3 y 2 Remove the two strt s which hd originlly strted the two FAs 26 / 26