 In today's lecture, we discuss about Clojure properties of regular languages. Some of the Clojure properties of regular languages are very straight forward from the definition that you have already observed. For example, if you say the regular the class of regular languages is close with respect to union that is straight forward from the definition or we can say that the class of regular language is close with respect to concatenation that is also straight forward from the definition and the class of regular languages is close with respect to clinic star that is also the part of the definition. Now, several set theoretic Clojure properties that we can see because a language is a set because this is a subset of sigma star. So, several set theoretic questions we can have and see like whether the class of regular languages are close with respect to those set theoretic constructs. Let us go one after another systematically and main point here you can observe that these Clojure properties will be helpful to understand further some of the new languages are regular. For example, if you have identified a language which is union of some of the known like regular languages you can use the definition or you know the Clojure property to say that the new language is regular. So, let us first look at this compliment. So, that means the question is if you are given a regular language L whether L compliment is regular this is not straight forward from the definition as you understand. Now, the answer is the class of regular languages is closed with respect to compliment that means if you are given a regular language L L compliment is regular. How do we observe this you consider a DFA for a given regular language and then you can do this by interchanging the roles of final and non-final states you can quickly understand that the compliment of a regular language is regular. That means for example, if you consider a language L and a corresponding to which let a be a DFA has given here q sigma delta q naught f. Now, you construct a dash states that is same as q as in a the alphabet of course is same then the transition map also we are not going to change the initial state is same, but the final states now the original non-final states you make them as final states and the original final states you make them as non-final states. That is by interchanging the roles of final and non-final states if you construct then you understand that the language accepted with a new DFA is compliment of the given language. So, this is the construction of a dash now you can quickly ascertain that if you take any x in sigma star if x is in L compliment that means x is not in L that is if you put x in the initial state of the original DFA then it will not reach to a final state. If it is not reaching to a final state that means in the new DFA that is a dash you see that delta cap of q naught at x by a supplying to the initial state you will be getting a final state of the new DFA and hence you conclude that this x is accepted within new DFA and as you see you know these are equivalent statements all what are all what are all written here and hence we can conclude that the new constructed DFA is precisely accepting a compliment of the given language. Now, if you have already identified a language is regular then it is compliment is to understand that the compliment is if you want to see that a language is regular if it is compliment of a known regular language you can conclude quickly that it is also regular. Now, let us look at certain corollaries of this result for example, intersection you consider the class of regular language is closed with respect to intersection why because the intersection has a relation with respect to compliments and unions as I mean by the de Morgan law as stated here L 1 intersection L 2 is L 1 compliment union L 2 compliment whole compliment this is the de Morgan law. Now, if you assume that L 1 and L 2 are regular as we have understood that L 1 compliment is regular L 2 compliment is regular and hence union of regular languages that is from the definition this is a regular language and a compliment of a regular language once again you use the result just we have observed and understand that intersection of two regular languages is regular. So, given a language if you want to see that is regular if it is intersection of some known regular languages you can quickly conclude using this result that it is regular, but one may be interested to find a DFA or an NFA finite automaton for a given language to say that it is regular for which I will give you an alternative proof for this result that means a construct constructive proof here we give a DFA to accept intersection of given two regular languages. So, what do you do you for in general let me give you the construct here consider 2 DFA say a 1 and a 2 let me call as the state sets q 1 q 2 and of course, common alphabet is sigma and the respective transition maps are delta 1 and delta 2 and the initial states here you may call it as q 1 and q 2 and the final states f 1 and f 2 for each here. So, I am considering 2 DFA as given here and now if you set a DFA as given here this is the quintuple the Cartesian product of the respective state sets of the given DFA and of course, the common alphabet sigma is the input alphabet for this and delta you define point wise that means if you take any state in the new DFA it is of the form a pair p q. Now, if you take any symbol a in sigma what do you do what are the transition that it is taking place in the first DFA you give as a first component and similarly, in the second DFA what are the transitions it is taking you give it as a second component and that is how this delta is defined and the initial state is the initial component first initial state component of the first DFA and the initial state of the second DFA we take it as components and declare that as q 1 q 2 here that is a initial state and final states is f 1 cross f 2 here because f 1 is final states of first DFA f 2 is final states of second DFA you consider f 1 cross f 2. Now, if you construct a DFA like this you can understand that this new DFA a is will accept the intersection of l 1 and l 2 where l 1 is the language accepted by a 1 and l 2 is the language accepted by a 2. For this first observe first observe that delta cap of p q for any state p q of the new DFA if you supply any string x in sigma star it is precisely delta cap delta 1 cap p x comma delta 2 cap q x. This you can observe by applying induction on the length of the string x that is not a big deal you can take it as an exercise and try that this is happening here. Now, I use this to quickly understand that the new DFA accept precisely l 1 intersection l 2. Now, take a string that is accepted by the new DFA a that means by definition by this observation you can say that you can say that the component wise that is going in f 1 cross f 2 because if you say a string is in language accepted by a this is the definition that is going to the final state by supplying the string x in the initial state of the DFA. And now by as this observation you can say that this is these are the values of that you are getting in f 1 and f 2 that means if you say a pair is in f r cross f 2 the component wise they belong delta 1 cap of q 1 x is in f 1 and delta 2 cap of q 2 x is in f 2. And now here now you have got the x is in l 1 and x is in l 2 as well and hence x is in l 1 intersection l 2. And you understand that this is you can follow conversely that if it is in the intersection this is what is happening and if it is in l 1 this is the situation with the first DFA and this is the situation with the second DFA. And these components if you take as a pair that is in f 1 cross f 2 and what we have observed by in this line you can again go back to here because these two are equal. And hence you can say that x is in x is in the language accepted by a. So, this constructive proof gives you a DFA which accepts intersection of two regular languages. Now let me give you an example because for example if you consider this all those strings in 0 1 star with the property that the number of zeros in x is even and the number of ones in x is odd. Suppose if you consider this language we can observe that it is regular of course you if you know that then this with this property if you consider the strings it is regular. And with this property if you consider the strings in over 0 1 if it is regular from the previous result that means intersection of two regular languages is regular you can get it. You see that this DFA this we have constructed earlier this DFA accepts all those strings over 0 1 with even number of zeros. Similarly you know that this DFA accepts all those strings with odd number of ones. Now from the result you can say the given language is regular, but using the construction you can give the DFA that accepts the given language this language. Now you consider the Cartesian product of these states here you have q 1 q 2 p 1 p 2. Now there are 4 pairs that is q 1 p 1 q 1 p 2 q 2 p 1 q 2 p 2 let me call them as s 1 s 2 s 3 s 4. And then in the Cartesian product the DFA what you have to do you have to put the respective transitions component wise and construct the DFA that is the construction given to you. So, if you construct using that you will get this. And now you see from the construction I have to declare s 2 s final state because in the first DFA q 1 is final state and second DFA p 2 is final state. Now q 1 p 2 that is state s 2 if you declare that as final state from the previous result this particular DFA gives you gives this particular DFA accepts the language given to you. Now by choosing the appropriate final states here you can vary this for example, if I choose s 3 what is the meaning of s 3 choosing as final state instead of s 2. This q 2 p 1 in q if you consider the first DFA q 2 as final state instead of q 1 you understand that the number of 0s accepted by this the number of 0s in any string accepted by this DFA is odd. And s 3 this is p 1 if this is if this is the situation if this is the final state with the second DFA then the number of 1s accepted by this DFA is even. And thus you can see if you makes s 3 as final state instead of s 2 this accepts all those strings in which the number of 0s is odd and number of 1s is even. For example, if you consider s 4 as a final state instead of s 2 that is q 2 p 2. So, q 2 if you consider the first DFA this accepts all those strings in which the number of 0s is odd. And in this case number of 1s is odd and thus intersection that is number of 0s is odd and number of 1s is also odd. Similarly, if you consider s 1 or now if you consider say s 2 and s 3 or any combination s 2 s 4 both of them that means, then this or this the property pertaining to s 2 or the property pertaining to s 4 or if you consider you know any of the combinations you understand that you know this particular construct is helpful to understand that various combinations of you know languages with the number of 0s and number of with the property of number of 0s and number of 1s either even odd can be observed here. So, this construction the Cartesian product construction of course, here we have observed the intersection of 2 regular languages is regular, but this construction will be helpful to understand some of the complicated languages to see they are regular. For example, you consider this set of all those strings over 0 1 in which the strings have number of 0s is even if and only if number of 1s is odd. If you consider this language you see this is a conditional statement whenever x has even number of 0s, then the number of 1s should be odd and conversely. So, the condition is looking little bit complicated. So, what you you can you know little bit analyze this little bit analyze this logical statement and formulate the appropriate connectives in terms of you know and or not or whatever and the previous construct that Cartesian product construct may be helpful to observe that this particular language is regular. You can take it this as an exercise and try to show that this particular language is regular. Now, let me consider another set set theoretic construct this is set difference and see that from the previous results that means, the complement and intersection if you consider the class of regular languages is closed under set difference. That means, if l 1 and l 2 are regular then l 1 minus l 2 that is also regular. You know that l 1 different l 1 minus l 2 is essentially l 1 intersection l 2 complement this is set theoretic property related to set difference. You see if l 2 is regular l 2 complement is regular l 1 is regular is given and l 2 complement is regular intersection of two regular languages is regular. So, you can understand that set difference you know set difference that preserves regularity or regular languages. Now, let me give you an example consider the language a power n such that n greater than equal to 5. That means, all those strings for single letter alphabet whose length is bigger than equal to 5 this is regular of course, constructing a d f a is not a big deal for you, but let me use this you take l 1 to be l of a star that means, the language represented by the regular expression a star and hence it is regular. And l 2 you consider these strings empty string a a square a cube a power 4 consider these strings and you know a finite set is a regular language. This is regular and this is l 1 is regular l 2 is regular l 1 minus l 2 is also regular and l 1 minus l 2 is nothing else, but the give the language under question. Here from this I will give you one important observation that is in general if you remove finitely many strings from a regular language that leaves a regular language. This property will be useful in several context because you see that you have come up with a language in which certain things are missing if the missing things from a known regular language. If what are the missing strings if they are finitely many then you can conclude that the given language is also regular. Now, I consider this construct that is reversal you know reverse of a string. Now, the property here is if l is regular then l power r that is defined by considering all those strings by reversing the strings of l l power r is equal to set of all x power r such that x is in l. So, take a string from l reverse it and put it in l power r. So, this is what is l power r and now I observe that if l is regular l power r is also regular. For this I require a small result that is for every regular language l there exist a finite automaton a with a single final state such that l of a is equal to l. So, here if you are considering a DFA what I will do if you are considering a DFA assume l of a is equal to l for l we construct suppose the DFA is like this certain states are there some initial state is there certain final states are there assume some n number of final states are there. Now, what I would say certain transitions here what I would suggest you consider a new state you consider a new state outside this state set of given DFA you make that as a final state and remove that they are final states you just make them as non final states just these are non final states whatever the final states that you have earlier in this. But, you put epsilon transitions from here to the new state epsilon transitions and you see any string that is accepted by a is the original DFA what is the situation any string if you put it in the initial state here it takes the transitions and finally, end up with a final state here. But, since there is an epsilon transition from each final state to this new final state the original final state to the new final state. Now, you understand that this particular string you know using this particular string from initial state to the final state you can always reach and when you can reach to this final state any string that is ending. If you put in the initial state ending in this state only you can reach to this new final state thus you can understand that this version of NFA can be constructed with unique final state and which precisely accepts the given language L that is now if you consider q sigma delta q naught F a DFA accepting L what do you do you set b to b q union singleton p a new state p and of course, the original alphabet transitions all the original transitions of the given DFA will be lying there in addition to that you take the transitions from the final states to the new final state. Because, this p is declared as new final state the original initial state is the initial state. So, this delta dash is defined as if this q is in the original state and a in sigma then as it is delta q a and if this q is in the final state. So, in addition to this transitions we are declaring that through epsilon transitions you will be reaching to the final state that is what is the construction I have shown. So, if you construct a finite automaton of course, this is an NFA then you can understand that this accepts the same language, but you have only one final state. So, now once you have this what you what I will do given a regular language L I consider finite automaton with unique final state. So, given L I consider a finite automaton with unique of course, initial state is always unique now I have only one final state. Now, you have certain transitions here you have certain transitions in this finite automaton a what I would suggest you now whenever you have an arrow in a for example, from p to q if you have an arrow under a you simply reverse this arrow in the new DFA. So, let me call this DFA to be say a r finite automaton let me let me not say it is a DFA because whatever that we have constructed with unique final state that is a non deterministic automaton NFA. So, what do you do you the final state of the finite automaton a you make this as initial state and the initial state of this you make that as a final state and whenever you have an arrow here from p to q you reverse that arrow that is all. So, the transitions will now flow back from final state to the initial state here thus in a power r you can understand that whatever is the string accepted in a it is reversal will be accepted in the new finite automaton because you know you take a string a 1 a 2 a n that you apply it in the initial state here you are reaching to the final state. Now, since arrows are reverse whatever the edges that you have here they are reverse you can understand that by applying that particular string the reversal of the string a 1 a 2 a n in this state you will come back to this you will come back to this state. So, now what do you do you give a formal construction. So, an exercise here is give a formal construction of a power r you see when I have demonstrated the idea that if a language is actually a DFA or you know finite automaton. So, for every regular language there is a finite automaton with unique initial state I have demonstrated like you have to construct this way and of course, here you have to observe that the language actually b is nothing else but l. So, this is a part of the exercises and now you have one more exercise first you give the formal construction whatever the idea I have explained here you give a formal construction here. So, of a power r and observe that and observe that this new automaton accepts precisely l power r. So, take this as an exercise and give a formal proof that if l is regular l power r is regular. Now, what are the properties so far we have discussed using this let me give you an example using all these properties we conclude that a particular language is regular is a very important language that you feel once I give this once I present this language consider the alphabet with 8 symbols say a naught to a 7 what are these symbols they are essentially the binary representation in this form of the numbers decimal numbers 0 to 7 that is a naught is triple 0 0 0 like this a 1 is 0 0 1 and so on a 7 is 1 1 1. So, you know now what is a naught what is a 1 and so on now a string over the sigma this alphabet is said to represent correct binary addition if correct binary addition if the first row I will say that is b i 1 dash b i 2 dash and so on b i n dash that is the first row of the of each symbol and plus second row of each symbol is equal to third row of each symbol because what are the string that you have considered a i 1 a i 2 a i n if you put them side by side the first row of each symbol plus the second row of each symbol if you consider those strings these are these are the binary numbers it should be equal to the third row of each symbol what are the string that you are getting for example, a 5 a 1 a 6 a 5 represents correct addition because this a 5 a 1 a 6 a 5 if you consider what do you have essentially let me write here 1 0 1 1 a 5 a 1 a 6 a 5 if you consider a 5 is essentially this 1 0 1 a 1 is 0 0 0 sorry this is 0 0 1 a 6 is 1 1 0 a 5 again is 1 0 1. We say this string represents correct addition because if you consider this first row that is 1 0 1 1 the second row that is 0 0 1 0 if you sum up these 2 you get this 1 1 0 1 and thus I say that this string a 5 a 1 a 6 a 5 over sigma represents correct addition. For example, if you take this a 5 a 0 a 6 a 5 if you put the symbol side by side and see the first row and second row if you take up the sum that is not equal to the third row and thus you see a 5 a 0 a 6 a 5 over this alphabet that does not represent correct addition. So, now you consider the language over sigma which contains all those strings that represent correct addition that is all those strings a i 1 a i 2 a i n over sigma star if you sum up the first row with the second row that should be equal to third row consider those strings we observe that it is regular that means essentially we are understanding that this binary addition you can represent a language of this form and we can see that particular language is regular. Now, if you remember we have constructed a millimission to perform the addition in which whatever the format that we have followed we are precisely adopting the same format here. Rather there you have considered a pair as input and you know the particular bit as output here the third bit is also included in the input and we have considered each symbol as a triplet and thus you have 8 symbols here. So, among this over this 8 symbols we have formulated the strings and we consider we consider only those strings which represents correct addition as defined here. Now, we observe that this particular language is regular you follow the same pattern as millimission for carries 0 state carry 1 state and you can observe very quickly that you can identify an NFA accepting this particular language. Let me present that here this is how the millimission we have constructed there only thing we have mentioned for example, here if you have 0 1 1 there we have mentioned 0 1 as input 1 as output because this is a carry 0 state and this is carry 1 state. And for example, here if you give 0 0 as input in the 0 carry state you will have 0 as output in case of millimission here we made it as a triplet because 0 0 0. So, for convenience I am writing this is horizontally 0 0 0, but you know the what is the symbol this is vertically we are writing in the bracket that 0 0 0. So, likewise here for each state I have only 4 symbols used for 0 carry state and 1 carry state. So, this among these symbols you know depending on the carry that if you add for the first 2 symbols the third symbol will be reflected as a third component of this triplet. And thus we have constructed here an NFA and now you can quickly understand by you know recollecting the construction of millimission are right here also. If you take the string like this a 5 a 1 a 6 a 5 what you are doing you are summing up these 2 and whatever is the corresponding symbol that is given as the third symbol here in the triplet. And if you have some carry here that carry will be considered while counting while summing up while summing up the components of the second symbol to look at the answer for the to look at the answer in the third component. For example, here 1 1 that is you see 1 1 when you are adding whatever is coming up, but what we have to look at here is when you are adding when you are adding these things because 1 0 1 1 and this is 0 0 1 0 when I am adding up this 1 0 that is 1 here when I am adding 1 1 here that is 1 0 here you have 0 as the you know result and, but you have 1 here as a carry. So, when you have 1 carry here so that is going that is changing the state there the input is 0 0, but you have 1 carry. So, the in the result it is reflecting 1 1 is reflected, but you look at when I am when I am giving the string a 5 a 1 a 6 a 5 I am not getting these transitions because these transitions are essentially carried from a 5 a 6 a 1 a 5 in this direction if you feed to the constructed n f a here then it represents the correct addition. Because you are adding from right to left not from left to right because the carry is important when you are coming from this side to this side in the usual way of adding to binary numbers. And thus you understand here whatever is the string accepted by this those symbols that you are adding component wise from right to left. And hence the strings which are accepted here is the elements of alpha aura and of course, since we made this initial state this initial state as vinyl state we have 1 more string that is empty string accepted by this, but what do we require we require reversals of the strings in alpha aura, but we do not want this epsilon as well. Now, what do you do you apply these properties this is the language accepted by this n f a and hence this language is regular you can safely remove finitely many strings from a regular language to observe the resultant language is regular that property we have observed. And thus what I would suggest first you remove this what is the resultant one that is alpha aura and from that property you say that l power r is regular. Now, since now since if x power r power r is x you know this property this is the property of reversals of the string you can understand that if you consider l power r power r because for each string again you take and obtain the reversal that is what is essentially l. And hence since l power r is regular its power that is l only where l is given precisely here. So, you conclude we can conclude that for l for this language we have a finite automaton and hence this language is regular see what are the properties so far we have discussed like reversal of a language is regular language is regular intersection and differences. So, this particular example has demonstrated some of the things and understand to understand that, but the language is looking little bit complicated, but you see applying these properties we can conclude applying this claudal properties we can conclude that the language is regular. Now, let me introduce one more that is right quotient this is new because so far whatever that we have discussed these are the all these things we have already defined earlier this operations. Now, this is a new operation that we introduce here that is right quotient between languages how do I define this let l 1 l 2 be two languages over sigma and alphabets right quotient of l 1 by l 2 we denoted by l 1 by l 2 is a language comprising all those strings x and sigma star such that there is y in l 2 such that x y is in l 1. That means, you see if you have any string x y in l 1 and there is a suffix in l 2 you can remove that suffix and the remaining thing you can put it in l 1 by l 2 that is how it is defined and this you can do it for any string and the resultant language you have to construct. Let us look at examples consider because this is a finite language. So, that you can understand the things very quickly consider l 1 to be this having four strings 1 2 a a b b a b a b a and in l 2 I simply considered a a b. If you want to have l 1 by l 2 what I have to do these two strings wherever that you get a subscript suffix those suffixes you remove and whatever the remaining prefix that you will be considering in l 1 by l 2 that is the definition. Now, you see a is suffix of this and this and the resultant strings now here it is this a for the first string a this is a suffix and the remaining prefix is epsilon and hence epsilon will be in l 1 by l 2 and a is suffix of this string also and if you remove this a the resultant string is b a b that will be in l 1 by l 2 similarly, if you look at a b a b is suffix for this for this these two strings and as this is suffix of this and the remaining prefix is epsilon. So, epsilon will go l 1 by l 2 already it is there and now for this string the remaining prefix is b. So, b will go in l 1 by l 2. So, l 1 by l 2 is now epsilon b a b and b. So, these three strings are there in l 1 by l 2 consider let me consider some infinite language in. So, l 3 is 1 0 star 1 given by this regular expression that means you know 1 0 star 1 means this is the for this regular expression the language is 1 0 power n 1 such that n greater than or equal to 0 and l 4 is considered to be 1 this is given as l 3 represented by this l 4 is given as 1 the regular expression that means this is singleton 1. Now, what is l 3 by l 4 suppose if 1 questions you consider all those strings which is having 1 as suffix in l 3 and remove that suffix and all the prefixes you collect. So, a general string is of this form 1 0 power n 1. So, in general for each string 1 is there as suffix and thus by removing that you get this is 1 0 star 1 0 star. Now, the question is now the question is is there any other string will come into the picture here since the regular expression this is 1 0 star 1 and the strings are typically of this form every string has 1 as suffix and only that suffix you can remove and the remaining strings are this 1 0 power n of course, for each n greater than or equal to 0 and hence you can conclude very quickly that l 3 by l 4 l 3 by l 4 is simply 1 0 star. Now, let me consider 1 more example consider l 5 to be 0 star 1 0 star. Now, if you consider l 5 by 0 star what is that as l 5 is given to be 0 star 1 0 star. Now, if you take the quotient with 0 star it is not that just it is not something like this do not get confused with this example that is in the previous example what has happened if you consider the regular expression 1 0 star 1 by 1 what we have got this is 1 0 star does not mean that we have cancelled this 1 1 and to obtain this this is not the situation. You cannot adopt the same to conclude here something like 0 star 1 0 star by 0 star by cancelling 0 star 0 star if you write 0 star 1 this is wrong what you have to do you consider from the definition you consider the strings in which 0 power n because 0 star is having 0 power n such that n greater than equal to 0. So, any string from this that is the typical of the form 0 power n which is having this as a subscript suffix and that particular suffix you remove and the resultant string that you take it in l 5 by 0 star. Now, you see for example, if you consider epsilon of course, for any string epsilon is suffix and all the strings are coming into the picture because of epsilon because l 5 by singleton epsilon if you look at all the strings are coming and even if you take say for example, single 0 you see here 0 star 1 0 star this is having you know all possible number of 0s as suffixes. So, that is 0 power m 1 say 0 power n such that m n independently greater than equal to 0. So, this is the language here since all possible number of suffixes of 0s are available you take anything the remaining string is of the form 0 power m 1 say 0 power n 1 where n 1 can assume any natural number and here you can observe that it is in fact, l 5 that is 0 star 1 0 star all strings will come in l 5 by 0 star and now if you consider 1 0 star of course, as you see in the arithmetic here you may feel it, but of course, you have to do that calculation and looking at the possible subscripts. Here this 1 will be helpful to understand that this is you know 0 star and now if you consider l 5 by 1 that is the language containing singleton 1 you understand that it is 0 star. So, this is the quotient the operation quotient between languages. Now, the result is if l is the regular language then so is l by l dash for any language l dash. So, that means, you quotient with any arbitrary language quotient of a regular language with respect to any arbitrary language is regular that is what we are proving here that is the result consider a regular language and an arbitrary language l dash what do you do? Since you have a since l is regular you have a d f a let me assume a to be the d f a here. Now, set a dash to be the same state set same in of course, alphabet is same and now you consider here l and l dash over the same alphabet sigma assume this way and now transitions are same initial state is same, but the final states we change it this way. Consider all those states in q by applying any string x in that particular state if you reach to a final state then you consider that state to be the new final state that is in f dash. You can quickly understand that this is a d f a and you can observe that this d f a accepts l by l dash. So, you can take this as an exercise take any string x that is in l of a dash and observe that this is in l by l dash. So, this is a formal proof to understand that l of a dash is l by l dash you can take this as an exercise and conclude that.