Finite Automt (FA or DFA) CHAPTER Regulr Lnguges Contents definitions, exmples, designing, regulr opertions Non-deterministic Finite Automt (NFA) definitions, equivlence of NFAs DFAs, closure under regulr opertions Regulr expressions definitions, equivlence with finite utomt Non-regulr Lnguges the pumping lemm for regulr lnguges Automt & Forml Lnguges, Feodor F. Drgn, Kent Stte University Finite Automt A simplest computtionl model Models computers with very smll mount of memory vrious electromechnicl devices rer Exmple: utomtic door controller front i.e., entries, exits in supermrkets Two sttes: open, closed 4 possile inputs (from two sensors) front oth rer neither Stte trnsition tle Input signl neither front rer oth Stte digrm rer oth neither front front rer oth Stte closed closed open closed closed open closed open open open closed open neither Automt & Forml Lnguges, Feodor F. Drgn, Kent Stte University
Finite Automt Other exmples: elevtor controller, dish wshers, digitl wtches, clcultors Next we will give definition of FA from mthemticl prospective terminology for descriing mnipulting FA theoretic results descriing their power limittion A finite utomton M tht hs three sttes q q, Automt & Forml Lnguges, Feodor F. Drgn, Kent Stte University 3 (Deterministic) Finite Automt: Definition An importnt wy to descrie certin simple ut highly useful lnguges clled regulr lnguges. It is A grph with finite numer of nodes, clled sttes. Arcs re leled with one or more symols from some lphet. One stte is chosen s the strt stte or initil stte. Some sttes re finl sttes or ccepting sttes. The lnguge of the FA is the set of strings tht lel pths tht go from the strt stte to some finl stte. Exmple: finite utomton M tht hs three sttes q q, Automt & Forml Lnguges, Feodor F. Drgn, Kent Stte University 4
Forml Definition of DFAs A deterministic finite utomton (DFA) is specified y 5-tuple ( Q, δ, q, where, F) Q is finite set of sttes, Q = { q, q, } Σ is finite lphet, Σ = {,} δ : Q Σ Q is the trnsition function, δ ( q,) = q, δ (,) = q,... q Q is the initil stte, q = q F Q is the set of finl sttes. F = {q} A DFA is usully represented y directed leled grph (so clled trnsition digrm) nodes = sttes, rc from q to p is leled y the set of input symols such tht δ ( q, ) = p no rc if no such, strt stte indicted y word strt n rrow, ccepting sttes get doule circles. For DFA we hve q q M Automt & Forml Lnguges, Feodor F. Drgn, Kent Stte University 5, Acceptnce of Strings the Lnguge of DFA Let M= ( Q, Σ, δ, q, F ) e finite utomton Let w = w, w e string over,..., w n Σ M ccepts w if sequence of sttes r, r, r,..., the following three conditions:. r = q,. δ ( ri, wi + ) = ri + for i =,..., n, 3. r n F If L is set of strings tht M ccepts, we sy tht L is the lnguge of mchine M write L=L(M). We sy M recognizes L or M ccepts L. In our exmple, L( M )=L, where L={w: w contins t lest one n even numer of s follow the lst } exists in Q with Automt & Forml Lnguges, Feodor F. Drgn, Kent Stte University 6 q r n q, 3
Regulr Lnguges A lnguge is clled regulr lnguge if some finite utomton recognizes it. Min questions is: Given lnguge L, construct, if possile, FA M which recognizes L, i.e., L(M)=L. (Is L regulr lnguge?) Another question is Given FA M, descrie its lnguge L(M) s set of strings over its lphet. First consider some exmples: q q L( M )={w: w ends in } L( )={w: w is ε or ends in } M 3 L( M 4 )={w: w strts ends with the sme symol} Automt & Forml Lnguges, Feodor F. Drgn, Kent Stte University 7 q s r r Design of DFAs Given lnguge, design finite utomton tht recognizes it. This is cretive process, is rt. No simple universl methods. One intuitive wy: put yourself in the plce of the mchine you re trying to design see how you would go out performing the mchine s tsk. we need to receive string to determine whether it is memer of the lnguge. we get to see the symols in the string one y one. fter ech symol we must decide whether the string seen so fr is in the lnguge (we don t know when the end of the string is coming, so we must lwys e redy with the nswer). we hve finite memory, so we hve to figure out wht we need to rememer out the string s we re reding it (we cnnot rememer ll we hve seen). In this wy we will find out how mny sttes our utomton will hve ( wht re the sttes). Exmple: the lnguge consists of ll strings over lphet {,} with odd numer of s. Automt & Forml Lnguges, Feodor F. Drgn, Kent Stte University 8 4
qe qo Two possiilities:. Even so fr,. Odd so fr. Hence two sttes. Design of FA for L={strings contining } We scn our string. There re four possiilities:. hve not just seen ny symol of the pttern,. hve just seen, 3. hve just seen, or 4. hve seen the entire pttern. So, four sttes q, q, q, q Therefore, L={strings with odd numer of s}, q q q q Automt & Forml Lnguges, Feodor F. Drgn, Kent Stte University 9 Regulr Opertions Let L L e lnguges. We define the regulr opertions union, intersection, conctention, str s follows. Union: Intersection: Conctention: Str: L L = { w: L L L = { w: L Lo L = { wv : L * L = { w w... w : k L}. L}. v L}. ech w L}. Exmple: Let the lphet Σ e the strd 6 letters {,,,z}. If L={good, d} L= {oy, girl}, then L L = {good, d, oy, girl}. k or L L = Lo L = {goodoy, doy, goodgirl, dgirl}. * {, good, d, goodgood, dgood, dd, goodd, L = ε goodgoodgood, goodgoodd, gooddd, } i Automt & Forml Lnguges, Feodor F. Drgn, Kent Stte University 5
Product construction It would e useful if we cn construct FAs for L L from FAs for L L, no mtter wht L L. This would give systemtic wy of constructing from the utomt M M n utomton tht checks if the input contins n odd numer of s or the sustring s well s L L if the input contins n odd numer of s the sustring. qeven qodd q L(M)={w: w contins n odd numer of s} L( M)={w: w contins sustring } q q q we cn run oth utomt in prllel, y rememering the sttes of oth utomt while reding the input. This is chieved y the product construction, Automt & Forml Lnguges, Feodor F. Drgn, Kent Stte University Product construction Let M= ( Q, Σ, δ, q, F ) M= ( Q, δ,, F ) e two FA with the sme lphet. We define finite utomton M such tht L( M ) = L( M) L( M ) such tht L( M ) = L( M) L( M ) s follows. M M M A,R B,R = ( Q, δ, q, F = ( Q, δ, q, F L( M ) = L( M) L( M ) ) ) where Q = Q Q, δ (( q, q ), ) = ( δ ( q, ), δ ( q, )), ( q, q ) F ( q, q ) F Automt & Forml Lnguges, Feodor F. Drgn, Kent Stte University q = ( q, q A,S A,T A,U B,S B,T B,U ), iff q F iff q F q F, or q F. Here, A=qood B=qeven R=q S=q T=q U=q ={w: w contins n odd numer of s the sustring } 6
Product construction A,R B,R A,S A,T A,U B,S B,T B,U L( M ) = L( M) L( M ) ={w: w contins n odd numer of s or the sustring } We hve proved y construction tht Theorem. The clss of regulr lnguges is closed under the union opertion. Theorem. The clss of regulr lnguges is closed under the intersection opertion. Lter we will show tht they re closed under conctention str opertions. Automt & Forml Lnguges, Feodor F. Drgn, Kent Stte University 3 7