 We will complete the proof of the pumping lemma for context free languages. Recall the statement of the lemma. Basically, it says that suppose L is a context free language, then there is a constant n which depends only on the language L such that for all strings z in L such that the lengths of these strings are greater than equal to n, you should be able to break up this z in five parts u v w x y such that both v and x cannot be empty. In other words, length of the string v x that is greater than equal to 1, length of v w x all together is less than equal to n where this n is the pumping lemma constant for the language L and then the pumping condition that for all i greater than equal to 0 that u v to the power i that means i copies of v followed by w followed by i copies of x followed by y, this string is also in the same language L. Last time we really completed the main crux of the proof which is showing how this condition 3 we managed to obtain for a certain break up u v w x y. What was left was to show that this condition 2 that is the length of v and x is greater than equal to 1 and v w x together their lengths all I mean the concatenation of v w x the length of that string is less than equal to n. This particular part was left otherwise we had completed the proof. Let us complete the proof by showing that the proof that we gave it is such that that this condition 2 will also hold. Now, very briefly what we did was first of all we started with the assumption of course that is given that L is a context free language and therefore, we said that let G be a Chomsky normal from grammar for L. Then we said that let G has or let G this grammar G let it have m non-terminals. Next what we did was using this value of m which is the number of non-terminals of the context free of the Chomsky normal from grammar G of the language L we defined for us the pumping lemma constant we said let n be 2 to the power n. Then we said consider any string whose in the language Z whose length is greater than this number. So, we said that let and then we considered the derivation tree for such a string Z and Z is greater than equal to n remember n is to power n. Then we said look at the longest path in this derivation tree. Now, we proved a small fact which showed that this path this path longest path length is at least m plus 1. So, once I have the longest path in the tree starting from the root node which is the start symbol S and of course, going to a leaf node which is labeled with a terminal. We know that this path has length at least m plus 1 we proved this fact. Then what we did was we started going up from in this you know we started from here the end of this path and going up till we found a non-terminal which got repeated. And again we argued that this case must happen that is a non-terminal must repeat further more the argument that we gave also clearly showed that by the time you move up m plus 1 edges one non-terminal must repeat. So, this length of this path you cannot be any more than m plus 1. So, is this clear what I am saying is that we started from this point first of all we said look at the longest path. This path of course, has to be of length itself greater than equal to m plus 1, but it could be in general much larger than m plus 1 because you know your z can be very large and then you are considering the longest path. But now you are going up from the bottom of this path till you find the first non-terminal which has occurred earlier in the path as you go from below. And the reason that we gave some kind of pigeonhole principle argument that this repeat must occur by the time this path is of length m plus 1 or less. And then we said that look remember we said that suppose this particular a derives this part of the string and this second a derives this part of the string and this part we identified as w this part we said is v this part is u this part is x and this part was y. So, this is how you would break up the string will it is clear that s of course, derived the whole string z which is u v w x y further a derives this string v w x first of all I can see that a derives this part a derives this w part. So, a derives w and if you if you think in this manner the derivation tree of a is you think of this. So, it is generating you know we argued all this last time that a I can see to be deriving also v a x. And now it is easy to see and this see this fact is very clear from the diagram itself. And now it is very easy to see suppose this condition is not true that means length of v x is 0 you know it has to be something length cannot be anything other than any anything negative. So, if it is not greater than equal to 1 then this v x length is 0 which means both the strings v and x is empty. So, what it means is if v x length is equal to 0 then this of course, implies both v and x are empty. And in that case this particular derivation would mean that a derives a. But that is not possible because the grammar is a Chomsky normal form grammar remember for this to happen we need to have either epsilon productions or unit productions or both. I mean either some unit productions such that a derives a or you know some epsilon productions such that some non terminals get rewritten as epsilon and starting from a we get only a back. But these cases are not there because our grammar is Chomsky normal form grammar. So, if we assume that both v and x they are empty then we get a contradiction because that cannot happens as the grammar is Chomsky normal form grammar. So, therefore, we say that we can see that this condition therefore, must hold. And the other condition is what we said that length of v w x is less than equal to n. But what is v w x now you what is v w x is derived by a. And this is the derivation tree this part is the derivation tree for v w x in that the longest path is the path from here to this see that is clear is not it because here they cannot be any longer any path which is longer than this. Because then the original path which we which we said is this is the longest path that could not have been the longest path in the big tree. So, this is the as larger path as possible in this derivation tree. And we know that is how we are good that this path length is is no more than m plus 1 see let us not get confused by this statement this was about the overall tree. And then when we what we said was that we are going down from here up and by the time we go up it no more than by the time we get no more than m plus 1 edges one non-terminal must repeat. So, we are waiting till the first non-terminal. So, this path length. So, how shall I write it. So, let us just say this path is theta. So, length of theta is less than equal to m plus 1 and theta is the longest path in the this derivation tree starting from it. That means what we go back to our old fact that suppose I have a derivation tree where no path is greater than m plus 1. Then the string that is generated cannot be of length greater than 2 to the power m plus 1 minus 1 which is equal to 2 to the power m which is of course equal to the pumping lemma constant. So, let me write it. So, that is clear length of theta is m plus 1. So, the string V W X cannot be of length greater than this which is equal to 2 to the power m which is equal to n where n is the pumping lemma constant. So, we have said the length of the string V W X cannot be greater than cannot be of length greater than this strictly greater than this. Therefore, length is less than equal to n and that is the other condition. So, we have proved this also and this and therefore the proof of the lemma is complete. This is something we must appreciate and this kind of thing was there for our pumping lemma for regular languages as well. What we are saying is that this lemma conditions they are necessary but not sufficient to prove a language to be context free. In other words that suppose you find the language L which satisfies all these from there you cannot conclude that the languages context free. In other words what does it mean that it is possible that some non context free languages also to satisfy all these conditions that is what we mean when we see that these conditions are necessary. In other words of course as the lemma states every context free language L they will satisfy these pumping lemma conditions but the other way is not true just because for a language all these conditions hold you cannot conclude the language that language L to be context free. In fact, so let me make this point once more that what it means is that it is not always possible to make use of this lemma to prove a non context free language not to be context free. So, such an example let me give right away is a well known example L 1 is a i p j d L such that either i equal to 0 or j is equal to k is equal to L. So, what it means is that when you know firstly this language L 1 has a string of a is followed by b is followed by c is followed by d is where either there are no a's or if you have a number of a's then it must be the case that the number of b's is equal to the number of c's equal to the number of b's. Now this language is not a context free language but you see that it will satisfy all these conditions. Why see suppose see there are two cases either i equal to 0 then there is no really restriction on j k L right. So, basically we have a consider a string like b j c k d L and let us see the entire v w x part occurs within b and then you pump. So, number of b's go up or 1 b goes down that is ok right this is still in that form because we cannot add any a's in front by pumping up or down right. So, will remain within the language L on the other hand suppose I have some a's followed by b's. So, let us say this is I know R then it must be the case if since I have number of a's C R and D R these number of occurrences of b must be equal to number of occurrences of c's and as well as for d's. Now again it is possible if you take such a string from the language then your v w x can very well be within this right. You can choose your u v w x y is such that that v w x part entirely is within a's. So, when you pump up or down all that happens is that you change the number of a's number of b's c's and d's do not change. And therefore, on pumping the string that you would get will be also in the same language L 1. So, the point I am making is that this is a language L 1 which satisfies the conditions of the pumping lemma and yet L 1 is not a context free language. So, let me write it down L 1 satisfies the conditions of the lemma, but is not a context free and we will be able to prove that this language L 1 is not context free language by some other means, but not by using this form of pumping lemma. There are stronger forms of pumping lemma in particular one stronger form which you can use which is fairly well known and used is called Ogden's lemma is a stronger, but we will not discuss Ogden's lemma here or there are other versions even Ogden's lemma will not be able to prove some languages to be context free. Then in fact, we gave one reference while discussing with discussing for regular languages and that reference that paper contains the most general form of pumping lemma for context free languages. Here are some examples some more examples of languages which are not context free and all these three languages you can prove that they are not context free, but by using the pumping lemma that we have seen. Now, just a little discussion on the form of these kinds of languages and at least intuitively we should be able to appreciate certain things or certain properties which context free language cannot ensure. See here what is happening? There are three strings a, b and c. What you want is first of all that b and c they must be equal in length and length of a is less than equal to length of either of this. Now, if you if you let us remove this then it will be a context free language, but adding this is the problem. See what you will see later when we discuss the machine version that it is easy to ensure this or this, but together it will not be easy for a context. It will not be possible to ensure both these constraints at the same time. These are intuitively I am trying to explain to you and similarly if this is not there this condition of course, we can ensure we can write a context free grammar which will generate this language b and c and such that n is greater than equal to 1 there is no m. But together both these conditions we cannot handle using the context free nature of the grammar that we have. Take another kind of thing similar things you see again there are these two condition business that i is less than equal to j and j is less than equal to k. The problem is the once you ensure this again you see this one of these was not there either a or you know this or either of this letters then again we can ensure that by means of a context free language. In other words supposing a was not there b j c k such that j is less than equal to k this is something we can handle we can we can write a c f g context free grammar to generate such strings, but these two conditions together we cannot handle. Now another version of the same two condition business is now I should say that you should also realize in fact let me let me let me say what I want to say after I discuss this. What is this again I have two conditions right that number of a's must be equal to number of c's and number of b's must be equal to number of b's two conditions. Again we this is something we cannot take care again if you look at pumping lemma y that is the case where is you know you can say pumping lemma constant is let us say k then you take a string a k b k c k d k right. And then what happens is that the window v w x will be either in entirely within one of these you know letters strings of one letter like entirely within a's or b's or c's or d's or can straddle two consecutive ones. So what will happen is it will change the lengths of two consecutive ones at most, but you know here we need to make sure that the lengths of the first and the third they are they match and that is where the problem will happen. The same way that we had proved for you know that language a n b n c n not to be context free language the same kind of proof will idea will go through here too. But you know I am somewhat incorrect by saying that we cannot handle two conditions we can handle two conditions so long they are not kind of intermixed or together. So for example if you if you take another language l 5 let us say I write it slightly differently a m b m c n d n this is context free right how will you do that remember I can separately generate this from some s 1 separately generate this and this these are just the two concatenations in other words what will be that grammar. So we can start with s s goes to s 1 s 2 right. And then s 1 is a s 1 b or a b and s 2 is c s 2 d or c d and you can see that this grammar is going to generate this language right. So we can handle two conditions, but not together is that clear or you know this is really intuitive way with what I am explaining and whenever you see that the conditions have to be kind of there mixing up or all both the conditions you need to ensure together that is where the problem arises right. So you should be able to at least intuitively see that the situation with l 2 l 3 and l 4 is different from l 5 or for that matter l 6 which is a m b n c n d m right. Here I need to keep track of correspondence between a's and d's separately from the correspondence between b's and c's this is something we can handle so long. So what is the difference between this and this as you handle this m is this m is you know number of a's here is equal to number of c's there I am getting some b's inside and you see that is where the problem will happen. We will kind of be able to appreciate this a little more whereas here you know this I can handle you know I have generated some a's and this is taken care of and separate I mean best is you should yourself write the grammar for l 6 this is a context free language. So you will be able to again very simply write a context free grammar which will generate this language. Well now that we have the pumping lemma and we now we know in particular one language you know several languages which are not context free now using this that fact I can come to a very strong conclusion right. So let me show what the conclusion is that the class of context free languages this class is not closed under intersection we will just now little later we will talk about the other closure properties but you know this kind of immediately almost immediately follows from whatever we have been discussing. So recall what does it mean to be for a class to be closed under intersection we are talking about classes of languages each language is a set you know I take two elements so one language and another language l 2 and I create the intersection of these two. We say the class is closed under intersection if whenever you pick up two languages from here in from the from within the class take their intersection the result is also within that class but we will be able to show very easily that this is not the case with context free languages. So let us take two languages l a i b i c j and l dash a i b j c j so claim which we can easily prove that both l and l dash are context free that let me let me quickly give a grammar for l for l you can this let me show you the productions s goes to let us say x y x goes to a x b a b and y goes to c y or so you see basically y can generate any number of c's and x will generate equal number of a's followed by b's right. So x will generate a string of a's and b's where number of a's will be equal to number of b's and y will generate just any number of c's and your string s is the intersect I mean the concatenation of these two so therefore you will generate all strings of the kind which is mentioned here and a very manner similar you know similar manner you can also give a grammar for l dash but what is the intersection of l and l dash so obviously they have to be again of the form a's followed by b's followed by c's since there in l all these strings in the intersection strings are in l so the number of b's must be equal to number of sorry number of a's must be equal to number of b's since the same string is also in l dash that means number of b's also must be equal to number of c's so therefore a's is equal to number of b's equal to number of c's so this is in fact this language a n b n c n n is greater than equal to 1. So as you see a very important result we proved quite easily from the fact that this language is not context free and this particular language is the intersection of two very simple context free languages so the class of context free languages this class is not closed under intersection because you know I could find intersection of two context free languages which is a n b n c n which we proved by pumping lemma which is this language is not context free this situation as you know is very different from the situation of regular languages regular languages are closed under intersection so since we are talking of closure you might as you will see some closure properties of context free languages so first point which is again fairly simple to see that class of CFL's is closed under union why you see what we are saying that you take two languages which are context free languages then take their union l 1 union l 2 and we are claiming that that union language will be context free so this this is this is very simple so let us say so let me give the proof with let l 1 l 2 be context free and generated respectively by by g 1 and g 2 so in particular let us say g 1 is n 1 s 1 and g 2 is now assume that you know we can if need be by rewriting some by renaming some of the non-terminals assume that these two sets v n 1 intersection v n 2 is empty that means we do not have do not use the same name for two non-terminals from the these two grammars right and now you see think of another grammar which is like this g which is a new start symbol s union put it in braces so basically just take the union of this v n 1 and v n 2 add s to that so you know that make it your new set of non-terminals union v n 1 union v n 2 right this is this is the set of non-terminals p of course sigma sigma p and this new non-terminals is your start and basically your p is p 1 union p 2 plus one more and which is that p is p 1 union p 2 union just one more production that is s goes to either s 1 or s 2 so what is happening you start this grammar g with the symbol s and this s can be rewritten as either s 1 or s 2 if you rewrite as s 1 you will generate a string of g o use the grammar g 1 to generate any you can you can generate any string of l 1 similarly you can generate if you first rewrite s by s 2 then you can generate any string of l 2 so therefore together it you know it means that from s you can generate all strings of s 1 as well as sorry all strings of language l 1 as well as all strings of the language l 2 which is precisely what the union language so therefore the class of c f l's this class is closed under union so from these two which we have just proved we can conclude something very important another property closure property that class of c f l's not closed under complementation remember complementation is that language l is there you take the complement and the complement language is sigma star that does alphabet minus language right the set of all strings over sigma which are not in the language l that set is the complement of l so what we are saying is it is possible that you take a c f l context free language l you complement it and you get a language which is not context free or similarly it is possible that you take a not context free language take its complement and it may turn out to be context free so see point I am making is that this three actually follows from 1 and 2 why because I can write intersection of two languages l 1 l 2 as you know take the language l 1 complement it take the language l 2 complement it take the language you their union right and then complement the entire thing this just a set theoretic way of expressing intersection in terms of union and complementation right essentially it is those of you know it is a kind of de Morgan's law so l 1 intersection l 2 is this now suppose the class of c f l's where I mean this class was closed under complementation so now suppose l 1 and l 2 are context free languages if the class was closed under complementation then this will be a context free language l 1 complement l 2 complement is another context free language you are taking their union which is union we know is you know preserves context freeness so then this whole thing will be context free again you are taking a complementation of a context free language which by assumption would be again context free so then what would it mean that l 1 intersection l 2 would be also context free so in other words what I am saying is if complementation if class of a context free languages this class was closed under complementation along with the fact that it this class is closed under union we would get the class is closed under intersection but we know this class is not closed under intersection therefore and we also know it is closed under union so what is the possibility left that it is not closed under complementation so that is how we prove 3 there are other closure properties which we can very easily see you know we talk of two other things often which is concatenation so we will say in fact this we can prove again these two things class of CFLs is closed under concatenation and class of CFLs this class is also closed under CLEANY star remember that what is this is an unary operator whereas this is a binary operation so we take two languages l 1 and l 2 and this is the concatenation language remember that l 1 l 2 is nothing but u v such that concatenation of u and v such that u is in l 1 and v is in l 2 right again this is very easy to see that class of CFLs is closed under concatenation why because you know for l 1 you have a grammar l 2 you have a grammar both are context free grammars and they have two separate you know something what we used for union same idea will do will use that suppose g 1 is the l of g 1 the language language generated by g 1 is l 1 and the language generated by g 2 is l 2 right and let us say g 1 is v n 1 sigma p 1 s 1 g 2 is v n 2 sigma p 2 s 2 and the new grammar for grammar for l 1 and l 2 will be a g which is will obtain by taking the unions of v n 1 and v n 2 assuming that they are disjoint that you can you can understand why I want them to be disjoint because otherwise the derivation of one will interfere with the other and will add a new star start symbol s and they will write it as we will just add this production and rest of the productions will remain g 1 and g 2 right. So, you can easily see that if you start with this s we generate s 1 s 2 s 1 and s 2 are the start symbols of g 1 and g 2. So, through s 1 I can generate any string of l 1 with s 2 I can generate any string of l 2 and therefore, I can generate the concatenation language Cleany star was if you recall we used it extensively in case of regular languages you know there was a language l and Cleany star was that star operation. So, what was it very briefly l star is the set of all strings obtained by taking 0 or any number or concatenation of any number of strings from l that will you will remember what it was now l star. So, basically l star is a c f l if l is a c f l this is the meaning of 5 and again that is not very difficult to see that suppose l is generated by g where where the grammar is v n sigma p s right. So, all we have to do is to just add one more production. So, basically sorry I should not have said this way. So, I should have said g suppose g is this such that l g is l then for l star the grammar is g 1 right which is just you add one more production p union just add this production keep the same start symbol s goes to s s or epsilon right and you can easily see that l g 1 is l star right because you see then now starting from s you can generate any number of copies of s and from each s you can generate a string of l and that is what would generate the language l star.