Lecture # 10
description
Transcript of Lecture # 10
Lecture # 10Lecture # 10
(Kleene’s Theorem)(Kleene’s Theorem)
Kleene’s Theorem Part III Kleene’s Theorem Part III
Statement:Statement: If the language can be expressed by a RE If the language can be expressed by a RE
then there exists an FA accepting the then there exists an FA accepting the language. language.
(A)(A) As the regular expression is obtained As the regular expression is obtained applying applying additionaddition, , concatenationconcatenation and and closureclosure on the letters of an alphabet and the on the letters of an alphabet and the NullNull string, so while building the RE, sometimes, string, so while building the RE, sometimes, the corresponding FA may be built easily, as the corresponding FA may be built easily, as shown in the following examples shown in the following examples
Example Example Consider the language, defined over Consider the language, defined over
ΣΣ={a,b}, ={a,b}, consisting of only bconsisting of only b, then this , then this language may be accepted by the following language may be accepted by the following FA FA
which shows that this FA helps in building which shows that this FA helps in building an FA accepting only one letter an FA accepting only one letter
Example Example
Consider the language, defined over Consider the language, defined over ΣΣ={a,b}, ={a,b}, consisting of only consisting of only ΛΛ , then this , then this language may be accepted by the language may be accepted by the following FA following FA
Kleene’s Theorem Part III Kleene’s Theorem Part III Continued … Continued …
(B)(B) As, if r1 and r2 are regular expressions As, if r1 and r2 are regular expressions then their sum, concatenation and closure then their sum, concatenation and closure are also regular expressions, so an FA can are also regular expressions, so an FA can be built for any regular expression if the be built for any regular expression if the methods can be developed for building the methods can be developed for building the FAs corresponding to the FAs corresponding to the sumsum, , concatenationconcatenation and and closureclosure of the regular of the regular expressions along with their FAs. These expressions along with their FAs. These three methods are explained in the three methods are explained in the following discussions following discussions
Kleene’s Theorem Part III Kleene’s Theorem Part III Continued … Continued …
Method1Method1 ( (UnionUnion of two FAs): of two FAs):
Using the FAs corresponding to rUsing the FAs corresponding to r11 and r and r22 an an FA can be built, corresponding to FA can be built, corresponding to rr11 + r + r22. . This method can be developed considering This method can be developed considering the following examples the following examples
Example Example Let rLet r11=(a+b)*b defines L=(a+b)*b defines L11 and the FA and the FA11 be be
and rand r22 = (a+b)*aa(a+b)* defines L = (a+b)*aa(a+b)* defines L22 and and FAFA22 be be
Sum of two FAs Continued Sum of two FAs Continued … …
Let FALet FA33 be an FA corresponding to r be an FA corresponding to r11+ r+ r22, then , then the initial state of FAthe initial state of FA33 must correspond to the must correspond to the initial state of FAinitial state of FA1 1 or the initial state of FAor the initial state of FA22. .
Since the language corresponding to rSince the language corresponding to r11+ r+ r22 is is the union of corresponding languages Lthe union of corresponding languages L11 and L and L22, , consists of the strings belonging to Lconsists of the strings belonging to L11or Lor L22 or or both, therefore a final state of FAboth, therefore a final state of FA3 3 must must correspond to a final state of FAcorrespond to a final state of FA11 or FA or FA22 or both. or both.
Sum of two FAs Continued Sum of two FAs Continued … …
Since, in general, FASince, in general, FA33 will be different from will be different from both FAboth FA1 1 and FAand FA22, so the labels of the states of , so the labels of the states of FAFA33 may be supposed to be z may be supposed to be z11,z,z22, z, z33, …, where , …, where zz1 1 is supposed to be the initial state. Since zis supposed to be the initial state. Since z11 corresponds to the states xcorresponds to the states x11 or y or y11, so there will , so there will be two transitions separately for each letter be two transitions separately for each letter read at zread at z11. It will give two possibilities of . It will give two possibilities of states either zstates either z11 or different from z or different from z11. This . This process may be expressed in the following process may be expressed in the following transition table for all possible states of FAtransition table for all possible states of FA33..
Example continued … Example continued …
Old statesOld statesNew states after New states after
readingreading
a a b b
zz11– – € € (x(x11,y,y11) ) (x(x11,y,y22) ) €€ z z22 (x(x22,y,y11) ) €€ z z33
Example continued … Example continued …
Old statesOld statesNew states after readingNew states after reading
a a b b
zz11– – € € (x(x11,y,y11) ) (x(x11,y,y22) ) €€ z z22 (x(x22,y,y11) ) €€ z z33
zz22 € € (x(x11, y, y22) ) (x(x11, y, y33) ) € € zz44 (x(x22, y, y11) ) € € zz33
zz33 + + € € (x(x22, y, y11)) (x(x11, y, y22) ) € € zz22 (x(x22, y, y11) ) € € zz33
zz44 + + € € (x(x11, y, y33) ) (x(x11, y, y33) ) € € zz44 (x(x22, y, y33) ) € € zz55
zz55 + + € € (x(x22, y, y33) ) (x(x11, y, y33) ) € € zz44 (x(x22, y, y33) ) € € zz55
Example continued … Example continued …
RERE corresponding to the above FA may be corresponding to the above FA may be
rr11+r+r22 = (a+b)*b + (a+b )*aa(a+b )* = (a+b)*b + (a+b )*aa(a+b )*
Example Example Let Let rr11=(a+b)*a=(a+b)*a and the corresponding and the corresponding FAFA11
be be
also also rr22 = (a+b)( (a+b)(a+b) )* = (a+b)( (a+b)(a+b) )* or or ( (a+b)(a+b) )*(a+b)( (a+b)(a+b) )*(a+b) and and FAFA22 be be
TASKTASK
Generate Union of FAs corresponding to Generate Union of FAs corresponding to rr11 and and rr22 i.e. i.e. rr11+ r+ r22
Assignment No 1Assignment No 1
Input Input FAFA11 and and FAFA22 representing representing rr11 and and rr2 2
respectively.respectively.
Generate a final automata Generate a final automata FAFA33 representing representing the Union of the Union of FAFA11 and and FAFA22 corresponding to corresponding to rr11+ r+ r2 2 . . Based on the algorithm studied of Based on the algorithm studied of Union of two FAs.Union of two FAs.
DueDue: 26: 26thth Dec, 2013 Dec, 2013
Kleene’s Theorem Part III Kleene’s Theorem Part III Continued … Continued …
Method2 (Concatenation of two FAs)Method2 (Concatenation of two FAs): :
Using the FAs corresponding to Using the FAs corresponding to rr11 and and rr2 2 , ,
an FA can be built, corresponding to an FA can be built, corresponding to rr11rr2 2 . .
This method can be developed considering This method can be developed considering the following examples the following examples
Example Example Let Let rr11 =(a+b)*b defines L=(a+b)*b defines L11 and FA and FA11 be be
and and rr2 2 = (a+b )*aa (a+b )* defines L= (a+b )*aa (a+b )* defines L22 and FA and FA22
be be
Concatenation of two FAs Concatenation of two FAs Continued … Continued …
Let FALet FA33 be an FA corresponding to be an FA corresponding to rr11rr2 2 , then the , then the initial state of FAinitial state of FA33 must correspond to the initial must correspond to the initial state of FAstate of FA11 and the final state of FA and the final state of FA33 must must correspond to the final state of FAcorrespond to the final state of FA22 . Since the . Since the language corresponding to language corresponding to rr11rr2 2 is the is the concatenation of corresponding languages Lconcatenation of corresponding languages L11 and and LL22 , consists of the strings obtained, , consists of the strings obtained, concatenating the strings of Lconcatenating the strings of L11 to those of L to those of L22 , , thereforetherefore the moment a final state of first FA is the moment a final state of first FA is entered, the possibility of the initial state of entered, the possibility of the initial state of second FA will be included as well.second FA will be included as well.
Concatenation of two FAs Concatenation of two FAs Continued … Continued …
Since, in general, FASince, in general, FA33 will be different from both will be different from both FAFA11 and FA and FA22 , so the labels of the states of FA , so the labels of the states of FA33 may be supposed to be zmay be supposed to be z11,z,z22, z, z33, …, where z, …, where z1 1
stands for the initial state. Since zstands for the initial state. Since z1 1 corresponds corresponds to the states xto the states x11 , so there will be two transitions , so there will be two transitions separately for each letter read at zseparately for each letter read at z1 1 . It will give . It will give two possibilities of states which correspond to two possibilities of states which correspond to either zeither z1 1 or different from zor different from z1 1 . This process may . This process may be expressed in the following transition table for be expressed in the following transition table for all possible states of FAall possible states of FA33
Example continued … Example continued …
Old statesOld statesNew states after New states after
readingreading
a a b b
zz11– – € € xx11 xx11 €€ z z11 (x(x22,y,y11) ) €€ z z22
Example continued … Example continued …
Old statesOld statesNew states after readingNew states after reading
a a b b
zz11– – € € xx11 xx11 €€ z z11 (x(x22,y,y11) ) €€ z z22
zz22 € € (x(x22, y, y11) ) (x(x11, y, y22) ) € € zz33 (x(x22, y, y11) ) € € zz22
zz33 € € (x(x11, y, y22)) (x(x11, y, y33) ) € € zz44 (x(x22, y, y11) ) € € zz22
zz44 + + € € ((xx11, y, y33) ) (x(x11, y, y33) ) € € zz44 ((xx22, y, y11, y, y33) ) € € zz55
zz55 + + € € (x(x22, y, y11, y, y33) ) (x(x11, y, y22, y, y33) ) € € zz66 (x(x22, y, y11, y, y33) ) € € zz55
zz66 + + € € (x(x11, , yy22, y, y33) ) (x(x11, , yy33) ) € € zz44 ((xx22, y, y11, y, y33) ) € € zz55
Example continued … Example continued …
Example Example Let Let rr11 =((a+b)(a+b))* , the corresponding =((a+b)(a+b))* , the corresponding
FAFA11 be be
also also rr22 = (a+b)((a+b)(a+b))* or = (a+b)((a+b)(a+b))* or ((a+b)(a+b))*(a+b) and FA((a+b)(a+b))*(a+b) and FA22 be be
TASKTASK
Generate the Generate the FAFA representing representing rr11 rr22 using Concatenation Algorithmusing Concatenation Algorithm