 We will continue our discussion on closure properties of regular languages. The first thing I would like to do is to once more review the result that we talked about in the last lecture, which is one of the results that regular languages are closed under operation you know reversal. And we will call by reversal we meant firstly we can talk of any string x and then we can talk of its reversal. So, for example, if the string is 0 0 1 then the reverse string is just writing the string the other way. And the reversal of a language L is all those x's such that reverse of x is in L. And we gave a very simple kind of example that suppose L had 0 0 and 1 1 0 then L reversal is going to be 0 0 and 0 1 1. And we also indicated we can prove this property that is regular languages are closed under reverses in two ways. One was taking a DFA for a regular language L and then reverse all its arrows the directions of the arrows in the transition diagram have a new initial state with epsilon transitions to the final old final states of the DFA that accepted that language L. And have a new final state as the old final old initial state of the DFA. So, that is something that we discussed. Now, another way we had proved it or we indicated that this result can be proved by using regular languages. So, the proof by regular expressions I would like to dwell on it for a little while because this proof idea is quite natural and simple. The step one in the proof was for every regular expression say e define e r called the reversal of e. Then step two was what we intend doing is the step two that if the language accepted by e is L this implies that the language sorry I should not have said accepted by language accepted by a regular expression or should have said the language denoted by the regular expression e supposing if it that language is L then the language denoted by e r which is defined in this in first step is the reversal of the language L. And what step one was was to define e r. So, that was a definition of e r step two we kind of very quickly indicated what we meant but let us now go over this once more. So, definition of e r look what we are trying to do is to give what is e r for every regular expression. You recall that whenever we talk of regular expression we keep some alphabet in mind. So, regular expressions over an alphabet. So, let us see the alphabet is some sigma and so this definition is for this alphabet sigma. And then the in this definition there is a base case this definition itself is an inductive definition. So, therefore, it has a base case and an induction case. So, base case was you recall what are the basis for regular expressions e over alphabet sigma there are three base cases. So, e can be in the base case either it can be m e or it can be epsilon or it can be a symbol a where a is in sigma. I put the underline here denote that these are regular expressions corresponding e r seem. Now, notice in step two I am supposed to prove this that if the language denoted by e is l then language denoted by e of r is l of r reversal of l. Now, what are the reverse what are the languages denoted by these three base case regular expression this of course, denotes the empty set this denotes just the language with the string denoting epsilon this denotes the language with just the string and consisting of a single symbol which is a. Now, such each of these languages on reversal clearly you will get back the same language and therefore, this is true this statement is true for the base case having defined e and e r for these base cases in this manner we can claim that this assertion is true for the base case. Now, let us take just one of the inductive part case and now remember once we have defined the base cases I need to say what about larger and larger regular expressions and you remember that any other regular expression could have been formed either by concatenation or by plus operation or by cleanies star star operation. So, you know inductive cases we had said that if e 1 and e 2 are regular expressions then e 1 plus e 2 e 1 e 2 and e 1 star all these are also regular expressions. Now, what we need to do in our attempt to prove this assertion having proved the base case now we have to say that suppose e 1 or e 2 are two regular expressions then inductively I can assume that regular expressions and now the assertion will say about e 1 r and e 2 r the following right we will say that language denoted by e 1 its reversal its language denoted by e 1 reversal. So, let us let us just spend one moment on this see from e 1 we obtain e 1 reversal this syntactically right by the rules that I discussed last time, but may be I will I will just discuss it once more here for one particular case and this is stating that inductively we can assume these two facts. So, let us just looking at that let us just take the how the induction inductive case will go for one interesting part of the three cases namely concatenation. So, we know that e 1 e 2 is a regular expression because e 1 is a regular expression and e 2 is a regular expression right now we defined remember that definition of e 1 e 2 this this regular expression its reversal was e 2 reversal followed by e 1 reversal and now this is how we had defined reversal for a concatenation case. Now inductively what we have what do I need to show now to show that the language denoted by e 1 e 2 reversal is the reversal of the language e 1 e 2 and now we use these two assumptions these two assumptions are from the fact that we are proving this inductively. So, we can assume given a larger regular expression having done carried out the induction so far that this assertion is true up to some length and let us see e 1 and e 2 their lengths are within that the standard induction that is you do on length of the regular expression. So, you see what is the language denoted by e 1 e 2 it is supposing I have a string in e 1 e 2 in this language then such a string is there in that language because that string can be seen as concatenation of two strings. So, as we are saying that suppose z is in this language language denoted by e 1 e 2 you can see this that clearly z is in the language denoted by the regular expression e 1 e 2 if and only if there are x and y such that x firstly that z is the concatenation of x and y and x is in the language denoted by e 1 e 2 and y is in the language denoted by e 2 clearly I mean that we know from our understanding of regular expression that when I concatenate two regular expression then this is what is the meaning of concatenation for regular expressions the language denoted by the concatenated regular expression can be seen in this manner and remember we need to prove this. So, what I need to show that z in L if and only if this if and only if I would like to show this if and only if the reversal of the language z r is in the language denoted by reverse of this, but by definition e 1 e 2 reversal of that as a regular expression this is our definition this is same as I can I can just look at that definition and now you can see I can replace this by e 2 r e 1 r right. Now by the way what is the definition this is z of r z of r is clearly z was x y. So, you must read it from this side y to x so y r x of r now because y is in L e 2 language denoted by e 2 y of r will be in the language denoted by e 2 r and x of r will be in the language denoted by e 1 of r. So, this is true and therefore, I can say this is proved for the other 2 cases for induction over regular expressions are star and of course, plus and these 2 cases are also in fact, plus is simpler star is also simpler than this. So, this is true and therefore, I can say this is proved for the other 2 cases for induction over regular expressions are star and of course, plus and these 2 cases are also in fact, plus is simpler star is also simpler than this. So, that completes the proof in detail that indeed. So, overall idea was that I wanted to prove this regular languages are closed under reversal. So, you take a regular language so let us say suppose L is regular and then because L is regular we can say let e be the regular expression such that language denoted by e is this language L. And then because of what we have shown we have essentially we have shown that language denoted by e r which is defined in this manner is going to be L r. So, you take a regular language its reversal is denoted by a regular expression. There is a regular expression which denotes the reversal language and every regular expression denotes only a regular language. So, this language L r is also therefore, regular and that is what we needed to prove. We have seen some closure properties for regular languages, but we still may need to like to answer this question that why study such closure properties. There are various reasons one reason is this suppose I have 2 classes let us say c 1 this is a class of languages by that now you know what we mean is c 1 is a set containing languages some languages. So, some class of languages c 1 and c 2 is another class of languages. Now, one big question is that these classes might have been defined some manner and we would like to know whether these 2 classes are same whether you know or not. So, one way of proving that they are not same is that that suppose I manage to show that c 1 is let us say c 1 is closed under an operation some let us say something let me just denote this operation like this and c 2 is not closed under the same operation. Then immediately I have that the 2 classes could not be identical. So, this is called separation of 2 classes c 1 and c 2 can be proved finding out an of some operation could be unary could be binary such that that one class is closed under that operation the other class is not closed under that operation. So, this is I can actually illustrate this that we have seen regular expressions are closed under complementation. So, c 1 if you take regular languages that class is closed under complementation and now some another class which we are going to study soon that is the class of context free languages this set consists of all languages which are context free that class will see that is not closed under complementation and that immediately tells us that these 2 classes are different. Of course, this is there are there are we will see you know in more direct manner that class of regular languages and class of context free languages are different. So, this is, but I just wanted to tell you this is one reason people study closure properties and for there are classes whose separation have been whose separation has been proved only using closure properties. Now, one more reason which we can see in our context quite easily that some proofs might be done simply using closure properties. So, let me let me give you an example consider this language L which is over the alphabet binary alphabet such that the number of 0s in x is different from the number of 1s. So, all those binary strings where when you count the number of 0s and number of 1s these two numbers become come out to be different. So, we are collecting all those strings and putting them in this language L and we would like to show L is not and one method we know of make providing such proofs is by pumping lemma. We can prove this through pumping lemma let me just indicate the proof by pumping lemma. Remember that pumping lemma proofs start with say it is a proof by contradiction we say let L be regular then we say let K be the pumping lemma constant and now the way with such proofs will go that I will take some z which is in L right whose length is greater than equal to K and get z 1 on pumping z such that z 1 is not in L it is not immediate at least all the other pumping lemma proofs we had seen things we are pretty clear what the z you should take and what is the pumping you should do so that you get a string in not in the language. Now here you can take z to be say 0 K 1 K factorial plus K you see it is not I will not give the details of the proof, but you should be able to see this you see what is happening is that now the u v part is here and it is the v part which we pump. So, v is some number which is between 1 and K that is your v all such numbers are divisible by K factorial right. So, what you can do so in fact let me let me let me indicate this. So, this 0 K is u v right u v let us say length of v is T right and now I can write this as 0 K minus T then 0 T this is your u v well there is something else here also u v 0 K is u v and some part of the v right. So, let me let me write it as 0 L u v served some part of the v and that part of the v which is in 0. So, part of the v this is this I write it as 0 K and now because this T is there which is the v part which you can pump you should be able to prove that you see for example, if you pump twice then what is the length of the string that will get the only 0's part it will be K plus T because you have pumped this part twice. So, this part will become 0 2 T so K plus T right. So, in this manner if you pump some R plus 1 times what you are going to get is some you can see that it will become K plus some R T and since T divides K factorial and this K part will cancel and therefore, I will be able to get a Z 1 which is not in the language because then the number of 0's will become exactly equal to this and leave the details. But the point I am trying to make is this is not a very immediate thing on the other hand. So, let me just show you a simpler proof using closure properties. Let me now give the simpler proof of this fact that this language L is not regular using closure properties. This proof also starts by assuming that L is regular. Now, we see then L complement is also regular. Now, how did I get this fact from this fact? Because regular languages are closed under complementation. So, therefore, L complement is also regular. However, what is L complement? You can see L complement will be the state of all strings in which number of 0's and number of 1's are equal. So, L complement is all strings over the binary alphabet such that number of 0's and number of 1's. So, this is L complement. Now, since L complement is regular, this implies L complement intersection 0 star 1 star is also regular. Remember 0 star 1 star is the talking of all strings which are of the form, some number of 0's followed by some number of 1's complement. Why can I why what is the reason I can claim this that L complement intersection 0 star 1 star is regular? L complement is regular, 0 star 1 star is this language is also regular, regular languages are closed under intersection. So, therefore, this language is regular. But what is this language L complement intersection 0 star 1 star? This language is nothing but 0 n 1 n and do you see the contradiction? Because this is a very simple language to prove that this is not regular. You can see we know this language L complement intersection 0 star 1 star is not regular and therefore, we have come to a contradiction. Why because I started with a regular language L and we did some closure properties operations, operations which preserve regularity and we got a language which is not regular which means our assumption must be wrong and therefore, I claim therefore, L is not regular. See here I got a contradiction therefore, L is not regular. So, you will definitely see that this proof is much simpler than directly applying the pumping level. Firstly, how does one figure out such a string? You have kind of rack your brains to find such a string and then we need to you know argue once of course, we found that string then that argument was also little involved, but here the all the arguments are much simpler because we use closure property. You recall we have four different representations for regular languages. What are they? We can represent D F A's. This is one way of representing regular languages N F A's then you have N F A's with epsilon transitions. The point I am saying that you can take a regular language L. I can represent that regular language by providing a D F A that would accept that regular language and N F A which would accept the same regular language. Possibly an N F A with epsilon transition or the same regular language and of course, I can give a regular expression which will denote the same language. Now, what we are interested in is in knowing can I go from one representation to another and what is the time complexity? How efficiently can I do these things? Now, by the way D F A to N F A, D F A to N F A with epsilon transitions. These are immediate right because all after all every D F A is an N F A and why? We have said this N F A says simply that from every state there can be zero or more number of transitions on a symbol. D F A just uses one transition per symbol from a state exactly one transition. So, that is fine. The D F A is also an N F A. N F A is also an N F A with epsilon transitions. So, these conversions D F A to N F A, D F A to N F A with epsilon transitions or N F A's to N F A's with epsilon transitions. They are not of interest because one is a more generalized version of the other. N F A is a more generalized version of D F A, N F A's with epsilon transitions is a more generalized version of N F A's. So, that is these this way it is simple. But what about going from N F A to N F A to D F A? We know the construction and we also know that if there can be N F A's such that let me write it down. There can be N F A's with N states such that any D F A accepting or let me just use the Q L and D F A you understand what I mean any Q L and D F A that means that new D F A has accept the same language as the N F A. So, they can be what I am saying is they can be N F A's with N states such that any Q L and D F A will have at least 2 to the power N states and we have seen an example like let us say kth bit from the right end is 1 for binary strings. You recall that example N F A had you know not too many states but the corresponding D F A at 2 to the power N states. And this is happening again because of the subset construction going from D F A to N F A. We recall that our way of doing that was the D F A will have the number of the set of states of D F A will be set of all subset of states of N F A. So, that way if there is an exponential blow up as you go from N F A to D F A they can be such exponential blow up in general. So, this is an exponential algorithm that is cannot do better than that because of this fact. What about going from N F A's with epsilon transitions to D F A's is the only different thing between N F A's and N F A's with epsilon transitions is that we need to take closure of states or set of states. The closure is not an expensive operation however because anyway we are going from N F A. So, in this case also that subset constructions will be there on top of that there will be that closure operation but closure operation is efficient because it is kind of reachability. Closure of a state is the set of all states reachable from that state using only epsilon transitions. So, reachability can be done in efficient time and therefore, this also however because we are going from N F A to D F A the number of states can blow up. So, this is again exponential time. What about regular expression to D F A? This actually we what we did was what we had proved was this that you can go from a regular expression we can get an N F A and that can be done quite efficiently. Recall that inductive proof that we gave that we gave N F A's for you know base cases of regular expressions and then we showed for the inductive cases how the N F A's will be built up from the component N F A's of the smaller regular expression. So, this can be done efficiently. So, in fact in linear time but let me just write this conversion can be done in polynomial time can be done efficiently. Now, remember we have also discussed going from D F A to regular expressions and same idea can be can be used for N F A's to regular expression or N F A's to epsilon N F A's with epsilon transitions to regular expression. What about this algorithm? Remember what we did was we took a D F A and then we wrote a number of regular expressions which are of this kind that if the D F A was Q sigma delta Q 0 F and I will just indicate just so that you remember what we did that we took the set of states as Q 1 Q 2 Q n and we define regular expressions of this form R i j k to be denoting all those strings over sigma which can take the machine m from Q i to Q j without passing through any states whose you know this this number whose number is larger than k. We build this thing and then finally when we got R i j n using some of those R i j n's we define we got the regular expression which denotes the same language as the language accepted by N and what did we do? We obtained R i j k's from R i j k minus 1's and here if you go back to that proof the length of R i j k length can increase by a factor of 4 because let me just write it an R i j k was defined to be firstly R i j k minus 1 the regular expression for this plus R i k k minus 1 R k k minus 1 this whole then R k j k minus 1. You see if the regular expressions with superscript k minus 1's we had then we could build the regular expressions with superscript k but in the process 1 2 3 4 such things we are using so in this definition the length can increase by a factor of 4. And so therefore see what happens is as you go from here to here how many times this factor of 4 increase happens as many times there are number of states. So you have a 4 to the power n order algorithm. So this is we cannot do anything better going from DFA to regular expression or from NFA to regular expression there can be a blow up of exponential blow up in the length of the expression and therefore the algorithm is exponential.