 We shall now study a new class of automata called push down automata P, D, A. These three letters constitute the acronym for this class of automata. So, for short we call them PDAs push down automata or PDAs. These PDAs will see they recognize the class of push down automata. This class recognizes precisely the class of context free languages. So, let me write this important fact class of PDAs recognize exactly the class of context free languages. This is something we will show in a while. The point about this PDAs is that so far we have studied context free languages in terms of context free grammars. Remember that grammars are generative devices. We say a string is generated by a grammar. In particular given a context free grammar g that will generate a set of strings which will constitute a context free language. This is something we have seen. But now what we are kind of moving to is a machine characterization of context free languages. Now remember that machines or automata they are not generative devices. There will be some input string and the machine will decide whether or not it will accept that string. If it accepts that string it is in the language accepted by that machine otherwise that string is not in the language accepted by that machine. So, all these things we had studied these notions we had seen in term when we when we discussed finite state machines. So, all those notions will be there that is for every PDA they will be exactly one language which is the language accepted by that PDA. So, all these notions we will formalize. But first of all let me give a kind of informal description of what these PDAs are. In fact let me motivate ourselves to these machines to these automata by means of an example. So, consider this language L W C W R where W is a string in over this binary alphabet and C is some symbol some terminal symbol which is different from 0 and 1. So, an example of a string in this language would be 0 1 0 0 then C and then 0 0 1 0. In other words this string is in the language because the part before the portion of the string before C namely 0 1 0 0 is the reverse of the string which occurs after C. So, you can see that if I reverse this string I will get 0 0 1 0 and that is the string which is there. So, therefore, this is in the language we can very easily show that this language is not a regular language because we can use the regular language pumping lemma to show that this language is not regular. And we can also similarly provide a context free grammar which will accept this language and what is that grammar in fact let us do it right away. So, we can see that S this is the start symbol goes to you know C as well as 0 S 0 as well as 1 S 1 right. So, there is only one non-terminal S and remember we said the 0 1 and C are the terminal symbol. So, this grammar I am not writing the set of non-terminals which is of course, just one this S and you can see that this particular string will be generated from by this grammar will generate this string because from S we go to S you know the outer words first. So, 0 S 0 then again 1 S 1 then 0 S 0 0 S 0 and this particular S is rewritten as C right. So, the string generated is 0 1 0 0 C 0 0 1 0 right. Now, notice the reason this grammar could generate this particular string is because the correspondence between this 0 and this 0 that is being taken care of similarly between this one and this one that this correspondence was taken care of in this rule in this using this particular rule in its application. And we had remarked sometime ago that context free languages can very nicely capture you know this intuitive notion of nesting that this particular string is nested between these two zeros and that correspondence is what you know I pointed out here. And you can also see again intuitively why this string or strings like this cannot be recognized by finite state machines. The problem is that the correspondence that is if in the beginning a 0 has to happen then at the end also that 0 has to happen. Similarly, if the kth letter is 0 from the left end that kth letter from the right end also should be 0 till till we see the C. So, this kind of nesting you know this is there is this correspondence and the other correspondence is nested within it and so on right. We had remarked about this kind of intuitive property of strings generated by a context free grammar. And now we would like to capture this idea in a push down machine or in a in a machine the what push down machine or push down automator will have it will have as usual as in the case of finite state machine it will have a finite state control. So, again we will elaborate all this, but the point is that such a machine also has a finite number of states right. But what it has which is in addition to something different from what finite state machines they have is this machine is also equipped with a stack or you know another name of stack is push down store. So, let me let me draw a picture. So, such a machine would look like that this is the part which is the finite state control of the machine. Now it has two heads two if you like two heads and one head is on a for reading the input. So, this this head is somewhere here and at this moment if the head is here whatever symbol is here that is the symbol the machine is scanning in addition to this head there is another head and this head is for reading the top symbol of a stack. So, this is the stack and mind you that the stack is something which is can grow arbitrarily large similarly can shrink also. So, you know a stack can grow in size and then again it can come down again go up grow and so on. Now, the machine can actually you know the move of the machine is basically will be that it reads a symbol it read something on the top of the stack and depending on these two information and of course, depending on the current state the machine is in it decides it decides to do what of course, it will take a decision about what will be the next state it will also decide about what to do with the top symbol. So, it what essentially in general what happens is the top symbol is really rewritten by a string. So, in fact I will give the formal definition a little later, but let us see how this particular language will be recognized or accepted by this by a machine like this. See what happens is before the c comes whatever symbol the machine sees in the input a symbol corresponding to you know 0 or 1 will be written in the stack. So, let us say we make this correspondence that will have for input symbol 0 will have a corresponding stack symbol. Let us say a and for input symbol 1 will have a stack symbol which corresponds to it b and let us see how what is this idea of correspondence what happens is for example, it sees this string 0 0 1 0 c 0 1 0 0. So, in the beginning it sees this 0 and because in the beginning it has seen this 0 it writes in the push down stack the symbol which corresponds to 0. So, in that it is a then it sees you know it has consumed this particular symbol. So, it comes here it will see another 0 and corresponding to that 0 it will write the symbol a. Now, it sees a 1 and therefore, it will push on the stack this symbol corresponding to 1 and again it will see a 0 here. So, it will do a 0 and now you see when it sees the c it knows it has seen the first part and what it should now see is the reverse of the part that it has seen so far. But you see if you see what is there on the stack and if you if you go from top of the stack to bottom that spells out this particular string the corresponding corresponding string which is this. So, basically remember 0 0 1 0 the course we according to our correspondence the string is a a b a and now from the reverse it is a b a a and that is exactly what is the string which we have on the stack and now what it can do it will see a 0 and this top of the stack is a. So, therefore, this 0 does indeed has a it knows it has a matching symbol which is this here which is this. So, now therefore, it checks it out and then again it sees 1 that matching symbol is here. So, it is b then 0 then 0 right. So, at the end of it when the stack is empty the machine would know that the string that it has seen so far is indeed the kind of string which is there in the language. So, therefore, it will accept that string. So, now you can see from this very informal description how we can formalize this kinds of machines. So, so you see you can clearly see what this such a machine will have of course, first of all. So, let me write here machine components it of course, has a set of states and this is a finite set of states then to define this machine I must say what is the input alphabet here in this example the input alphabet was 0 1 and c. So, this there is an alphabet which I can say the input alphabet input alphabet then you are also writing you know strings on the you are reading the top of the stack and so on you are writing something on the stack. So, the stack has it is own set of symbols or an alphabet. So, let me call that this as the stack alphabet which is capital gamma. So, this is stack alphabet then the machine is making moves then that move for that move we must follow a certain transition function and that will call delta and will elaborate will see exactly what this what is the form of this delta etcetera and what are the things to remember like in finite state machine we have to say what is the initial state to define a finite state machine. So, here also we need to say what is the initial state. So, let me say q 0 will be the initial state also for reasons or we know we will have a convention that usually the stack is not empty and stack is empty on a very very special occasion. So, to begin with there will be some something in the stack and what is in the stack there will be some initial stack symbol the stack would initially will have only that initial stack symbol. Let me call that as z 0 initial stack symbol and of course, it like any machine like finite state machines also you know it will have some set of final states or accepting states. So, let me call that f. So, it is not difficult to see in order to formalize or describe or define such a machine I need to provide all these seven components of the machine namely the set of states the input alphabet the stack alphabet the transition function. So, this was transition function then the initial state the initial stack symbol and the set of final states. So, now let us try to say what this transition function delta is transition function delta. What is a transition transition is in this case the machine is in some state. So, what at a given step at a given step you can see the machine has machine has to be in a particular state. So, it can be in some state q and then the input head is scanning some symbol in the tape which is the input tape and input this particular head and you should be it is kind of clear we are not writing anything here only writing that we do is in this on the stack. So, this is we can we can think of this tape as a read only tape and what more we will see that this head never moves back this head will move from left to right. So, coming back to what our description of a transition function at a particular point of time the machine the p d a is in a is in a certain state q it is scanning an input symbol some symbol in the input tape call it a and what is this read I mean the stack head doing it is scanning the top of the stack that is the top stack symbol it is you know it is a kind of convention or it is by definition when we use stack we can access if we have a stack we can also at a certain time we can only access the top of the stack. So, we can push that we can push something on the top of the stack or we can pop the top symbol of the stack. So, it is therefore seeing some symbol a on the top of the stack. So, let me say this is the current state symbol input symbol being scanned and top of the stack symbol and depending on these three things what the machine will do the machine will seeing this it will go to there will be some next state p and what is the other thing that will happen that you know it will manipulate the stack by manipulating the stack what will always mean is what is written in place of the top of the stack symbol. So, if I write this. So, gamma is therefore, some string over the stack alphabet and suppose we say that what it means is that whenever the in the the p d a is in state q scanning the input symbol a with top of the stack being capital A. Then what is going to be the situation. So, let me let me let me write it. So, that there is no confusion or draw a picture rather that this is your input here it was a and this is the machine it is in state q and on top of the stack symbol is a there can be some other thing if we mean if we say that the transition function says that from you know from this the next state is p and the string that is written as gamma. So, in particular let me just say that in this case gamma is let me say b b a b b just b b right b b b then from that. So, you can see this is supposing this is the situation in a particular point of time then in the next instant and let me also say here the symbol was b let us see if the machine has made use of that transition that means now you know it has consumed this particular symbol has been made use of. So, it has consumed the a this symbol and so right now the head has moved one square to the right and what is happening to the stack. So, let me just say what was written below was may be c d e and here your bottom of the stack symbol remember we said that such a thing means the top of the stack symbol is replaced by gamma and we have taken this as an example that gamma is the string b b. So, it will mean that what new stack will be or currently what will be there in the stack is b b in place of this symbol a. So, that is the point that this symbol is rewritten by this string gamma and then the other things of course would not be disturbed. So, c d e and z 0 right. So, and the machine is right now in state p. So, this is one move of the machine such a move will be there such moves will be there and these are what the transition function will specify. Now, right away I should tell you that we will always consider not see this is a kind of deterministic thing that if the this situation if I write like this that whenever the machine is in state q the input symbol is a and the top of the stack is a then the machine goes to state p and replacing a with gamma that is determinism right. If this happens then it has to happen next day, but we will right away make our definition of p d s to be non-deterministic where can non-determinism enter see it can enter in two ways. The first way is obvious that suppose I had a number of such tuples. So, we appreciate this would mean that suppose the machine is in state q scanning the symbol input symbol a top of the stack symbol a then either the machine moves to state p 1 writing gamma 1 in place of a or it moves to state p 2 writing gamma 2 in it is in place of a and so on or it goes to state p k writing gamma k in place of a. So, this is one obvious way non-determinism comes in will also allow something which corresponded to the notion of epsilon move in a function for finite state machine. So, what was epsilon move remember that a finite state machine on an epsilon move could do could what it could do otherwise basically chain state without consuming the current symbol in the input. So, this is something will allow also. So, what it means is that this a also could be not just a concrete symbol of the alphabet input alphabet it could also be epsilon. So, in that case what would it mean independent of supposing it was let me let me write it this way. Let suppose delta q epsilon a was p 1 gamma 1 and p 2 gamma 2 this set what it would mean it would mean that if the machine in state q independent of whatever is in the input the symbol that is in the input it could change state to p 1 or p 2 writing gamma 1 or gamma 2, but the point is suppose at that time the machine was scanning some symbol the input head does not move forward. So, given all this how should we write this delta let me let me clarify this because you see the now as I said there are two kinds of non-determinism we can or we should take care of one is in terms of state what is what is to be written on the stack that pair as well as whether the input symbol is to be consumed or we are resorting to a epsilon move. We will say therefore that the transition function of a p d a. So, let me write the p d a as q sigma remember this is the set of states this is the set of the input alphabet gamma which is the tape alphabet then delta is the transition function q 0 which is the initial state z 0 the initial stack symbol and the set of final states and then if the machine is this then the transition function is a mapping. So, from q cross we remember we said that the this transition function will be defined it can make use of epsilon moves in the for the input symbol. So, the for the this part second component here we can either have a symbol of the input alphabet or epsilon cross gamma what does it mean? That this the argument is a is a triplet first is a state of the machine second is an input symbol or epsilon third is a top of the stack alphabet and this is a mapping to power set of what q cross gamma star. So, let us understand this this is not you know we are writing like this it might be slightly confusing what is let us say I had q to be q 1 q 2 and I had some gamma to be a b and. So, let us say in a particular move the machine could either go to let us say q 1 and the top stack symbol would have been replaced by b b a or let us say q 2 and let us say b. So, in that case you see what is what is q cross sigma star what is this set? This set is q 1 q 2 cross all of these strings like you know you know whatever gamma you know there are infinitely many string. So, this will be the set of all tuples the first or set of all pairs first of which is a state the other is a string and the power and a power set of that will be a subset. So, this is a subset of q cross gamma star. So, this is that is about it we are just writing like this and it should not confuse us. And now the point is that you can see we could have used q a a the our own example. So, this this now is. So, we need to define what is for suppose q is q this is a this is gamma then what should be what are the moves? So, that is what your delta would give right. So, you know like whatever I had you can see that is a subset of q cross gamma star. And now let us take an example to concretize what we are saying will write down the transition functions properly. And let me take the example of a slightly in fact a language which is similar to what we had seen, but which will necessarily use non-determinism. And that language is w w r w is a string over 0 1 star. So, this is what we have seen. So, you can see that in previously I had in between this w and w r I had a symbol c which would you know necessarily indicate the first half of the string is over and the second half the reverse part is now to be expected, but now I will have just a binary string right. So, the machine will need to you know standard way we can imagine what it will do it will guess the middle has come. So, therefore, it will make use of non-determinism non-determinism to capture or to to to to recognize strings like this. So, again informally first describe let me describe what such a machine will be which will accept this language. And in fact why am I saying that this is somewhat informal because I have not yet defined the notion of what does it mean to say that a language is accepted, but informally we understand something about acceptance and that is what is enough to describe the machine which will take care of or accept this language. So, let me describe a delta for a machine which will accept such this language and we will see that we can do with three states. So, therefore, our q will be q 0 q 1 q 2 and of course, right away I know the sigma is 0 and 1. Now, what I indicated in the previous example that we would use a stack symbol corresponding to 0 and a stack symbol corresponding to 1. And so we would have we said that for 0 we can use a for 1 we can use b and we will also need an you know initial stack symbol which we call this is z 0. So, these are the three symbols which are there in for which will be which can which will constitute the stack alphabet. And now the delta is what I should describe and so let us see how we will go about doing this. So, the idea is simple that supposing I had a string like 0 1 0 0 and 0 0 1 0 the idea is something what we had said before that for whenever so long we are in the first half will keep pushing the corresponding symbol. So, 0 for 0 we should push so initially remember this z 0 is there in the stack. So, a b a a this is what will happen and now after the first half we it is a matter of checking that the string should correspond to this in the manner. So, 0 will correspond to a. So, this will get wiped out and so on and you can see that how do I know when the middle of this you know we have seen the first half that will that the machine will guess and that is when non-determinism comes in. So, it is not difficult to see for this strategy. So, to begin with if I was in the machine is in state q 0 and it c is a 0 and of course, the state the stop of the stack symbol is let us say z 0 then what it should do it should it should push the corresponding symbol. So, it would be in without changing state. So, q then for 0 I had a right. And remember the top of right now what is the top of the stack symbol which is z 0 if I just write q 0 a it would mean z 0 is replaced by a, but that is not what we want to do we want to add this symbol on top of the stack. So, z 0 is replaced by a z 0 then it would mean that this z 0 is there this is replaced by a z 0. So, therefore, in effect what I am doing is I am just pushing the symbol a right similarly delta q 0 1 z 0 it should be q 0 b z 0 right and if we could also the thing is q 0 0 and let us we had now let me just talk of the pushing phase. So, we are in q 0 we see 0 and top of the stack is a then if I consider that it is it is this 0 is part of the first step. So, if I consider the first part then what I should do is of course you know go I should be in the same state and for this 0 I should put an add an a right. We will need something more I will come to that a little later and similarly delta q 0 0 b. This will be q 0 for this 0 I should write an a right this in the we will we will worry about a little later whether anything else is needed there and you know correspondingly we will also have these other two 1 a right. We need to push for 1 a b again I will worry whether I need to put something here and here what I need to do is supposing this is the other thing right 0 0 and here we are doing 1 and suppose I had b q 0 then corresponding to this 1 I would push b we will we will see what it means. Now, I should remember we said that we also need to guess when the middle has come. Now, that can happen whatever symbol you are scanning it is possible in q 0 the middle has come right it is possible. So, we why do not we have one particular epsilon move to go to a state which we should be once the middle has come. So, let me say that state is 1. So, that 1 indicates if we are the machine is in the state q 1 it would indicate that the first half is over and we are in the second half right. So, delta why why do not we simply do this that q 0 on epsilon see at this time we are just making the decision that we have seen the first half right and suppose this is 0 then we go to q 1 and all it means I am sorry this is the third component cannot be 0 it can be either a or b. So, if it is a we do not change this change the thing and similarly delta q 0 epsilon b it is just we are making the we are making the decision that we have seen the first half. So, we just go to on epsilon without doing anything on the stack. So, this will be like that only and in this and you see it is also possible that in q 0 on epsilon the top of the stack is z 0 you will go to q you can go to q 1 and and without changing the top of the stack. When we need to do this because you see in this language can be the string epsilon is in the language right. So, initially the the the the input is empty there is nothing there only an the top of the stack only has z 0 we should we should then of course, decide we should be able to decide in such case that the first half is over. So, this is the thing that we are doing and do you see now the q 0 moves are right. So, this is what is happening now we are in q 0. So, let me now in fact see that this is it right let us see whether and then I need to elaborate what q 1 moves are right. In q 1 the idea is in q 1 I should check out check off right in q 1 if I see a 1 right and then I here top of the stack of symbol is b then that means it is checking out remember 1 corresponds to b. So, I am in the second half. So, let me let me write it. So, delta q 1 that means we are in the second half in the input we are seeing a 0 in the top of the stack symbol is a this is good right this is what we expect that this 0 therefore, can be checked off with the top of the stack symbol by checking off what we mean is that we pop this a. So, now that this particular a has been checked off. So, we remain in q 1 and write epsilon. So, is it clear what is happening in such a case it means the top symbol a is popped when a the a here I have the top stack symbol and here I have epsilon that means for a I am writing epsilon in effect it means that top symbol is being rewritten. So, this is again is a good case we are in the second half as we are in state q 1 we are seeing the symbol 1 here right in the input and on the top on the stack we have b which is fine. So, that means we can check it out. So, that means it will be q 1 epsilon we have defined a transition for you know from state q 1 on both 0 and 1 in the input, but we did not see anything about what happens when this what I am trying to say is that for q 0 I mean this is this is that we are just checking out checking of the stack right 0 checked checked off with a 1 checked off with b here this is this is what is important from q 0 on epsilon we are going to z 0 which is now in q 1 right. If you see a z 0 on top of the stack then what does it mean it could mean that everything is alright right that some string was there the first half which was put on the stack and now z 0 has been exposed because we are in the second half and we are seeing z 0 right. So, that means what so let me write this and delta in q 1 right on epsilon and z 0 on epsilon. And z 0 I should go to a new state q 2 I can say z 0 what and this q 2 will be my final state. So, what I am saying is that we are in the second half we have exposed the bottom of the stack symbol. So, one good possibility is that if the input is also over that means we have taken care of the checking part of the first half because so far we have been successful right. You see the checking part would not be you know we would not succeed if in q 1 we are seeing a 0, but the top of the stack is b. So, in that case we have no transition defined. So, the machine would not proceed any further, but this means it is in the right kind of situation we have checked of all the first half with the second half and now we all that is left in the stack is z 0. So, we should go to a state indicating that we have reached the accepting or final state. So, this is q 2. So, what I am going to do in the next lecture will try to informally at least prove the correctness of what we did you know right now it is looking all very clumsy because so many things are there on the board, but will be able to see once we tell you what is the notion of acceptance that whatever we have done so far indeed will be the machine that would accept this language and will continue with this example after we prove after we define what the notion of acceptance is and then will again look at this example and convince ourselves that this language is indeed accepted by this machine. So, we have actually defined the entire machine we have given the q which is the set of states sigma gamma and delta and we have been we have told you clearly that initial state is q 0 and the z 0 is the initial stack symbol. So, you see the all the seven components we have given for here that is the description of delta all this and initial state is q 0 the initial stack symbol is z 0 and the set of final states is just this state q 2. So, all the seven components of the machine have been defined. So, we have completely actually defined the machine, but we need to convince ourselves that this machine indeed does what we wanted to do.