 In my previous lecture, I introduced the concept called Turing machine, as we see several sophisticated or more complicated languages than regular or context free languages. For that purpose, we have introduced and at that point of time, I have also mentioned that this has both the features of language acceptor as well as features of more and really type of machine giving output also. First, let me recollect what we have discussed in the previous class. I have introduced Turing machine as a quadruple, that is I have written Q sigma delta Q naught, where Q is a finite set, sigma is a finite set delta transition map and Q naught the initial state of this machine. And Q set of states in which H is not part of that the halting state that we are using and we take this special symbol to use blank that is an element of sigma. And we have taken this a total function the transition map that is from Q cross sigma given any state and a symbol. We assign so called the next state can be halting state also and that is either you print a symbol or you move to left or right. This is how we have defined and Q naught is an element of Q called the initial state. This is how I have introduced the notion of Turing machine as a quadruple and I have introduced the concept of computation there like in case of other automaton. So, one step relation is introduced and that is through each transition if you apply a transition on a state and a symbol in a particular configuration. So, this one step relation and configurations are introduced if I write C the set of configurations of a Turing machine. And I have discussed about this one step relation as usual a binary relation on this C and then we talked about reflexive transducer of that and given a Turing machine M the language accepted by a Turing machine M is set of all those strings x in sigma naught star such that if you give in this format infinitely many step you are getting a halting configuration that say y a z. This is how we have discussed where sigma naught is sigma minus blank symbol and I have constructed some Turing machines to accept particular language. We have discussed how to construct those Turing machines and all that and I gave some of some languages some popular languages is known to you earlier to construct a Turing machine. Now, we will introduce the concept of giving output also by the Turing machine here I only thing is I fix some convention under what conditions we say for a particular input x the output is y. So, that kind of convention I have to introduce again I give the input as earlier on the left justified right side infinite tape we have this is the Turing machine I let me call it as the standard Turing machine under discussion. I give the input as earlier say x is given as input and on the right side this blank the reading and writing head we keep this is the instantaneous description or configuration we call this is how we start and after finitely many steps we will whatever the output that you are expecting y we should live with this format and again the reading and writing head is here. By fixing this convention we get certain advantages that we will discuss and you will realize after you know one or two lectures that why we are fixing this kind of convention because we see a lot of variance in the literature the various books when you are looking at you can see that. If you are expecting y as output you may print y in place of x itself because by arising x or whatever ultimately on the tape if you are left with y then you are happy. So, it is just a convention that the output how do you expect on the tape because unlike in case of millimission that we have discussed there you have a separate tape for output and given an input on the input tape the output is anyway shown up the required output is shown up on the output tape. Here both input and output we have for both of them we have only one tape thus we can have certain convention to report the output. Here for my lectures I fix this convention that the input will be given as usual that we are giving in case of language acceptance, but the output I expect again in the format that first cell should be blank and what are the output expected that should be printed say y and then on the right blank I will be halting with the halting state. In the beginning you are with the initial state say q naught and you are when you are halting you will be halting with the halting state like this. So, this is how we expect the output. Now, let me formally give this definition let f from sigma 1 star to sigma 2 star a function where sigma 1 and sigma 2 2 alphabet are not containing the special symbol blank. You take a function we say a Turing machine say m q sigma delta q naught is said to compute the function f. If this 2 alphabet sigma 1 sigma 2 are subsets of sigma and for any x in sigma 1 star and y in sigma 2 star if y is image of x under f then give x as input and you expect y as output as per our convention and conversely that is with the initial configuration. So, if you start with something and by the time it halts and by the time it halts by leaving some output y then that has to be image under the function f that is the meaning if and only if. Look here that x is if y is image of x under f then y has to come as output and whatever the output for any string you are getting that has to be the image. So, that is why we are writing if and only if. So, under these conditions we say the function f is computed by the Turing machine m. Now, a function f sigma 1 star to sigma 2 star is said to be Turing computable or simply computable computable if there is a Turing machine that computes this another definition. So, when do we say a to a function is computable. Now, we have mentioned when we say a Turing machine computes f. So, this definition we have now. So, to compute a function we have to construct a Turing machine with this convention then that particular function we may call it as a computable function or more precisely Turing computable function because we are constructing a Turing machine to compute that function. So, this is another notion that I talk about other than the language acceptance with respect to Turing machines and let me just point out that the languages that are accepted by Turing machines are Turing acceptable language I may say or I may also call one may say that is recursively enumerable languages. So, let me just point out this a Turing acceptable language is also called as recursively enumerable language. Now, we see that we construct Turing machines as of now for two purposes one Turing acceptable languages or recursively enumerable languages or for Turing computable functions. Now, let me continue with few more examples. So, that you can get familiar with the notion of Turing machine or the constructing Turing machine for certain purpose. So, let me just take this your homework example that is a power n b power n such that n greater than equal to 0 this I have asked you to construct a Turing machine what type of checking that we conduct the Turing machine because in for this language when we have constructed push down automaton you are reading of course, there from left to right because there is nothing like moving left and right we have only one direction moving that is with the usual convention that moving from left to right side. As long as you are getting yes you are putting yes into stack that is how we are remembering and once you start getting b's you are matching with the number of yes that are already in the stack if they are matching then you are accepting otherwise you are rejecting there in case of push down automaton. Here we do not have any other memory device memory here like stack here we have we can go back and forth on the tape and that is how we will actually do the matching as you see that if a power n b power n certain number of a's followed by certain number of b's are given you simply go back and forth and keep matching with the symbols and because there is nothing like counting and remembering here the things are given it is something like you just match them and understand whether it is of the form a power n b power n or not. So, if the x is some x is given as input the first cell anyway as usual blank if x is given as input that means say for example, certain number of a's and followed by certain number of b's that is the required thing to be accepted and reading at writing at is here you start with the initial state say for example, q naught and take a left move just if this is empty string that should be accepted because when n equal to 0 a power n b power n this string is epsilon that is the empty string then it should be accepted. So, just to distinguish this blank this blank and this blank I will change the state. So, when I go to left side if I get the blank in the beginning or in the beginning then I will simply accept it when you get a b that is when the process starts if you get a clearly the string is not of the form a power n b power n therefore, you can put it in infinite loop or you can make it you can make the machine hang. So, this first checking condition will be if I get to b what I have to do that I have to pursue I may do this I will make blank cell here I will go till this end and cross check take a right move and cross check whether corresponding to this b whether there is an a if there is an a then I will mark it may be I will make it blank then I will go to right till the blank then I will take a left move and see whether there is a blank and if there is blank then corresponding to this a. So, there is only a b as input if there is another b then I continue this process as earlier if there is an a again the input is not in the required form to accept. So, that is how this loop I can continue and eventually if it is in the required form I have to accept in the halting state. So, let me just give you the transition map with this logic let me start with the symbols of course, you are allowed to take more and more symbols in sigma. So, let me start with in the initial state I am reading blank I will take a left move by changing the state to q 1 q 1 indicates that I have started reading the input if that is blank then we can simply accept. So, halt by say let me print there itself blank and halt you can do whatever you can go to you can take a right move and halt, but you should ensure that you should not take a left move here. So, if you take a left move it hangs. So, I put it in halting state make blank and there is another possibility that you may get a b positively I mean. So, in which case I understand that by changing state say q 2 and I will make it blank. So, when I am in q 2 when I am in q 2 I know that I am reading blank. So, I am not going to read any a or b. So, this is the cell I require some information. So, I will change say for example, to q 3 and take a left move. So, that means I have just mark b and I have to go till left end and I have to see whether there is an a at the end of at the beginning here. So, this q 3 is indicating that I have just mark b and I am going to cross check whether there is an a. So, in q 3 I continue till the left end. So, that will be recognized by blank. So, if I get a s or b s in between on the way I will keep going to left. So, that is q 3 left even if I get b in q 3 I can continue if I am getting blank. Now, I recognize that is how this blank is required. If there is no such special marking here on the tape we will go and hang because what to cross check because input is if it is in the from the beginning. So, that is how I hope now you understand that why we require some special symbol in the beginning. When I am going when I am when I start reading the input from right and going to left. So, we require a special symbol in the beginning of the tape that is how we have introduced this. So, once you receive blank then I can take a right move and let me indicate that by changing a state. So, q 3 say let me go to q 4 and take a right move in q 4 what is expected in q 4 we expect that there has to be a. So, I will look for that positively suppose there is an a then I will change the state to q 5 and print and mark it that. So, we are as that by printing blank there. So, in q 5 of course, I know that I will be reading the blank only because just we have printed blank. So, let me change the state. So, say for example, q 6 and move to right and in q 6 now I have to go all the way till the end till right end. So, if I get a s or b s I will continue on the tape by continuing the same states say q 6 or till I reach to the blank. Once I reach to the right end the blank you know that in the beginning when I am in the initial state q naught I take a left move by moving to the state q 1. So, here the same thing we can do. So, that it will continue to the loop. So, I will change to q 1 and take a left move again. Now, you see if there is another b and corresponding to which if there is another a in the beginning of the tape as per this whatever we have defined in q 1 you are reading b change to the state q 2 and in q 2 you are reading blank we know because we have just printed blank no other symbol is possible. So, q 3 we are changing to the state q 3 and moving to left and in q 3 you keep continuing to the left and till you reach blank because in the beginning we have the first year we have a rest. So, there is a blank there. So, till that point it will go and take a right move there and positively we are expecting an a there. So, in which case we are changing the state to q 5 and in q 5 of course, since we have printed just blank you are reading blank. So, that change to the state q 6 and q 6 you can continue till right hand. So, this loop continues if you have say for example, 3 a's and 3 b's the loop will continue for 3 times. If you have say for example, 4 a's followed by 4 b's the loop continues for 4 times and so on. Now, let us look at other part. Now, for example, in the beginning here if you get a. So, this is the cell that we have to look at. In this case we put say for example, in q 7 and ask to move to right because this is not desired in the state q 1 I am not expecting to read a for the desired string in the language. So, I will put it in the state say for example, q 7 and in q 7 what I will do I will keep moving to right. So, that the machine goes to that infinite on to the it will run on in the infinite tape. So, I will continue in q 7 and keep going to right. So, q 7 keep going to right q 7 keep going to right. So, this takes the machine to the infinite tape and it never halts because there are you know that is the right side infinite tape. So, in q 1 I am not expecting to read a. So, if I am reaching that then this is what we are being in q 2 we have printed blank and therefore, in q 2 a and b you would not get at all. So, since delta is a total function we have to define it as a total function because for every state and the input symbol we have to give definition. So, you give something arbitrarily let me use the symbol a to say that arbitrarily we define let me let me give something later this thing. Similarly, in the initial state as per our convention we start with the blank cell that is on the right side of the input. So, a and b are also not expected because we are not continuing in q naught once you come on to the input I am changing the state to q 1. So, these two are arbitrarily I will define something. Now, look at in case of this q 4. So, what is the meaning of q 4 that I reach it to the left hand and took a right turn if I if I get a then I am ok if I get b then this is a mismatch for the pattern. So, now I can put it in q 7 and ask it to go to right. Similarly, I have if I have consumed a b if I have noted a b corresponding to that if there is no a if there is only blank then also I will put it in the infinite loop this is how I can do and in q 5 q 5 means currently I am reading blank I have just by when you are changing to the state q 5 we have printed blank there. So, we will be reading blank only we are not going to get a or b or any other symbol. So, these two places again you can define anything arbitrarily. So, for this a something since we have to give some state component let me put say q naught and something may be asking it to go to right or whatever because this situation would not arise wherever the cell I have written a that situation would not arise, but since by definition delta is a total function for every state and a symbol I should have some definition. So, let me say define with this state component q naught and something I have to define I am just saying r. So, this is how I declare and with this definition if you set the Turing mission. Now, the state set is where a is this now set q to be the states q naught 2 I have till q 7 sigma is a b blank delta has defined here if you consider m this q sigma delta is defined here and q naught is a Turing mission such that the language accepted by m is the one we have asked. What do you do you just do some computations on it and realize that this precisely accept this language let me just do some computations and observe this. So, in the initial state if you are given say a a b b this is the initial configuration as per our definition it will go to q 1 blank a a b b and in the next step it will print blank at that place a a b this is the situation and in q 2 of course I read blank then I change to q 3 and go to left and in q 3 I keep moving to this till left end of course here one step I come on to this a and the next step next a and come on blank. So, in 3 steps I will be let me indicate that in 3 steps I will get this kind this configuration and when I have blank in q 3 I will change it to q 4 and go to right. So, now the state is q 4 and I make a right move. So, this is the configuration and in q 4 if I am getting a I will change it to q 5 and make it blank q 5 and this is made blank that is the situation and in q 5 of course I will be reading blank. So, I change it to q 6 and go to right q 6 and we go to right that means the current cell is this and in q 6 I continue to move to right that is how it is defined. So, q 6 while reading a or b we move to right. So, this is blank blank a b this is one one step in another step also we will move that is q 6 blank blank a b now I go to this. So, I will get blank here now in q 6 when I receive blank then I will change to q 1 and go to left that is the idea here. So, I will come to q 1 and take a left move now as earlier when I read blank it will print when I read b it will print blank there change it to q 2 and in q 2 I am reading blank I will change it to I will change it to q 3 and keep moving to left till I go to this blank. So, here let me just after finitely many steps of course here making here it is blank that is one and in q 3 I will continue to this position and at this blank this indicates that I have reached to this I do not have b now because we made it blank there. Now, in q 3 again I take a right move by changing to q 4 changing to q 4 and now the current situation is this in q 4 when I am reading a we converted to blank. So, that is q 5 this situation now in q 5 I am reading blank it will change to q 6 and take a right move in q 6 it will take a right move. So, you get this configuration and in q 6 you take when you are getting blank it will take a left move. So, that is now q 1 blank blank blank this is the because in q 6 when I am reading blank the configuration the definition is will change to the state q 1 and take a left move this is the transition. So, by applying the transition I get this in q 1 when I have blank then it halts by printing blank there. Now, in the next step we go to halting state by printing blank in a third cell of course, this is the final configuration. So, with this computation you see that a a b b is accepted and if you consider a a a b b b say a cube b cube then the same thing you can see that this will continue this loop will continue and finally, you will come to the halting state. For example, if there is a string ending with a you as per the definition here in q 1 if you are getting a I am going to q 7 then thus it will go to the infinite loop of going to write keep going to write on the infinite tip or for example, you have a b, but corresponding to which if there is no a I will come to the situation that in q 4 I am cross checking whether there is a otherwise I am putting in this I am we are defining this transition that is q 7 r and thus it is going to again on the right on the infinite tip it keep it will move on the infinite tip. So, the string will not be accepted and what are all the other patterns which is not of the form a power n b power n because this is a total function here what we have defined delta is a total function. So, you give any situation of the input we have defined something here and you see what are the possibilities that we have defined and through which we can argue that because there are only finitely many transitions and the transitions are having certain pattern because we have followed certain logic. So, you can apply the pattern and prove that this transition will give this transition will accept the language a power n b power n and delta n equal to 0. So, you look at the pattern of input and argue on and we can of course, prove that this language actually this Turing mission is precisely L. So, now you can of course, do this kind of computation just to realize that if some other string is given as input what is happening. Now, as I have introduced the notion of Turing computable function let me now give you a function and constructed Turing mission compute that particular function a simple function here that is let me take F 1 from a b star to I will call it as again a b star such that F 1 of any x is equal to the identity function so called. So, whatever is the input that you give you have to get the same output. So, here in this case. So, the input is expected this way as I have mentioned but, originally it is in q naught and what I have to give after finitely many steps I should leave this with the halting state. You can quickly guess what sort of machine should be that and what type of transitions that we have to define there very simple you take one initial state and then immediately you halt it because, the water is the input you want to leave the same as output. So, here I need not do any anything here and we can pursue the job very quickly. So, the Turing mission very quickly one can easily say that because, the alphabet is this. So, the transition with one state I can give and you define anything arbitrarily. So, I have only one state. So, I can as I can whatever that you are reading of course, I will read blank. So, there I have to halt we know but, I should not take here the chance of moving I have to print blank here because, so that the reading and writing at there only. Here also let me just say anything arbitrarily you define here that does not matter because, we are not going to encounter in the initial state q naught a or b we are not moving the head. So, this transitions this the Turing mission with this transitions precisely compute this function as you understand quickly from the transitions defined here. It is a very trivial Turing computable function you see let me now give this little non trivial but, of course you realize that this is also a trivial function u a b star to let me say for the sake a b star only. Now, f 2 I define for all x I will send it to the empty string. So, here what we have to do whatever is on the tape we have to erase it and leave the tape because, the epsilon when we are putting this as input for example, the obviously the format is as per our convention. The first cell is blank and here I have to put x and then on the right side of that particular input I have to be there. So, epsilon will be indicated by this is what is epsilon on the tape will be indicated by this as input of course, of course as output here we have to see. So, that means if you start with the tape of this format starting here say initial state q naught after finitely many steps we will come to the halting state by having you know having this as of this configuration. How do we define this we just take a left to move as long as you are getting a s or b s keep erasing it once you get blank you just take a right move and simply halt this is the logic I define it here. So, the delta transition function of the Turing machine I am going to construct take say in q naught just to distinguish that I have started the process. So, I will change it to q 1 and take a left move and in q 1 if I get a say I will go to q 2 make it blank or even if I get b will go to q 2 make it blank in q 2 of course I am reading blank. So, I will change it to q 1 and take a left move or I can of course write instead of writing here the transitions q 2 I can say q naught does not matter we can reduce the number of states there. I am not worried about how many states that I am using at this point of time. So, I will simply say that I am changing to the state q 2 and in q 2 I am reading blank. So, it will again to pursue this job I change it to q 1 and take a left move in q 1 when I get again a it changes to q 2 and print blank and b print blank in q 1 if I am reaching to this state I mean in this situation having blank then I take a right move and halt. So, that I have arranged everything in q 2 since I am reading blank I have only this possibility and similarly in the beginning I do not have I do not have to read any non empty cell only blank cell. So, here arbitrarily you define anything because we have to define something as delta is a total function in the definition say here a can be something. So, with this transition function whatever the Turing machine I construct because the states are clear there are 3 states symbols are there and the delta I have defined declare q net is initial state. Now, this Turing machine clearly pursues the job that as desired to show that the function f 2 is a Turing computable function this machine simply arises the tape and leaves the blank tape not blank tape essentially the as epsilon as output. So, these are little understandable very quickly little trivial one more for the sake of understanding this let me consider for the change of the situation. So, let me use 0 1 star and what do I do f 3 of x is y where y is obtained from x by replacing 0 in place of in place of say a and 1 in place of b wherever you have b you place it with 1 wherever you have a you place it with 0. I hope it is very simple phenomena and you can understand this function how this is defined for epsilon the out the image is epsilon. So, what essentially you have to do you keep going to left as long as you are getting a whenever you get a you print it print 0 there when you are getting 1 you print you print sorry whenever you are getting b you print 1 there till you go to the end of the tape left hand that is indicated by blank then you take a right one keep going to right till reaching to the end. So, take this as an exercise that this is a Turing compatible function now the point is you look here some of this because so far I have handled just very simple examples as a Turing compatible function or Turing acceptable languages in just in case of a power and b power in itself I have used about 7 states and any other language now you can try for all those palindromes you can in a similar way you can try or I have asked to construct a Turing mission to accept the language say a power and b power and c power n greater than equal to 0. So, you require one more sort of check it is not just reading after b we have checked for a if it is a power and b power and c power n then you have to see that corresponding to each symbol whether there is in this respective pattern or not those things we have to cross check. As long as the symbols are increasing or the checks the loop whatever that we define we are choosing certain new states and that is how we are creating the memory. And for simple examples for simple examples we see that you here you would require several states sometimes you know for very simple examples that we have already constructed for regular languages or contrast language type of things themselves you may have to require some 20 state 30 states like that and the transition function you know looks very complicated because you have to go through carefully the transitions are carefully defined and the places and everything. Now if you look at some sophisticated more complicated languages or compatible functions the type of Turing mission that you would you are going to construct will be more and more cumbersome to see you would construct and you may verify you can always prove that whatever the transition function that you have constructed does the job the desired job. But the point is if there are for example multiplication addition and this kind of things you know you can do it using computer. So, this as we have mentioned that this Turing mission is essentially taking care of the things that you can handle using usual computer there are several things that you see that you can do it using your usual computer. So, for certain simple phenomenon if you have to require say for example 100 states 200 states and 1 lakh or that order then it will be very difficult to really write and see. So, in this direction I will introduce a short hand a notation short notation while constructing the Turing mission we will follow that notation and try to decrease this complexity in seeing or in understanding the construction of that particular Turing mission. First in the direction first let us first realize what are the basic Turing missions possible and first and what are the Turing missions that we construct and those Turing missions we further use to construct some of the complicated missions wherever it is required. So, this is the logic that we follow to construct the to introduce this notation a short hand for constructing a Turing mission. In the direction first we realize what are the basic Turing missions and some of the basic Turing missions which you may quite often you use I may give some fixed symbols for that and those symbols whenever you recall we assume that this Turing mission that you have already constructed and now I can make use of that like in your programming you would have written certain modules certain procedures in a bigger program and whenever you require you can of course call it and continue with this. But, only thing is here we have to take care that whenever you are connecting to a particular Turing mission the pattern of the input is essentially as required to the mission that you have constructed earlier and whatever that output that you are getting or whatever if it is accepting or whatever. So, the time it is actually halting where we are actually leaving the tape that is very important and now I can make this point clear that why we have to follow a fixed convention here because starting here and ending here that kind of convention what we are following. So, that in this particular for this particular cause this is this convention is very useful. Now, let me start with looking at basic Turing missions and then we will try to see that how to construct certain complicated Turing missions with using this easy notation. One can quickly realize that Turing mission the basic operations it is doing is it is moving of course it is reading and writing head moving to a cell left from the current cell from the current cell or it is moving to a cell right from the current cell or in the current cell on the tape it would print some symbol these are the three possible transitions current cell it prints a symbol. So, these are the three things the basic things that a Turing mission is doing. Now, if I want a Turing mission wherever it is currently it has to just move one cell left and hard. Let me call the Turing mission with this L this is the name of the Turing mission and similarly if I write R is the Turing mission that takes a right move from the current cell and hards. And for all a in sigma I write P a the Turing mission that prints a in the current cell and hards defining these Turing missions is very easy it is not a big deal because for L you can construct a Turing mission like this this transition. So, let me call it as delta L whatever the input symbols let me a 1 a 2 a n say what are all the symbols that you have I take one states say initials the initial state q naught wherever I am I will just hard by taking a left move that is how you can define and so on. So, that is the transition function delta L is defined such a way that this q naught at any symbol a this is hard by taking a left move for all a in sigma this is the Turing mission. Similarly, one can look for delta R that you can define take one states that is the initial state for all symbols you define it as hard by taking a right move for all a in sigma and now if I write here delta a here I take one state that is the initial state what are the symbol currently I am reading let me use now say b a variable here I hard by printing a in the current cell for all b in sigma. So, if you define things like this this Turing missions precisely they do whatever that is required as mentioned here the Turing mission L whatever it is the current cell from which it will take one left move and holds and the Turing mission R that takes a right move and holds from the current cell P a the Turing mission which prints a in the current cell and simply holds whatever it is reading in the current cell. So, these are the basic operations are these are the basic type of transitions that we are realizing in a Turing mission. So, these things are now I have used L R P a for this basic Turing missions. So, using this basic Turing missions how to construct certain complicated Turing missions and what is the formal way of constructing the everything that we will discuss in a next class. Now, since we have discussed how what is a Turing acceptable language what is a Turing computable function how to construct a Turing mission using the state phenomena you construct certain Turing missions and see that how many states actually you are requiring and all those things. So, let me give certain problems. So, f from say a b star to a b star you define why say f of x is equal to x power r reversal of the string and prove that this is Turing computable Turing computable functions. So, we will we see this let me take say g a b star for example, 0 1 star g of x take a string that you create let me put say a b star only it is x say x power r say h a b star to a b star x x of course, I will give few more examples and these are the very simple in this line up and you see that these are for the simple examples how many states that you are requiring and how the notion of giving a short notation to construct a Turing mission is useful that you will realize. So, construct Turing missions to show that these functions are to be compatible and such and similar functions that you can take and construct Turing missions. We will discuss construct giving short notation in the next class.