 Last time we had explained that we have two notions of acceptance for PDAs. So, suppose I have a PDA and which is as a set of states as this is sigma is the set of input symbols and gamma is the stack alphabet delta is the transition function q 0 is the initial state and z 0 is the initial stack symbol and f is the set of final states and for this for such a machine we had explained what was the language accepted by final states. That means any string which this will consist of all those strings which can take the machine from the initial state to one of the final states. So, we said ending in a yeah. So, in one of the final states. So, in terms of the instantaneous description it was that q 0 w is going to be in the language provided if the initial initial id is always q 0 that w and z 0 and this after some time you reach P epsilon and we do not care whatever is the in the stack right. So, we said that language accepted by m by final state is the set of all strings w such that this condition holds. Now, as opposed to that we also defined last time that there is another language associated with such a machine and we said we use the notation n m and this is the set of strings which are this is the language accepted by empty stack and let us see how we can define it. It is again the all strings w in sigma star such that here also of course I should have written sigma star all strings w in sigma star such that from the initial id which is again q 0 w z 0 after some time we reach a state P and so this P can be any state any P in q as opposed to of course in this case the P was one of the final states for some P in the final states set of final states. So, contrast these two know these two languages which are associated with a P d a m in the first case it is all those strings in sigma star which can take the machine from the initial id to an id where the entire input is consumed. So, what you what is left is epsilon and the state is one of the final states and we do not care what is the stack contains that time as opposed to in this case this is the language accepted by empty stack here we are saying this language consists of all those strings in the alphabet sigma over the alphabet sigma such that from the initial id with that string w in the input the machine can go to this particular instantaneous description and what is that description that we do not care what the this state P is, but the stack should be empty as well as the input should be completely exhausted. So, these are the two notions of acceptance by a P d a and so you notice that the for the same P d a m actually we have two languages which are associated with m. So, I can talk of the language accepted by m by a final state and here it is the language accepted by empty stack. Now, as it happens one may think this is more natural because you know we are used to acceptance by final state as we had seen in the case of finite state machines, but often it is easier to describe language acceptance by this notion. For example, consider this language you know simple language we know it is not a regular language and just consider this particular machine P d a which has exactly one state and so there is only one arrow it has to go from the state to this and what it can do is if it is c is a 0 and on the when it c is the stack symbol is z 0 it will push let us say a right. Now, if it c is a 0 and an a here it pushes on the top of the stack is a. So, it just pushes another a so instead of a you have the string a a the top of the stack symbol a is replaced by a a and now if it is 1 and if it is a then this is this top of the stack symbol is simply popped and it can also go basically do this right. So, it is not difficult what is happening you see that for example, if you had the string 0 0 0 1 1 1. So, initially I should have said the initial stack symbol is z 0. So, let me describe this particular machine m in this manner that it has only one state q and input alphabet is of course, 0 1 and the stack alphabet is a n z 0 and this is delta and delta is what I have described here in terms of this diagram and initial state is q because that is the only state we have and initial stack symbol is z 0 and we do not care suppose I just say the we have an empty set of final states which is because I am going to associate the language by empty stack acceptance. So, this is the language I am interested in so for as this machine is concerned. So, since the acceptance is empty stack we are not concerned with any final state and so therefore, I do not describe any state to be I do not mark any state to be a final state and now on this input what will happen initially the machine has z 0 and then you see the machine is going to see this symbol top of the stack symbol is z 0. So, it just pushes an a here and after consuming this particular symbol then it sees another 0 and now we can make use of in fact, the only transition that we can make use of is this. So, this particular 0 on this 0 it pushes another a this 0 is consumed and similarly one more time we have the same situation. So, this that particular 0 was consumed and then a was pushed and now what you have is a string of three ones and for every one you see and if the top of the stack is a that particular symbol top of the stack symbol is popped this is what it means that if I have the input symbol one top of the stack symbol is a then that particular symbol is replaced by epsilon. So, this after consuming this one the situation will be this because this particular a will be consumed I mean popped and similarly for on this one this one also will be popped and this one this one also will be popped. So, what we have is the whatever was the input that is totally exhausted and now I can make use of this particular transition to even remove this z 0. So, what has happened notice machine starting with the initial state and in this case there was only one state q on the input 0 0 0 1 1 1 with the top of the stack symbol 0 as the only contents of the stack. We manage to come to the I D in which the stack is empty as well as the entire input string has been consumed and therefore that particular string 0 0 0 1 1 1 would be in the language n m which is associated with this particular machine and it is not difficult to see that this particular machine will accept all strings which are in this language. In fact, actually the string epsilon is also there in the language and you can see if only epsilon is there the initial I D will be epsilon p sorry q epsilon and z 0 then you can just use this particular transition and we can remove that z 0 and go to a go to the I D. So, that would mean the epsilon would be accepted. So, now I have two notions of acceptance and correspondingly I have two languages we associated possibly with the same machine n. So, what is the by the way I mean it is a trivial kind of question what is the language accepted by m by final state that language is empty no string will be accepted because there is no final state p and. So, therefore, no string in this set. So, in any case the point is that for every machine m we can talk of two languages which are associated with that particular PDA. Now, the question therefore, is that is it possible that I have a language for which I can define a PDA which will accept that language using one of these notions and not the other. Then we have a some bit of problem because then I cannot talk of both these notions of acceptances in the same manner in the same breath. So, to say as it happens that is not the case the point is that if for a language there is a PDA which accepts that language by empty state I am sorry empty stack then they will be another PDA which will accept the same language by final state and vice versa. So, the point is if a language is at all accepted by a PDA using either of these two notions of acceptance then that language is also accepted by some other PDA possibly using the other notion of acceptance will prove this now. What I would like to show you now that suppose I have a PDA which accept some language by empty stack we would like to construct another PDA from that old PDA which will accept that same language the new PDA will accept that same language using final state acceptance. So, let us see what is the situation suppose I have this is my PDA M and which is accepting some language with empty stack acceptance. So, you know schematically it is something like this that this is the initial state of that PDA. So, let me say M is Q sigma gamma delta Q 0. So, the state is Q 0 and Z 0 and since it is accepting by empty stack you know we can just say that the set of final states for this machine is empty. Now, what I would like to do is essentially that create a machine which when it senses that this particular machine has emptied its stack it goes to a final state it can go to its final state. Now, you might say that why not have the situation that from such a state it should go to a state which is final state. The problem is you see you have to we must appreciate that when this machine has emptied its stack then there can be no other transition why because every transition requires something in the stack some symbol some stack symbol as the top of the stack symbol. So, the if the stack is empty the machine cannot proceed any further because the way we have defined our PDAs you notice that if for every transition we require that some symbol should be there as the top of the top of the stack symbol. So, the point I am trying to say is that once this particular machine has emptied its stack this particular machine cannot do anything. Now, if you are just running this machine and once that has emptied its stack then of course you it nothing can be done. So, one possibility is how do I to figure out that situation has happened that we create another machine M 1 where we have a different initial stack symbol and so another state new state P and from that state P on without consuming any symbol that on. So, in that machine the initial stack symbol is x 0. So, x 0 is replaced not replaced by when the x 0 is there we can push this z 0 which is the top of the stack symbol of M. So, is it clear what we are saying we are saying that imagine this old machine which is M to that I add another new state and the really the role only role this state plays is to push this stack symbol start stack symbol start of z 0 on to its own initial stack symbol x 0 and now and then it goes from this state P to the state initial state of this machine M. Then this machine let us say starts working and let us say at some point of time this machine has emptied its stack then what will happen you will this composite machine is going to find the top of the stack symbol to be x 0 is not it because this machine which kind of takes over once this state is reached if it ever empties its stack that time this machines empty stack means that the old top of the stacks of an initial stack symbol is exposed now which is x 0. So, in such a situation what we want is from every state if we sense that if we find that that now from this state if you find the top of the stack symbol is x 0 then you may write this x 0 I will not write it here and go to a state let me call it B F for final state. So, similarly from here also this transition is possible on no without consuming any symbol if you you can go from this state to this particular state writing as the same thing and basically the same situation. So, what we are saying is that from every state in this machine this extra transition is there to a new another new state. So, you see we are adding two states one is the new initials state and final state and now I claim that this particular machine see this which was inside the circle or this ellipse was the old machine M let me write it and this entire machine is M 1. So, now is it clear what is M 1 that M 1 is essentially the this set of states union two other states that we are putting P and P F right of course it will have the same set of input alphabet same input alphabet and what is its gamma it is the old gamma union we have a new bottom of the a new start start symbols the symbol stack symbol with which you start which is the start stack symbol x 0. So, which we this is the new stack alphabet. So, basically new stack alphabet is obtained by just adding a adding this x 0 to the old set of stack symbols delta dash delta dash is a new transition function which retains all the old transitions and adds a few more. So, one is to go from this state P to the old initial state of machine M or rather this machines initial state and the other set of transitions will can will be for taking the machine this composite machine from a any state to this final state on top of the stack symbol if found to be x 0 right. That means the this old machine M would have emptied its stack and. So, therefore, we go to a final state the only final state that we have. So, this is delta dash and now for this composite machine the initial stack symbol is x 0 and it has a final state which is this state I am sorry I am writing this as these are two poles. So, this is not set right. So, I should have written like this. So, it is not too difficult to prove that the language accepted by M 1 on final state is the language accepted by M on empty stack. So, that is why it is possible from any PDA given any PDA which accepts a language by empty stack using this construction to obtain a new PDA M 1 which will accept the same language by final state and as an example we could have done this construction for this particular PDA which was accepted accepting this language 0 N 1 N by empty stack. So, it would have meant since there is only one state. So, this is the old initial state there is only one state here and this is our new P and from here we can go to P F which is the final state. So, let me write like this and here also I should have put another circle to N to say that this is the final state and here what should we what is the transition without consuming any symbol on its initial stack symbol which is now x 0 we push z 0 right. So, now we start the this machine and anytime the stack is empty that would mean that we are going to see x 0 and we come here. So, you see that from the old machine just by adding these transitions we get a machine new machine M 1 and it is not difficult to see that L M 1 is also 0 N 1 N greater than 0. Let us now prove the converse of what we proved just now. So, what we want to show that suppose I have a PDA this is accepting a language by final state right by reaching a final state and from this PDA what I would like to do is to construct another PDA which will accept the same language by empty stack. So, it is kind of tempting to say that look why not have transitions from every final state. So, in this case you know I have marked two of these states as final to a particular state right where the job of this particular state where once you go there or once the machine chooses to go here the this in this state what we are going to do this machine is going to do is to just empty the stack. So, how will we do that see basically that here is on epsilon right on any x to epsilon. So, what it means is that whatever x is any stack symbol right and when we go here when we have reached some final state and the machine has the capability of making this transition and for making this transition of course, it does not have to it does not need to or does not wish to consume any input symbol presumably by then if it has accepted the string it has reached this final state there is no input symbol to be consumed right and so whatever be the stack symbol here writes the same stack symbol or it can even just remove that pop that stack symbol similarly from here also it can do the same thing. So, you might say that this should work right why because let us let this within this ellipse whatever be the you know states and transitions which were there that shows the old machine and suppose now the old machine has gone to a final state. So, that means it has reached one of these final states and now it should indicate that string to be accepted by empty stack. So, all we are doing is that we are going to a state and emptying the stack right this would work almost why is this is not the correct conversion for a machine which accepts a language by final state to empty stack because seems this is all right the reason it is not correct is that the old machine you know this situation is possible that you see that this machine suppose the old machine was M which we again will write Q sigma gamma delta Q 0 Z 0 F. Now, it is possible that this machine empties its stack consumes the entire input. So, suppose in this case what I am trying to say that suppose from the initial id Q 0 W Z 0 it goes to some state P epsilon epsilon and P is not a final state. So, such a W will not be accepted by the old machine such a W is not. So, I can say that W is not in language L M and now you look at this composite machine which you are trying to which we said our first attempt to convert M to a machine accepting the same language on empty stack. Do you see in this machine what is going to happen that W has taken the machine from here to some state P which is not a final state, but the stack is empty the input is empty. So, then that means the machine has reached this state reached this id and so, if we are having the notion of acceptance by empty stack then this W would be accepted. This situation we want to avoid it should not happen this particular string W should not be accepted then how do you take care of such situations. The only way I mean one way of doing it would be that you add another initial state to this and they gain the role of this initial state is to put a new see this new machine will use x 0 as its initial stack initial stack symbol and from x 0 it just puts z 0 on top of the stack x 0. So, now now let us see what is going to happen. So, what is going to happen is if this situation happened in this machine of course, this machine will also reach this state P the input will be exhausted, but the stack would not be empty because all that stack will now show this old top of the stack symbol x 0 here. So, is it clear what we are saying that this particular machine had z 0 as its initial stack symbol. We are creating a new machine where we will use a new symbol stack symbol x 0 as the you know initial stack symbol and the only thing that you do really is to write in the beginning on top of this x 0 you put the initial stack symbol of this machine and then let the old machine run. So, basically we are going to the initial state of the old machine which accepted the language by empty stack and now if the old machine sorry the old machine was accepting the language by final state and now if the old machine had emptied the stack exhausted all the input and in a is in a state which is not a final state. So, what is going to happen right now the this particular machine the composite machine is going to see x 0 on the top of the stack right. So, the stack is not empty and therefore, there is no way this machine this composite machine is going to remove that x 0. So, therefore, that w is not going to be accepted. So, this is the correct conversion from a machine which is just this which was accepting some language by final state to a machine which accepts the same language by empty stack. What did we do we added an extra state here as the initial state as well as we added another new state whose job was to basically you know flush the stack and that state you would reach you can reach only from one of the final states and the accidental emptying of stack is not going to now matter because we have this x 0 in the stack. So, this is the conversion. So, we added two states added a new stack symbol and we can now you know it is easy to get the definition of the empty stack acceptance machine from the old machine. We had encountered this language before we gave this as an example of a context free language which is not a regular language and let us design a PDA to accept this language. The strategy is something very simple. So, let us say for 0 there is a corresponding stack symbol. So, this is the input symbol and the corresponding stack symbol is a and for 1 the corresponding stack symbol is B and think of some example string in the language. Let us say 0 1 1 0 1 1 0 0 or something like this. So, this is 4 0s and 4 1s which is therefore string which is in the language. So, what you are going to do is something like this that here is my stack there is some initial stack symbol z 0 when I see a 0 I will push an a and now I see a 1. So, you see what I can do is therefore that this particular 0 is can be checked off with the one that I have seen. So, on 1 and if the top of the stack is a then I am going to consume that 1 and you know we are going to pop the a. So, basically that means I have what I had a symbol 0 here I have seen a 1. So, these 2 have been paired off and now the rest of the string should have the same property that it should have equal number of 0s and 1s and now again I see a 1. So, corresponding to 1 this 1 I will push a B and again I see a 0. Now, 0 and top of the stack is B. So, I can consume this 0 and corresponding this to this 0 was the old 1 for which I had a B and therefore I pop it and now you see I have 1 here. So, I will put a B another 1 here. So, I will put another B is it clear why we are doing it because you know I as yet I have no evidence that there is a 0 2. So, for so long I have you know come to this point I have no evidence that these 2 1s can be paired off with 0s and. So, there is 2 Bs are recording the fact that I have seen 2 1s which have not been paired off with 0s and now I see a 0 this 0 for this 0 this B will be removed this 0 new last 0 this B will be removed and then we can remove this at 0 and the stack will get empty. So, what I have described is that I have 1 just 1 state and if because I have only 1 state that is the initial state as well as all the transitions are going back from that state to itself and let us now write down the whatever I described. So, if you see a 0 and that means so far the stack is empty. So, what you are going to do you are just write the corresponding stack symbol and push it there right. So, a z 0 similarly 1 z 0 will be B z 0. Now, if I see 0 and B what should you do you should consume this 0 and pop off this B. So, epsilon 1 a epsilon 1 a epsilon 1 a epsilon and what about 0 and a it would mean that we should put push another a and 1 and B I should push another B and finally, that I should have the freedom to remove this z 0. So, epsilon z 0 epsilon right. So, what has happened is that I have a PDA call it M and I claim that this PDA accepts this language L by empty stack. So, it is not difficult to understand difficult to see that any string which has equal number of 0's and 1's will be accepted by empty stack by this machine correct. And on the other hand suppose I had a string like this 1 0 0 1 0. So, what is going to happen that initially of course, you had z 0 and when this 1 came you pushed a B right then this 0 came you know you pop this B and checked of this you know consume this 0 this 0 came you put an a this 1 came. So, now you know 1 a. So, this a will be popped off and now a 0 is there so corresponding to that this a is there you see and now the input is exhausted and we cannot you know empty this stack because on the top I have a and such an a can be removed you see only with a 1 and that 1 is missing. So, you can see that any string which is not in the language whatever I wrote there that string would not be accepted. So, it is not difficult to prove that this machine will accept this language which has equal number of 0's and 1's. The interesting point about this particular machine is that it is accepting a kind of non-trivial language using just 1 state and of course, it is doing so this acceptance is by empty stack. So, 2 points I want to make here that firstly you see that it is kind of easy to define PDS to design PDS using the notion of acceptance by empty stack to accept some given language. We will believe this as an when we do more and more problems I mean we will not do it in these lectures many more, but if you try more and more problems we will find this kind of acceptance is fairly easy to use. The other interesting thing is this language seem kind of complex because it is not a regular language and yet we could accept that language by empty stack using only 1 state. This is not accidental what we can show in fact we are going to prove that any context free language can be accepted by a PDA with just 1 state using empty stack, but we will prove that in the next lecture and in the next lecture we will prove the converse of this not so much 1 state business. The converse would be given any PDA I can get a context free grammar such that the 2 devices that is the language accepted generated by the grammar will be the language accepted by the PDA that we are going to design. So, in other words the 2 results that we are going to show that given a PDA we can find a context free grammar to generate the same language as accepted by that PDA and given a context free grammar we can find a PDA which will accept that language which is generated by the context free grammar. So, that will show that PDAs capture exactly the set of languages generated by context free grammars. So, therefore PDAs are just another way of capturing the class of context free languages. This is something what we are going to do in the next class.