Finite Automt (FA or DFA) CHAPTE 1 egulr Lnguges Contents definitions, exmples, designing, regulr opertions Non-deterministic Finite Automt (NFA) definitions, euivlence of NFAs nd DFAs, closure under regulr opertions egulr expressions definitions, euivlence with finite utomt Non-regulr Lnguges the pumping lemm for regulr lnguges Theory of Computtion, Feodor F. Drgn, Kent Stte University 1
egulr expressions: definition An lgeric euivlent to finite utomt. We cn uild complex lnguges from simple lnguges using opertions on lnguges. Let Σ = { 1,..., n } e n lphet. The simple lnguges over Σ re the empty lnguge, which contins no word. for every symol Σ, the lnguge {}, which contins only the oneletter word. The regulr opertions on lnguges re U (union), o (conctention), nd * (itertion). An expression tht pplies regulr opertions to simple lnguges is clled regulr expression (nd the resulting lnguge is regulr lnguge; we will see lter why ). L(E) is the lnguge defined y the regulr expression E. Formlly, is regulr expression if is 1. for some in the lphet Σ (stnds for lnguge {}), 2., stnding for lnguge { }, 3., stnding for the empty lnguge, 4. ( ) 1U, where, 2 1 2 re regulr expressions, 5. ( ), where, 1o 2 1 2 re regulr expressions, * 6. ( ), where is regulr expression. 1 1 Theory of Computtion, Feodor F. Drgn, Kent Stte University 2
Nottions When writing regulr expressions, we use the following conventions: For simple lnguges of the form {}, we write (omitting rces). Prentheses re omitted ccording to the rule tht itertion inds stronger thn conctention, which inds stronger thn union. The conctention symol is often omitted. We write Σ for... 1 n o. * We write for (which is the lnguge tht contins only the empty word). For exmple, 01* stnds for the expression ({ 0} o ({1}*)) ( *). ( ΣΣ)* (0*10*1)*0* Exmples of expressions Σ *000Σ* the lnguge of ll words tht contin the sustring 000 the lnguge of ll words with n even numer of letters the lnguge of ll words tht contin n even numer of 1 s Note tht conctenting the empty set to ny set yields the empty set; 1* = Theory of Computtion, Feodor F. Drgn, Kent Stte University 3
Euivlence with Finite Automt egulr expressions nd finite utomt re euivlent in their descriptive power. Any regulr expression cn e converted into finite utomton tht recognizes the lnguge it descries, nd vice vers. We will prove the following result Theorem. A lnguge is recognizle y FA if nd only if some regulr expression descries it. This theorem hs two directions. We stte ech direction s seprte lemm. Lemm 1. If lnguge is descried y regulr expression, then it is recognizle y FA. We hve regulr expression descriing some lnguge A. We show how to convert into n NFA recognizing A. We proved efore tht if n NFA recognizes A then DFA recognizes A. To convert into n NFA N, we consider the six cses in the forml definition of regulr expression. Theory of Computtion, Feodor F. Drgn, Kent Stte University 4
Proof of Lemm 1 (6 cses) 1. = for some in Σ. Then L( ) = { }, hence N = ({ 1, 2}, Σ, δ, 1,{ 2}) δ ( 1, ) = { 2} δ ( r, ) = for r or 1. 2. =. Then L( ) = { }, hence N = ({ 1}, Σ, δ, 1,{ 1}) δ ( r, ) = for ny r nd. 3. =. Then L( ) =, hence N = ({ }, Σ, δ,, ) δ ( r, ) = for ny r nd. 4. 5. 6. = = = 1 1 * 1 U 2. o 2.. in these cses we use the constructions given in the proofs tht the clss of regulr lnguges is closed under the regulr opertions. We construct the NFA for from NFAs for 1, 2 nd the pproprite closure construction. Theory of Computtion, Feodor F. Drgn, Kent Stte University 5
Exmple 1 ( )* Building n NFA from the regulr expression ( ) * Theory of Computtion, Feodor F. Drgn, Kent Stte University 6
Exmple 2 ( )* ( ) * Building n NFA from the regulr expression Theory of Computtion, Feodor F. Drgn, Kent Stte University 7 ( ) *
Euivlence with Finite Automt We re working on the proof of the following result Theorem. A lnguge is regulr if nd only if some regulr expression descries it. We hve proved Lemm 1. If lnguge is descried y regulr expression, then it is regulr. For given regulr expression, descriing some lnguge A, we hve shown how to convert into n NFA recognizing A. Now we will prove the other direction Lemm 2. If lnguge is regulr then it is descried y regulr expression. For given regulr lnguge A, we need to write regulr expression, descriing A. Since A is regulr, it is ccepted y DFA. We will descrie procedure for converting DFAs into euivlent regulr expressions. We will define new type of finite utomton, generlized NFA (GNFA). nd show how to convert DFAs into GNFAs nd then GNFAs into regulr expression. Theory of Computtion, Feodor F. Drgn, Kent Stte University 8
Generlized Non-deterministic Finite Automt Generlized non-deterministic finite utomt re simply NFAs wherein the trnsition rrows my hve ny regulr expressions s lels, insted of only memers of the lphet or. strt * * ()* * ccept For convenience we reuire tht GNFAs lwys hve form tht meets the following conditions. the strt stte hs rrows going to every other stte ut no ingoing rrows. there is only one ccepting stte. It hs ingoing rrows from every other stte ut no outgoing rrows. moreover, the strt stte is not the sme s the ccept stte. except for the strt nd ccept sttes, one rrow goes from every stte to every other stte nd lso from ech stte to itself. Theory of Computtion, Feodor F. Drgn, Kent Stte University 9
Forml definition of GNFAs A GNFA is 5-tuple ( Q, Σ,, strt, ccept), where 1. Q is the finite set of sttes, 2. Σ is the input lphet, 3. δ : ( Q { ccept}) ( Q { strt}) 4. strt 5. ccept is the strt stte, nd is the ccept stte. δ is the trnsition function, A GNFA ccepts string w in Σ* if w = w1 w,..., w, where ech is in nd seuence of sttes exists such, 2 w tht n i Σ* r 0, r1, r2,..., r n 1. r 0 = strt, rn = ccept 2. For ech i, we hve w i L( i ), where i = δ ( ri 1, ri ) ; in other words, iis the expression on the rrow from r to r. From DFAs to GNFAs dd new stte with n rrow to the old strt stte, new ccept stte with rrows from the old ccept sttes. if ny rrows hve multiple lels (or if there re multiple rrows going etween the sme two sttes in the sme direction) replce ech with single rrow whose lel is the union of the previous lels. dd rrows leled etween sttes tht hd no rrows. i 1 Theory of Computtion, Feodor F. Drgn, Kent Stte University 10 i
i From GNFAs to egulr Expressions. Convert(G) 1. Let k e the numer of sttes of GNFA G. 2. If k=2, then G must consist of strt stte, n ccept stte, nd single rrow connecting them nd leled with regulr expression. eturn the expression. 3. If k>2, select ny stte r Q different from strt nd ccept sttes nd let G e the GNFA ( Q', Σ, δ ', strt, ), where ccept Q' = Q { r}, And for ny Q' { } nd ny Q' { } let for = δ, ), = δ (, ), = δ (, ), = δ (, ). 1 ( i r 2 r r 3 r 4 i 4. Compute Covert(G ) nd return this vlue. 4 1 3 r i ccept δ '( i, ) = ( 1 )( 2 )*( 3 ) ( 4 ), i Clim. For ny GNFA G, G is euivlent to G. 2 Theory of Computtion, Feodor F. Drgn, Kent Stte University 11 strt ( 1 )( 2 )*( 3 ) ( 4 )
Proof of Clim. Clim. For ny GNFA G, G is euivlent to G. We show tht G nd G recognize the sme lnguge Suppose G ccepts n input w then there exists seuence of sttes s.t. 1 2 strt 1 2 3 4 k 3... ccept, wi L( i ), w = w1 w2... wk if none of them is, then G ccepts w r since ech of the new regulr expressions leling rrows of G contins the old reg. expression s prt of union 1 3 r if does pper, removing ech seuence of consecutive sttes r r forms n ccepting pth in G. i i r So, G ccepts w. Suppose G ccepts w s ech rrow etween ny sttes nd in G descries the collection the sttes nd rcketing seuence hve new regulr expression on the rrow etween them tht descries ll strings tking to vi on G i of strings tking i to in G, either directly or vi, G must lso ccept w. r Theory of Computtion, Feodor F. Drgn, Kent Stte University 12 i i 2 4 ( 1 )( 2 )*( 3 ) ( 4 )
1 2 3 s Exmple 1 2 3 s 3 2 ( )* s ( ) * 3 ( )( ) * ( )( ) * s ( ( )* ) (( )( )* ) *(( )( )* ) ( )* Theory of Computtion, Feodor F. Drgn, Kent Stte University 13