 So, we had proved that the class of context free languages this class is not closed under complementation. And last time we did provide a language example of a language which was not context free. In fact, that is the very first language we proved not to be context free if you recall A and B and C N, but we proved that the complement of that language is indeed a CFL. So, you know when we say that this class is not closed under complementation what it means is that in general it is not the case that if you take a context free language its complement is going to be a context free language. It may be it may not be in some cases of course like for example, you take a regular language which is of course, also a context free language its complement is also a regular language therefore, a context free language. So, here is an example of a language whose you know the language itself and its complement both are context free. Here are couple of examples which is kind of interesting that on one side that is the maybe the language is context free its complement is not context free. And of course, there will be languages which is you know each of which is neither context free nor you know its complement also context free. So, that is also possible. So, all these cases are possible and the particular reason why we are giving this another example is because this is an interesting example of showing a kind of you know initially a certain language might appear not to be context free, but on some analysis it turns out to be context free. So, this the example to do we are taking up is one such alright this language L 1 which is W W where W is a binary string this language L 1 is not a CFL. Now, what just notice what is this language it is any string W repeat it once more. So, take any string W any binary string W concatenate that same string with itself. So, you get W W. So, a repetition of one string any string any binary string this particular language is not a CFL and we had argued sometime back that why this is not a CFL. In fact, if you just take W to be a n b n a n b n. So, it is a n b n repeated twice where n is greater than equal to 1 that string you know on pumping will be able to get a string which is not of the form W although that string n b n a n b n was of this form and that where the n that we choose for a particular string for using in the in the for our use of pumping lemma that n is the pumping lemma constant of the for that language if it was a CFL right. So, this is this is something we have seen and what we want to claim is that its complement that is L 1 complement is a CFL this is what we would like to show and in particular what I would like to do today to begin with is that this particular language what is this language L 2 which is concatenation of two strings x and y both are binary strings and the length of x is same as the length of y. So, concatenation of two equal length strings which are not equal x is not equal to y this particular language is a CFL and this is the hard part or relatively harder part that if you prove this then you should be able to prove that L 1 complement is also a CFL I will leave that part as an as something that you can do yourself. So, once more what I am trying to say is that this particular language L 2 which is the concatenation of two equal length unequal strings right the language consisting of such strings that is a CFL how do we go ahead and prove this to be a CFL and this is where I think a little bit of analysis very simple analysis of this condition will help us. So, what is it saying? So, in fact let us think of a string let us say this is x and this is y firstly it is saying that the lengths of these two strings are equal as you can see I mean I am trying to analyze this all these three conditions and. So, this is y and the way we have drawn these two strings are of equal length for our analysis that we can see now it says the binary strings which is ok. So, x and y both are over this alphabet 0 1 and now what does it mean to say that the string x and y they are not equal remember what is our task our task is to provide a context free grammar g which will generate all strings of this kind that is all strings x y where x and y have equal lengths they are binary strings, but x is not equal to y how do you go ahead and fulfill this condition what does it mean to say the string x is not equal to y is that is that is the crucial thing what it means is if you think about it I mean how do you can how do I convince you that this string and this string they are not equal supposing I have what is the simplest way of convincing you that two equal length strings are not identical when I say equal that means identical that means as a string they are not same if you think if you pause for a minute or even less than a minute what it would seem one way of convincing you first of all we are assuming that these are two equal length strings right now take some bit here which is in after b bits in this this bit and the corresponding bit here so what it what it means that the bit which we obtain in this string x after skipping b bits right b symbols from this you know starting from the left I move b positions and then the symbol that I get and here again I do the same thing this length is b right and let me say this symbol is let us say a and this symbol is b of course a and b there either 0 or 1 and because the two strings so let me write it this is the kind of analysis I am talking of because length of x is equal to length of y right then what it means immediately is that the rest of the bits here rest of the string here the its length is same as the length here isn't it so that to begin with the two strings are of equal length I am considering the symbol which comes after b bits b symbols from the left here and the symbol b symbols from the left in the second string and whatever will be left in the first string that length is obviously equal to the length here so this is c okay so now I claim a proof that the string x is not equal to or not identical to the string y is that there is a position after b bits in x such that the symbol there is different from the symbol from the corresponding symbol in string y this is again not too difficult to see but all I am seeing that your task of providing a proof that x is different from y you know it uses to finding out a position in the string x which comes after you know b bits actually this b and this b are different so let me call it this is a and this is a prime right so a and a prime are two symbols and they are the two symbols at a corresponding position that means you know if it is the kth symbol from the left here this is in x a prime is the kth symbol in y from the and that is your counting k from the left of y all right is this clear I think it should be you know kind of obvious that if I manage to show or find such a a prime such that the two symbols a a prime are not same though occurring I am just saying the same thing in a different way in the same position in x and y respectively these two symbols witness that the string x is not identical to the string y right. So, this is about this is about our analysis and what then I need to come up with a grammar which will do two things simultaneously one is that it will generate two equal length strings that is easy isn't it that if I if I ensure the grammar generates only strings of even length then clearly whatever it generates it can be seen as two strings concatenated and these two strings are of equal length so that part is okay the harder part is that grammar should also ensure that you know there is some position b in the string x you know this this condition that I have written that the symbol a and a prime are different and you know as you if you stare at the problem what you see is not immediately clear that I can indeed define such a grammar a grammar context free grammar which will ensure that the two corresponding you know some at least for one particular position that the corresponding position here the two symbols are different you see the point is this because the one way of I am trying to ensure something about these two symbols so you can imagine that I am one way of doing that would have been you know generate something you know from here and you see that like as in the case of x reverse that the correspondences between these two can be taken care of provided I am generating pairs of symbols you know starting from the middle and somewhere I make sure that pair is the pair that I generate at some point is different in the sense they are not off there the pair is not 0 0 or Z or 1 1 pair can be 0 1 1 0 but then that is easy. However then how do I ensure that this the other part here you know this these lengths length considerations how do I ensure that that after that we need to generate only c bits here but on the left side we need to generate b bits here so if you think about it that approach is not going to work but you know this this picture if I just do something slightly differently immediately the solution will stare in our face see these are two strings this is of length C this is of length B why do not I do one thing instead of instead of the way I have written let me see view this string a little differently what we are going to do is instead of viewing this part of the string as first a string of length C and then followed by a string of length B why not let me do this first a string of length B and then a string of length C right if we are just doing some accounting if you like differently so all I am saying now consider this entire string to be what that first some string of length B that entire string was then a string of length C plus B then a string of length C now I am doing it equivalently as if I am saying that let me count the B part right from here rather than at the end that a length B then this symbol a followed by a string again of length B followed by a string of length C then the symbol a prime then this another string of length C so let me you will first of all agree that I have not changed anything in that string however I am just viewing that string a little differently so let me rub this out the old way of accounting okay now now the solution is coming out see what is it saying is that I have what I have this this entire string is a string like this it is some symbol A flanked by two equal length strings B I am redrawing it then a prime I am sorry then a string C of length C followed by the symbol a prime again a string of length C now isn't it this is the same thing I have just named some parts of the strings a little differently it is the same string I am viewing it differently but what is the condition that this symbol a is different from symbol a prime so let me write that can you see now how this can be done so easily quite easily so essentially generate some string an odd string so this is a string of length 2B plus 1 you know this is one symbol so the 2B plus 1 this is a string of length 2C plus 1 so there are two odd length strings binary strings and every odd string has a unique center so the center of this 2B plus 1 string center of this string is this symbol and center of the rest of the string is this particular symbol a prime what we are saying is that the two centers are different this string so let me let me let me now summarize what I am saying is this such a string what is such a string a binary string which is composed of two strings of equal lengths but the two strings are not identical can be seen equivalently as two strings of odd length the centers of the two strings being different all right now once once we understand that then grammar for that is comes out very very trivially so first of all by the way what is the any restriction about this lengths B's and C's do you see that lengths B's and C's are kind of independent they have nothing to do with each other isn't it because if you take a large string then some bit position is at B here the same bit position at B in the next string and whatever is left is C so you know B and C so far as in general the set of all these strings are concerned they are quite independent and now let us try to give grammar a grammar context free grammar which will generate these strings let me define two context free grammars one which generates let this two grammars one generating an odd length string with center bit 0 on the other generating again an odd bit generating an odd length string with center so let me see the start symbol for this is a 0 and the start symbol for this is s 1 so what are the productions of this first grammar it is quite easy a 0 can be 0 or s 0 can be 1 s 0 1 1 s 0 0 0 s 0 1 0 s 0 so if you think about this this grammar I mean I have given the productions and it has only one non-terminal s 0 okay so the grammar is g 1 I said g 1 I am defining it as s 0 p s 0 and these are the productions or this is the these are the productions and this I am calling it p now it is very very simple to see first of all that it will generate only odd strings right odd length strings and its center will be 0 because why see see you know think of let me just give an example so let me say 1 0 1 0 1 1 0 this is an odd length string with center 0 centers symbol is 0 so that how do how do how are we generating in this now start with s 0 and 1 s 0 0 that takes care of the two outermost thing then 0 1 s 0 so these two are gone then 1 1 s 0 and finally 0 so the final s 0 which is replaced that gives the center right and that is always 0 in the same way we can define another grammar the grammar for this is going to be very simple very very similar obviously identical almost s 1 0 1 p 1 let me see and s 1 and s 1 is 1 and s 1 is you know other things are similar s 1 1 1 s 1 0 0 s 1 1 0 s 1 0 so g 2 will generate odd length strings with center 1 for the same reason as we have given and now imagine that I have I combine these two grammars to have one single grammar and great so what I am going to do I will have these all these productions at the same place right and we will add see what is what is our goal our goal is to generate an odd length string with some center bit and then generate another odd length string whose center bit is different so do you see this is going to work that my new start symbol is s s I will say first you either you first generate an string which can be derived from a 0 followed by a string with center 1 odd length string with center 1 so that will mean that somewhere this a is 0 this a prime is 1 or it can be right and then my grammar is therefore will now have three non-terminals so the actual g that we derive is s s 0 s 1 this is the set of non-terminals and followed by set of terminals is of course 0 1 and then I have this new set of productions p prime which is all this followed by the start symbol s and remember p prime has this as well as all this this is your p prime this is the grammar now I claim LG LG is what the grammar L2 that we wrote that set of all strings x y such that length of x is equal to length of y right x is not equal to y and x y are both binary strings language generated by this grammar is indeed that language that we had earlier called L2 and by analysis or analysis and our way of viewing it we got the fairly simple grammar actually isn't it to generate this language which is concatenation of two equal length strings which are different and since I could generate this language using a context free grammar this language is a context free language so now we will consider another topic another subtopic of context free languages is about their decision algorithms now what is what is a decision algorithm a decision algorithm is an algorithm which solves a decision problem and in turn what is the decision problem a decision problem is a problem which will have yes no answer you need to decide given the input you need to decide yes or no for example in case of context free grammars that your input is usually you will be a grammar or a pair of grammars or a grammar and a string so example decision problems for CFLs so let us say one is given CFG G as input is the language generated by G infinite so if you say yes that means LG is infinite if you say no LG is finite similarly given CFG G is LG empty so this is another decision problems there can be more given G a CFG and a string X is X in the language generated by the grammar G and of course let me take another or two others given G is LG is equal to sigma star where the grammar G the input alphabet is sigma another given two CFGs G 1 G 2 is LG 1 equal to LG 2 now for a moment let us instead of CFG think of regular languages is there in other words instead of context free languages we can of course you could have posed the same problems for the class of regular languages so there for example as something a problem like this will be given a DFA M as input is the language accepted by M infinite again given a DFA M is the language accepted by M empty and so on and so for example last would be that given two DFA M1 M2 is the language accepted by M1 same as the language accepted by M2 now if you go back and remember what we did for regular languages all these decision problems for all these decision problems we could given for each of them we could given algorithm so in fact almost everything that we think we could think of as decision problem for regular languages we could give an algorithm to solve that decision problem in case of the this class context free languages the situation is very very different in fact we will indeed be able to show or give algorithms for these decision problems and for these last two one would be able to prove later on if we if we do a little more of this course that these there are no algorithms to solve these decision problems so you see what I am trying to say is whereas I will be able to provide an algorithm to solve let us say any one of these first three decision problems when it concerns context free languages for the other two for example here what you are differ asking the question is it seems very innocuous that here is this grammar G over with generate strings over an alphabet sigma does it generate every string of the alphabet sigma and interestingly that there is no algorithm no one algorithm at all for solving this decision problem similarly given two context free grammars do they generate do both of them generate the same language again there is no algorithm to decide this question and such decision problems are called undecidable problems which when we do Turing machine will be able to go deeper into the class of undecidable problems so right now let us provide the positive results that is all we can do let me provide algorithms for one two and three so the first problem is you are given so the first problem is that given a grammar CFGG is LG infinite actually the simplest simpler simpler thing let me start with which is the second problem given a CFGG is LG MT now one kind of one algorithm follows the proof of that proof that we had seen of pumping lemma for both one and two but let me give you a more direct algorithm for G which actually we have done so you recall we had provided an algorithm for the following problem that given a CFGG and given and for a which is a non-terminal G does a derive any terminals tree and remember that is this one way of supposing in other words actually I should have said we can we can write this or we can symbolize this this way that is there a W W is an element of sigma star sigma is the input alphabet of G so is there a W W is in sigma star such that this non-terminal A derives the string W right if we go back we will be able to remember this algorithm if you do not remember right away the idea was that we kind of iteratively figure out all those non-terminals which generate terminal strings and at some point of time we will be able to discover all those non-terminals which generate terminal strings and then if this non-terminal A happens to be in that set of non-terminals which generate terminal strings then I can say that this A does derive a terminal string that was the idea now you see for a grammar G to be empty that means what S does not derive any any terminal string at all right so you know I can just run through the same algorithm for the input grammar G and if I find that the start symbol S does not derive any terminal string then clearly the grammar generates the empty language so that is the that is the that gives us the algorithm to solve this decision problem the other two will take up in the next lecture and this one also will be quite simple in fact we have done most of the work for this this is a very interesting algorithm which we will provide so in the next class we will continue with this topic decision algorithms for CFLs in particular we will provide decision algorithm for problems 1 and 3.