 First, we see today a few more closure properties of the class of context free languages, one operation which is called the string homomorphism. Now, this considers two alphabet, let us say sigma and gamma and string homomorphism is a map from sigma to gamma star. So, what it means is for example, your sigma is let us say 0 1 and gamma this alphabet is a b c. So, this is a map which is assigning a string of over gamma to every symbol of sigma. So, it could be that h of 0 for example, is a b c and h of 1 is let us say b b. Now, this h clearly extends to strings of sigma star to strings of gamma star. So, what we mean is that suppose I have this string 0 1 0. So, what we will do is we will apply this map h individually to each of the symbols in the string. So, to get a new string over gamma. So, h of 0, h of 1, h of 0 and these three strings are concatenated. So, in other words by definition what we mean is. So, this extended thing if I call it h dash which is a map from sigma star to gamma star. In this case is h of 0 concatenated with h of 1 followed by h of 0 because these are the three symbols each symbol individually we are applying the map h. For this example what we have h of 0 is a b c. Then h of 1 is b b then again a b c. So, clearly this map h dash h dash will map a language over sigma to a language over this other alphabet gamma. In a very natural way that is. So, in fact we can write this h of h dash of l is the set of all h dash of w such that w is in l. So, you can see h dash of l will be a language in language over the alphabet gamma. So, the closure properties is that if l is a CFL is a context free language and h is a map from sigma to gamma star and I should have said h if l in sigma star is subset of sigma star. So, that means the alphabet of l is sigma and h is a map from sigma to gamma star that is h is a string homomorphism. Then h dash of l the way we have defined h dash is also a CFL. So, one way of saying this is that this operation of taking a language applying h dash to it it is a unary operation. So, this operation does not take a context free language to a non context free language. Therefore, we say that any context free language or the class of context free languages is closed under this operation which is known as the homomorphism or string homomorphism. Now, this is actually fairly simple to prove why because you see l is a CFL. So, let us say g generates l and g is v sigma and now what we can do is we can consider another grammar g dash which is as follows we will say that this grammar g will have also these terminal symbols that is the symbols of sigma as non terminals. So, what would that mean? That means our non terminal for g dash is union sigma there is no problem in doing this and my terminal symbols because we are going to generate this language we are going to give a grammar which will generate h dash l. So, here of course it will be gamma the alphabet of this language l h dash l is gamma. So, therefore, the terminal symbol is gamma p dash and s. So, p dash is what we are going to do the idea is very simple first use the these productions p to generate a string from s that string will be over sigma. So, basically generate a string of l all right. So, from s we generate a string let us say w of in sigma star, but then sigma star is no longer or the alphabet sigma is no longer the these are not terminals anymore these are non terminals right. So, we just add these productions let us say for a in sigma at the production a goes to h of a right for each a in sigma we add these productions and. So, your new p dash this is fairly now simple to see what we are trying to do new p dash is old p plus the all how many productions are there is as many as we have symbols in sigma. So, for each symbol which is now a non terminal each symbol of sigma is now a non terminal of this grammar g dash and you can rewrite that with h of a which is a string over comma. So, what is going to happen the essential idea is that from s you will generate a string over sigma and now for every. So, let us say this is a this is b. So, here we will use the production h of a and so on h of b right and then you are going to get a string over this alphabet now clearly it is very easy to see the grammar that we have described this g dash is going to generate h dash l. And since this is a context free grammar therefore, h dash l is also a context free language. So, therefore it is very simple to see that if l is a context free language then h dash l is also a context free language which is what we needed to prove using very similar idea actually we can do something another closure property which is somewhat more general and let me explain that property and that property is called or that closure property or that operation is called that of substitution. Now, next property that we look at is substitution in case of substitution what we have is again two alphabet one is sigma the other is gamma and now let us see we have a language l over sigma right and what we do we associate a language over gamma for every symbol in sigma. So, let me write it down for every symbol a in sigma we associate a language let me call it a l a. So, for every symbol a we associate a language a l a over this other alphabet now you see in the same manner now we can take a string over sigma. So, let me again give an example. So, let us say sigma is 0 1 and now we so l 0 this language let me write it as a n b n and l 1 let me write it as a n b n. So, what I mean is this is n greater than 1 this is one language and this is the other language or let me just to make it point I am going to make I will say little later. So, m is greater than 1 n is greater than 1. So, we have these two languages l 0 and l 1 now the substitution a substitution essentially tells you first of all that this association of every symbol of sigma is associated with a language over gamma right. Now, so let me call such a substitution as s this particular substitution as s and now you see what we can do is if I if you take a string let us say a 1 a 2 a n right where each a i is an element of sigma in our case it is 0 1 that we said then I can get this actually defines a language how this is this set w 1 w 2 w n concatenation now these w's are strings whereas, these a's were symbols over sigma such that w i is an element of the language associated with the corresponding symbol. So, remember the way we associated we said a i is a i is some particular symbol. So, that there is some language associated with it and that is a l i that is the thing that we are saying. So, now what we have is I get a new string, but it is not just a string. So, here I can I could substitute for w i any string from this language. So, that is why it is a this this substitution of a string is now a language and substitution operation when I do this for a language l what is going what is it going to be it is going to be the union of in all these right. So, this remember this going to give me a set a language. So, it is to talk of this and what we are saying is that a 1 a 2 a m this string is an element of the language. So, essentially what we are doing is that for every string of the language l right on substitution I get a language and then we take the union of this language. So, now basically our theorem is that suppose for alphabet sigma l a is a context free language what is l a for each a in sigma. In other words what we are saying that suppose for every symbol in sigma the language that the substitution associates with that symbol is a context free language under substitution s. Then if l over sigma star is a c f l then so is see remember again that like string homomorphism substitution also is an operator which takes a language and provides and you know returns another language right. And what we have said or we are trying to assert in this that if each language that we associate with a symbol under the substitution operator s that you have defined is a c f l. And then you apply the substitution to a c f l l then s of l also is going to be a context free language you know it all this definition took a long time to explain. But the proof is again very simple and in this in the manners very similar to the string homomorphism case. So, now instead of saying you know previously what we did in case of string homomorphism that we just considered that elements of sigma to be part of the non-terminal set for the language which was going to generate the language which we obtain under string homomorphism. Here they will be the for every such symbol we will instead of generating a string we can what we can do is that we think of a generating a string for but where in that string for a we have the start symbol of let us say s of l a. So, let us say there is a grammar which since it the grammar is c f l for you know l a l a we said is a c f l. So, there is a start symbol for l a. So, let me just denote it as start symbol of l a and this was the association right. What we are saying that generate a string which will generate you know you start the derivation of l and then when you finish that derivation instead of getting a string over sigma you get a string over corresponding start symbols. And then use those start symbols start derivations from those start symbols using the grammars of l a etcetera to generate the other string this is a very simple idea and this is going to work. Now, what I can show you that once we understand this that substitution preserves context freeness this operation does not take the class of context free languages to anything else. Then certain things like all those concatenation union which we proved those operations to be for those operations the class was closed under the context free languages. For example, let us take this case we proved that if l 1 l 2 are c f l then so is l 1 union l 2 right this is one result that we had you know this you can prove very simply using this substitution idea consider a language very trivial language which is consist of two just these two strings a and b. So, therefore, this language l clearly is a subset of a b star that is okay, but this is a very trivial language this language l has just two strings a and b. And now what you say l a is the this symbol a the language you associate with l a is let us say l 1 and l b the language you associate. So, let me just say this s of l a is l 1 s of l b is l 2. And now it is easy to see s of this language is nothing but l a union l b which is nothing but l 1 union l 2. So, in the same manner we can show just using substitution that context free languages are closed under concatenation for example, or even cleanies star. So, all those things really follow from can follow from though we had proved them individually we can also see them as corollaries of this particular state a theorem that context free languages the class of context free languages is closed under substitute. We had proved that context free language class is not closed under concatenation. This means that it is possible that l is a CFL, but l complement is not a CFL. And also the other way similarly it is possible l complement is not a CFL or l is not a CFL l complement is then it would be nice to get examples of such pairs of languages that one is of that pair that pair is a language and its complement one is a CFL the other is not a CFL. And in fact the very first language that we had taken as the example of a language which is not a CFL what was that we said this language a n b n c n n greater than equal to 1 we know l is this l is not a CFL. We had proved this using you know quite simply our pumping lemma that we had proved and we know that this language is not a CFL, but what we can show that l complement however is a CFL. Now what is l complement if you see that l complement is really the union of two sets one is we can say l complement is l 1 union l 2 where l 1 is all those w's over this alphabet l 1 plus l 2 plus l 2 a b c such that w is not of the form a i b j c here we are not insisting that the i j k could be anything, but essentially this is not of that form. And what is l 2? l 2 is a i b j c k where either i is not equal to j or j is not equal to k. This is not too difficult to see. So you see something may not belong to this language because for a reason that it is something like let us say you know this string b b a a a b you know something like this. So in this kind of strings all a's will precede all b's and they will precede all c's. They come in a's then b's then c's will come, but if that order is destroyed then you get some string. So clearly that is that cannot be in the language l. So these are the kinds of strings which we you know these are the strings which form the language l 1. Now can you see that l 1 is a regular language claim l 1 is regular. Why? Because the complement of l 1 now l 1 complement is what? W is of the form a i b j c k, but that can be checked by a finite automaton that first all a's then all b's then all c's. And so complement of l 1 is regular therefore l 1 is regular because regular languages are closed under complementation. So therefore l 1 is a c f l claim 1. Now claim 2 and this is where the main part of our work is there is that l 2 is a c f l. Now since l complement is the union of l 1 and l 2 and once we also have we have these 2 claims claim 1 and claim 2 both l 1 and l 2 are context free languages. So remember that context free languages this class is closed under union. So therefore if both of them are context free languages then it has to be also context free language. So that is the idea behind this proof and I kind of give you the reason why claim 1 is true which you can convince yourself off. So let us try to prove that claim 2 which is that this language l 2 which is of the form a i b j c k where either i is not equal to j or j is not equal to k. This language is a c f l further what is l 2 I can take l 2 as 2 again you know I can say that l 2 is union of 2 languages l 2 1 or let me say it l 3 union l 4 what is l 3 l 3 is a i b j c k such that i is not equal to j and l 4 is a i b j c k such that j is not equal to k. You can easily see that l 2 is the union of these 2 languages. So because every string in l 2 satisfies either this property or this property. So separately we are considering these 2 properties and then taking their union these languages therefore I am getting the language l 2. What we will show individually that both l 3 and l 4 each of them they are each of them is context free language and you can see that if I show for example l 3 is context free in the same way we would be able to show l 4 is also context free. So let us try to prove that l 3 is a context free language. We are trying to prove this claim that this language l 3 a i b j c k where i is not equal to j but you recall that we want i j k to be greater than equal to 1. So I am adding that also. This language is a c f l. Now again you see l 3 now is the union of 2 other languages l 4 union l 5 where l 4 is a i b j c k such that i is not equal to j. i is strictly greater than j and i j k greater than equal to 1 and l 5 a i b j c k i is strictly less than j and again i j k is greater than equal to 1. Now further claim what we can claim is that and we can prove this that l 4 and l 5 are context free languages. You see how we are making use of the closure property. Suppose I manage to show l 4 and l 5 are context free languages that is we prove this claim. Then what do I have that l 3 is also a context free language because it is a union of 2 context free languages. In a similar manner I can show that l 4 I am sorry I mean I used up l 4 here. So l 4 is maybe then I should use l 5 l 6. So this is l 5 and this is l 6 and then l 5 and l 6. So anyway the idea is very simple that l 5 and l 6 are context free languages. We need to prove this but suppose we have done it already. In that case l 3 will become a context free language because this is the union of 2 context free languages. So l 3 is a context free language. In the same manner very similarly you see l 4 is very similar to l 3 and l 2 is the union of 2 context free languages. After we manage to show l 3 is context free as well as l 4 is context free then l 2 is a context free language. But what is l 1? We said l 1 is regular therefore l 1 is a context free language. So we have proved l 1 and l 2 they are context free languages. Their union is l complement. So therefore l complement is also a context free language and that settles our goal to show that l complement is a context free language. This is one way of making use of closure properties of languages. Here we are using them to show that something is context free language and similarly you can sometimes use closure properties to show that something is not a context free language. But that example we have not seen yet. Let us just work on this. You will agree that if I can show you that how we can generate l 5 by a context free grammar thereby proving that l 5 is a context free language very similarly you can show that there is a context free grammar for l 6 also. And then of course we will be able to prove that l 3 is context free language. So let us see what is c f g for l 5. So what is l 5? Think of a typical string of l 5. So you know it is number of a's is strictly more than number of b's. So something let us say a a a a a b b and then you have some c's. You do not care actually about how many c's you have. The number of c's so long it is greater than or equal to 1. So you see suppose what I have I have a start string s and this sorry start symbol s for the grammar for l 5 and then let me use let us say x and then capital C. So the role of this capital C is to generate a string of c's one or more c's. So that is very easy to do right. So c is either small c capital C or simply small c. So you know this is going to generate any number of c's at least one or more number of c's. So that takes care of this. With x I would like to generate this part of the string. What is that part of the string? That is it has number of a's followed by number of b's but the number of a's is strictly more than number of b's. So like in this case. But here what you can see is that you see there will be some number of a's then equal number of a n b n and this number of a's will be this is some other a n where n n are greater than 1. This language captures strings of this kind where the number of a's will be strictly more than the number of b's and this is fairly easy to generate right. We know. So basically x should generate strings over this language. So what we are going to what we can do? I can write x as y followed by z. What is the role of y to generate this initial part of a's? So y is again very simple. A y followed by a's. So it will generate one a or any number of a's. And what is z? z we should generate equal number of a's followed by equal number of b's. Number of a's followed by equal number of b's. Again we know how to do that right. So we can say a's z b's. So I can claim that this grammar which consists of start symbol and these non-terminals x, c, y, z and the terminals are a's, b's and c's right. So in fact let me clean it up and clean this what I am making. So let me say this is my set of productions and let me just rewrite it here so that they are all in one place. This is p and your grammar is therefore s, x, y, z, c. These are your non-terminals. Your terminals is of course a, b, c. This is the set of terminals. This is your set of productions p and of course the start symbol is s. This grammar generates L5 and if you are convinced that this grammar generates L5 then on your own it would be very easy to write a grammar for L6. So that proves this claim that L5 and L6 are context-free languages. Since L5 and L6 their union is L3 and each is a context-free language. So therefore L3 is a context-free language and in a similar manner we can prove that L4 is also a context-free language. Now L2 was L3 union L4 so L2 is a context-free language. So this claim is also there. Claim 1 was already you know we argued. So L complement is L1 union L2. Each one is a context-free language. So L complement is a context-free language. So what we have finally managed to show that L complement is a context-free language. So what is the point that I have a language L which is a, n, b, n, c, n. N is greater than equal to 1. This set of strings that was not a context-free language but its complement that language's complement is L complement which is we managed to show that it is a CFL. So here is a pair of languages. One is a CFL its complement is not a CFL. In this manner you know this is something very different. This behavior is very different from regular languages because regular languages are closed under complementation. If some language L is regular then L complement is also regular. But here since these languages, this class of context-free languages, this class is not closed under complementation, we have such a possibility. Having a pair of languages, one is a complement of the other. One is a CFL, the other is not. You know some, I think not in the last class, maybe the class before that, we tried to informally say what kinds of things are, what kinds of languages are context-free what are not by looking at some examples after we had proved the pumping lemma. And for example, I will elaborate that a little bit, that point. See consider this language L, W, W, R where W is a string over 0, 1 and by W, R, 1 just means the same string reversed. So, if W is suppose W is 0, 0, 1, 1, 0 then W, R is reverse. So, you start from here 0, 1, 1, 0, 0. What we said or what we are trying to say those, the language which consists of two strings such that one is the reversal of the other, then this language is a CFL, L is a CFL. Then you can prove it easily, I think we even wrote a grammar for it, but you see what is happening. So, you know, so let us just take this, this is W, R. So, this is W and this is W, R, 0, 1, 1, 0, 0. Now, there is a correspondence, what is the correspondence between, I mean pairs of symbols. This corresponds to, so this and this has to be same, is not it? Because you know W, you have reversed it. So, the first symbol of W becomes the last symbol of W, R. Similarly, second symbol of W is the second symbol of W, R and so on. So, do you see these symbols kind of correspond and in this correspond means here we are saying that they are same, it could have been different also, that is not the point. But the point is, you see these correspondences, the pairs of symbol which correspond, they nest, this is called a nesting, that this encloses, this encloses, this, this. I am saying this informally, but you understand nesting, might have come across in some other context. So, context free languages are very good in taking care of nestings, correspondences which are basically nestings that can be taken care of. Now, you see informally why A n, B n, C n is not a CFL. So, we can say this corresponds to this, of course this corresponds to this, this corresponds to this. We also wanted to say things like that let us say that this corresponds to let us say, suppose we say this, we know we are trying to nest. So, but you see these two nestings are kind of flashing, this is something we cannot take care of in context free languages. So, on the other hand if I had just one set of nestings, which we can take care of. So, this very something looks very similar, but yet it is not a context free language which is the following language. So, what we are saying that this language L consists of two strings. So, basically one string W followed by the same string W, you can take any binary string write it twice, you will get a member of the language L. Now, let me call it L 1, L 1 is not a CFL. Now we can prove this very simply by using pumping lemma, that suppose your pumping lemma constant for this language was k, then consider the string a k, b k, a k, b k and you will get a contradiction. So, it is easy to show this L 1 is not a CFL, of course we know L, L is a CFL and now in fact this L 1 gives another example that L 1 is not a CFL, however L 1 complement is a CFL and this is this is a this proof is quite interesting, which that is why I thought proof that L 1 complement is not a CFL, we would like to see this. What I am going to show which is slightly different from this language, but you will be able to show that we can take care of L 1 complement once we take care of that language. So, let me just say L 2 is this language x, y such that length of x is equal to length of y y such that length of x is equal to length of y and x is not equal to y. So, essentially L 2 is a set of strings, they have length even such that the first half is different from the second half, today we are running out of time. So, we will just claim or state what the proof that we are going to show in the beginning of the next class that L 2 is a CFL and you see my point is because L 2 is a CFL, then you will be able to prove that L 1 complement is also a CFL. However, this proving that L 2 is a CFL is quite interesting, which is what we are going to do in the next class.