Download as pdf
Download as pdf
You are on page 1of 14
After going through this chapter, you should be able to understand : Regular sets and Regular Expressions Constructing FA fora given REs Conversion of FAto RES Pumping Lemma of Regular sets Closure properties of Regular sets 3.1 REGULAR SETS A special class of sets of words over S, called regular sets, is defined recursively as follows. (Kleene proves that any set recognized by an FSM is regular. Conversely, every regula set can berecognized by some FSM.) 1, Every finite set of words over S (including ¢, he empty set) is aregular se, 2 If Aand Bareregularsets over S, then 4\, Band AB are also regular 3, IfSisaregular set oversS, then soisits closure S*, 4, Nosetisregular unless itis obtained by finite number of applications of definitions (1)t0(3). i.e, the class of regular sets over Sis the smallest class containing al finite sets of words over S and closed under union, concatenation and star operation, Examples; }) Let £={a,b} then the set of strings that contain both odd. number of a's and b's is a regulrset, i) Let S= {0} then the setofstrings {0,00,000,...} isaregular se, fi) Let 2 = {0,1} then the setofstrings {01 10} isaregular set. FORMAL LANGUAGES AND AUTOMATA THEORY Page 28 3.2 REGULAR EXPRESSIONS The languages accepted by FA are regular languages and these languages are easily described by simple expressions called regular expressions, We have some algebraic notations to represent the regular expressions, Regular expressions are means to represent certain sets of strings in some algebraic manner and regular expressions describe the language accepted by FA. If 5 isanalphabet then regular expression(s) over this can be described by following rules. Any symbol from 3,¢ and 4 are regular expressions. If r, and r, are two regular expressions then union of these represented ay 7, U 7 OF 1 +f ivalsoa regular expression . fr, and r, are two regular expressions then concatenation of these represented as 77, is also a regular expression. |. The Kleene closure of'a regular expression ris denoted by + is also a regular expression. . If is aregular expression then (r) is also regular expression. The regular expressions obtained by applying rules 1 to 5 once or more than once are also regular expressions, Examples : (1) If = (a,d),then (@) aisaregular expression (Usingrule 1) (®) bisaregularexpression (Usingrule 1) (©) a +b isaregular expression (Using rule2) @ b+ isaregularexpression (Usingnule 4) © ab isaregular expression (Usingnule3) (© ab + b* isaregularexpression (Using rule 6) (2) Find regular expression for the following (a) A language consists ofall the words over (a, b} ending in p. (b) A language consists ofall the words over (a, b} ending in 5. (©) Alanguage consists of all the words over {a, b} starting with a and ending ind. (@ A language consists ofall the words over {a, 6} having 99 asa substring. (©) A language consists of all the words over (a, 6} ending in aah, Solution : Let 2={a,b} and Allthe words over 2 = {¢, 4,6, aa, bb, ab, ba, aaa,.....}= E* or (a +b) * or (au b)* FORMAL LANGUAGES AND AUTOMATA THEORY Page 29 4,6, aa, bb, ab, ba, aaa, bbb, abb, baa, aabb,...} = {Allthe words over {a 5} } = (a+b)* So, (a* +5) = (a+) * 3.3 IDENTITIES FOR REs The two regular expressions P and Q are equivalent ( denoted as P= Q ) if and only if P represents the came set of strings as Q does. For showing this equivalence of regular expressions weneed to show some identities of regular expressions. LetP,Qand Rare regular expressions then the identity rules areas given below ek=Ke=K “ ccismll string (=< isempty sting. @R=R)=> Ore ReR (P+ Q)R= PR+OR "O)=(P' +0) RY(c+R)=(e+R)R’ = RE (Ree) = R° etR = R’ (PQ) P= P(QPY 16. RR+R=RR 3.3.1. Equivalence of two REs Let us see one important theorem named Arden's Theorem which helps in checking the equivalence of two regular expressions. FORMAL LANGUAGES AND AUTOMATA THEORY Page 30 Ardon’s Theorem : Let P and Q be the two regular expressions over the input set :. The regular expression Ris given as R=Q+ RP ‘Which hasaunique solutionas R= QP" Proof : Let, Pand Q are two regular expressions over the input string ¥;. IfP does not contain ¢ then there exists R such that R=Q+RP sal) ‘We will replace R by QP* in equation 1. Consider R. H. S. of equation 1. =Q+0P'P =0(¢ +P?) =oP ver RR=R ‘Ths R=0P" isproved. To prove that = QP" isa unique solution, we will now replace L.HLS. of equation 1 byQ+RP. Then it becomes Q+RP mela lest Q+RP=Q+(Q+RP)P =or0r+ Rr Again replace R by Q+RP. =Q+0P+(Q+RP)P’ =0+0P+OP*+RP* ‘Thus ff we go on replacing R by Q+ RP then we get, 0+ RP=0+ OP + OP*+....40P' + RP* = Q(EHP + PP Ph) RP From equation |, RaQ HEE Pte t PVE RE Where i20 Consider equation 2, R=Qle+P +P? tant PY) RPM R=QP'+RP* ieawboaitigoflenghi. FORMAL LANGUAGES AND AUTOMATA THEORY Page 31 =£6.0,000,1111,0110 oo) = { any combination of 0's, any combination of I's, any combination of Oand 1 } Hence, ‘I. H.S.=R.H.S.isproved. 3.4 RELATIONSHIP BETWEEN FAAND RE “There isa cose relationship between finite automa andthe regular expression wecan show thisreation in below figure. Can be Converted NFA without moves FIGURE : Relationship between FA and regular expression “The above figure shows that itis convenient fo convert the regular expression to NFA with € moves. Letus ee the theorem based on this conversion, 3.5 CONSTRUCTING FA FOR A GIVEN REs ‘Thoorem If bearegular expression then here exists @ NFAWwit -moves, wich accepts Zr) Proof First we will discuss the onstruction of NFA. with « -moves forregular expression rr and then we prove that L(M) = I(r). Let r bethe regular expression over the alphabet >. Construction of NFA with . - moves Case 1: @ r=6 FORMAL LANGUAGES AND AUTOMATA THEORY Page 32 NEA M = ({s, #3, (18,5, (/9) as shownin Figurel (a) : (No path from initial state sto reach the final state) Figure 4 (a) fi) r=e NFA Mf = ({3}, {}.8,s, (9) asshown in Figure I (b) ©) (The initial state sis the final state) Figure 1 (b) @i) r = asforalla ex, NFA M = (fs, f1.2,6.5, 1/1) . (One pais there from initial states —O-O toreach the final state fwith label a.) Figure 4(c) Gase2: [rit Let», and », bethetworegular expressions over 2,,, and N, and N, aretwo NFA for +, and r, respectively as shown in Figure2 (2) Figure 2 (a) NFA for regular expression », and r, FORMAL LANGUAGES AND AUTOMATA THEORY Page 33 ‘Now letus compute for final state, which denotes the regular expression. + willbe computed, because there ae total 2 states and final state is g, whose start states 9, ri-ihebba)ba) =0(e)"e)+0 =0+0 +f) =0 which isa final regular expression. 3.6.1 Arden’s Method for Converting DFA to RE ‘As we have seen the Arden’s theorem is useful for checking the equivalence of two regular expressions, we will also sec its use in conversion of DFA to RE. Following algorithm is used to build ther. c. from given DFA. 1. Let g, bethe initial stat. 2. ‘Thereare 4, 43:43,4a»-dy ttumber of states. The final state may be some q, where jm 3. Let a., represents the transition from 4, 10 9,. 4, Calculate g, such that q= 4,4, Ifg, isastartstate aa yay 5. Similarly compute the final state which ultimately gives the regular expression . Example 4 : Construct RE for the given DFA a )Dau Solution : Since there is only one state inthe finite automata let us solve for g, only. 49 = 400+ Gite p(O+1)te FORMAL LANGUAGES AND AUTOMATA THEORY fonstruct RE for the DFA given in below figure. Solution : Letus see the equations G = +q,0+€ 1 = 400 = 40 95 = 90+ G.1+9,00+1) Letus solve 4p first, 07 ail4q,0+€ Go = GOL + gol Ore Ge = Gp(01410)+€ “R=Q+RP qo=€{01410)* = 0P* where Go (01+10)* R=4Go.Q =€,P=(01+10) ‘Thus the regular expression will be r=(01+10)* Since q, isa final state, we are interested in q, only. FORMAL LANGUAGES AND AUTOMATA THEORY Example 8 ; Show that the language 1 - {a’ b*|i> 0} isnot regular. Solution : The set of strings accepted by language Lis, = {abb, aabbbb, aaabbbbbb, aaaabbbbbbbb.. Applying Pumping lemma for any ofthe stringsabove. Take the string abb. Itis ofthe form www. Where, | uv |si|v 21 To find isuch that w/w ¢ L Takei =2here, then w'w = a(bb)> bbb Hence wv'w=abbb ¢ L Since abbb is not present in the strings of L. ~ Lisnot regular. Example 9 ; Show that L = {0"|n is a perfect square } is not regular. Solution : Stop 1 : Let Lis regular by Pumping lemma. Let n be number of states of FA accepting L. Step 2: Let : = 0° then |z[/=n22. ‘Therefore, we can write z=uvw ; Where | wv}s mv 1. Take any string of the language L= { 00, 0000, 000000... ‘Take 0000 as string, here u=0, v=0, w=00to indi such that wv'we J. ‘Take i=2 here, then wv'w= 0(0)700 00000 ‘This string 00000 is not present in strings of language L. So av'we L- :. Itisacontradiction. 3.9 PROPERTIES OF REGULAR SETS Regular sets are closed under following properties, 1. Union 2. Coneatenation FORMAL LANGUAGES AND AUTOMATA THEORY Page 36 Kleene Closure ‘Complementation ‘Transpose Intersection . Union : If R, and R, are two regular sets, then union of these denoted by R, + R, or R, UR; isalsoa regular set. Proof : Let R, and R, be recognized by NFA N, and NV, respectively as shown in Figurel (a)and Figure! (b). FIGURE 4(a) NFA for regular set R, @ —__—— FIGURE 1(b) NFA for regular set R, ‘We construct a new NFA.N based on union of NV, and N, as shown in Figure | (c) FIGURE 1(c) NFAfor 1, + 1p Now, 1(N) = €L(M)) € + €L(N3) € Since, Nis FA, hence L(V) isa regular set (language). Therefore, R, + R, isa regularset, FORMAL LANGUAGES AND AUTOMATA THEORY 2. Concatenation : If Rand R, are two regular sets, then concatenation of these denoted by RR; isalso aregular set. Proof : Let R, and R, be recognized by NFA N, and N; respectively as shown in Figure 2(a) and Figure 2(b). FIGURE 2(b) NFA for regular set , ‘We construct anew NFA Nbased on concatenation of N, and N, as shownin Figure2(c). GG" ®D FIGURE 2(c) NFA for regular set 2,R, Now, I(N) = Regular set accepted by 1, followed by regular set accepted by NV, = RR, Since, L(V) isaregular set, hence R,R, isalsoa regular set. . Kleene Closure : If Risa regular set, then Kleene closure of this denoted by R*is also regular set Proof: Let R is accepted by NFA N shown in Figure 3(a). FIGURE 3(a) NFA for regular set FORMAL LANGUAGES AND AUTOMATA THEORY ‘We construct a new NFA based on NFA Nas shown in Figure 3(b). FIGURE 3({b) NFA for regular expression for R* ER ARR,RRR yur} Since, L(V) isaregular set, therefore R° is aregular set. . Complement : If x is a regular set on some alphabet 5: , then complement of R is denoted by £° - R or R isalsoaregular set. Proof : Let x be accepted by NFA N = (Q,E,6,s,F). It means, L(N)=R. Nis shown in Figure 4(a). FIGURE 4(a) NFA for regular set R We construct anew NFA 1v' based on yy as follows: (a) Change all final states to non-inal states. () Change all non-final states to final states. Nis shownin Figure 4(b) FIGURE 4 (b) NFA FORMAL LANGUAGES AND AUTOMATA THEORY Page 39 Now, 1(N")= {All the words which are not accepted by NFA N} = { All the rejected words by NFA.N} =r°-R Since, L(N') isa regular set, therefore (:" - R) isaregular set. . Transpose : If Ris aregular set, then the transpose denoted by ”, is also aregular set. Proof : Let x beaccepted byNFA N = (Q,2,5,s,F°) as shown in Figure 5(a). FIGURE 5 (a) NFAN for regular set R If w isa wondin x, then Wanspose (reverse) is denoted by ww" - Let w= a,a30d, Then w? = a,a,...-0, ‘We construct anew yy" based on 1 using following rules : (@ Change the all final states into non-final states and merge all these into one state and makeit initial state, (b) Change initial state to final state. (©) Reverse the direction of ll edges. 1y* isshown in Figures (b) FIGURE 5(b) NFAN’for regular set” FORMAL LANGUAGES AND AUTOMATA THEORY Let w = aia;...a, beawordin R, then itis recognized by jv and w? = a,a,_,...a, istecognized by 1" as shown in Figures (b) In general, we say that ifa word w in Ris accepted by Vand then yy" accepts 7. Since, £(1’) isaregular set containingall 7 ;itmeans, £(N') = R. Thus, X” isa regular set . Intersection : if R and R, are two regular sets over 5, then intersection of these denoted by R, m R, isalsoaregular set. Proof : By De Morgan's law for two scts A and Bover R, AN B=R*-(R*-A)U(R*-B)) So, RO Ry = B*-(E*-R,)U(E*-R,)) Let Ry =(2*-R,) and R, =(2*-R,) So, R; and A, are regular sets as these are complement of R, and R,. Let Ry = Ry Ry So, &; isa regular set because itis the union of two regular sets R, and R,. Let Ry =E°-R, So, 2; isa regular set because it isthe complement of regular set ,. Therefore, intersection of two regular sets is also regular sct. FORMAL LANGUAGES AND AUTOMATA THEORY Page 41

You might also like