 Now, what we shall prove now that there are languages which are recursively enumerable but not recursive. We will try to prove existence of RE or existence of languages which are RE that is recursively enumerable but not recursive. In particular, we will show that LU is RE but not recursive. Definition of the language LU is if you recall is this that set of. So, this notation stands for that you are given as input a string which encodes a pair and first element of that pair is the code of some machine Turing machine M and the second one is a string W. So, we will show that this language to be recursively enumerable but not recursive. And therefore, if we go back to the picture that we drew last time that this square box if you imagine it to be the set of all languages over sigma subset of it is recursively enumerable languages. And it is a proper subset because we had seen the diagonal language LD is of course, a language over sigma but it is not recursively enumerable. So, we have a set of RE languages and then by definition set of recursive languages will be a subset of RE languages because it comes from definition because you see a recursive language is a language which is accepted by a Turing machine which holds on all inputs. The first condition that a language is accepted by all excuse me a language which is accepted by a Turing machine means it is a RE language. So, recursive languages are by definition recursively enumerable languages. So, we drew a subset and the question is that whether this subset is a proper subset whether the set of recursive languages that set is a proper subset of the set of all recursively enumerable languages. When we prove this that LU is recursively enumerable but not recursive we show the separation between these two sets recursive and recursively enumerable. We show that the separation is strict and in fact LU is such a language which is RE but not recursive. So, you can see that we need to do two things to show that LU is RE that is 0.1 the 0.2 is LU is not recursive and we will do it one by one. So, let us first prove that LU is RE. So, we we prove this that LU is RE by demonstrating something which is very important but fairly simple that is the existence of universal Turing machines. So, right now we are trying to prove that LU is RE and for the proof of this statement will first of all require that a particular kind of Turing machine which is called universal Turing machine such a Turing machine exists. In fact, the name LU, LU stands for this U stands for universal. Now, what is a universal machine? Universal machine is one fixed Turing machine which can simulate other Turing machines so far as language recognition is concerned for the purpose of language recognition that is the simulation should be such that that this fixed machine will be able to tell you whether any given M accepts its own input or whatever input you have given to that machine M or not. So, essentially universal Turing machine so if I write it like this abbreviation UTM. So, UTM is a fixed machine fixed TM and what such a TM can do is that such a TM so this is your UTM it is on its input tape two things will be given one is the code of a Turing machine and a particular string W and this UTM will decide or not decide really this what it will do is that it will simulate the working of M on W step by step and because it is simulating M on W step by step if ever M accepts W UTM will know that M would have accepted W and therefore, it would accept its input now its input was the spare MW. So, this UTM therefore, the language accepted by UTM by the way we have described it is clearly LU by now it should not be very surprising to you how why such a you such a machine exists. So, let us see after all what do we mean by we have given the code of a Turing machine M code we said that is something we have done before code of a machine is in terms of its quintuples and so the code of M is really a string which is essentially the quintuples of that machine each quintuple is coded if you recall as a five tuple of numbers each number was represented in a unary form all that we know this quintuples were separated by some double zeros this is quintuple 1 quintuple 2 etcetera right. And we have some further let us say conventions that is the state numbered 1 or numbered 0 maybe we can start with 0 state numbered 0 basically what otherwise you would have called as q 0 whose such a state numbered 0. That means, it is the number is 0 and its representation in unary is 1 this state is the initial state and we also said the state numbered 1 is the unique accepting state now this UTM what will it what will it have is maybe it will it will have a few other tapes and what one of these tapes will be is to carry the coding of the tape of M as it works on W right imagine this last tape is the coding of the tape we are assuming M is a one tape machine and the code of that tape will be appearing here. Now, why do we not directly work with the tape as M would have seen it or as M state see the reason is UTM is a fixed machine has a fixed alphabet problem basic problem that non matching of UTM tape alphabet with the alphabet of M by the in the manner in which we coded M itself because you see even for the quintuples of M we need to state the symbols that M uses. So, we do not really use the symbols directly they are there those symbols as such are of no importance, but if we what we code them by unary numbers and therefore, since 0 and 1 we are assumed to be in the tape alphabet of UTM we can at least express the coded version of every symbol of M for UTM to work on. So, this tape as I said this last tape is the coding of the tape of M on W right without any loss of generally you may assume that sigma is that is the input alphabet of M is a subset of the tape alphabet also we can assume that blank symbol it is we see the blank symbol is same it is the same symbol let us see the same symbol acts as the blank symbol for both M and the machine UTM universal Turing machine. So, non blank portion initially we will have W right. So, what UTM can right away do that it can copy the W in the beginning here and also it can copy let us say after some special symbol the code of M. Code of M recall will be the quintuples of 1 quintuple 1 followed by quintuple 2 quintuple 3 and so on that is the code of the machine right. And let us also say that this part before this dollar it uses something the space here you can imagine that it will use this part will store the current symbol. So, let us say or the coding of the current symbol. So, let me write it as S to say coding of the current symbol and this part which may be a number of cells all these are it will consist contain coding again in unary of the current state. And these two are separated by two zeroes all right. So, let me draw this part a little more clearly here for better readability what we are saying is our intent is this part will have code of present state and this part will have code of symbol currently being read by M. So, see we are saying present the word we are using present we are using the word current. So, this is in the context that we imagine that M which you want to simulate is working on W. And it is going from step to step at every step it has it is in some state that is the code that is the state present state of M. So, let us say code of present state of M and at that time the particular beginning of a move of M is reading a particular symbol and its code appears here then what we have said that there is this dollar and here we have code of M. Recall as I said that code of M is nothing but quintuples one after another in the beginning what is what will be in the beginning in the sense in the beginning of M's work on W. The state is going to be the initial state which we just said is the zeroeth state and that code of that state is just the number just the string I mean unary string one and here code of the current symbol. So, here whatever is the symbol in W the first symbol let us say A and as we said the tape you do not need to code sigma. So, it is we can say the A is there. Now, we will just have the convention we are just making one convention and that we can follow that in the in coding the quintuples if a symbol from sigma appears that will write directly we would not code it in unary. So, this is there and otherwise the tape therefore the the the tape coded version of the tape of M as it works on W would consist of symbols from sigma which will directly write and you know we can we can have some coding for symbols which of course they are not there in not in sigma those symbols will code them in unary and separate them by some special symbol. So, let us say some cent and then and then here it we may have something like A B 1 you know maybe 0 which is. So, this is how the coded or the last or the lowest tape of UTM lowest tape is this one tape of UTM will look like something like this. Of course, there will be lots of blanks because blank symbols are common for both now you see. So, what we said is initially suppose the symbol A is the first symbol of W that we can copy in this part which is the expanded version here and this we call the buffer region. So, buffer contains the code of the present state of M code of the symbol currently being read by M and now what would be the action of M when it is in this state and reading the this symbol that is defined precisely by a quintuple whose first two components are these two separated by two zeros we also assume that you know there is no confusion that these two zeros are separating the coding of the state and coding of the thing the symbol. So, now at any given time. So, now imagine dynamically what is the situation how does UTM simulate the working of M and W at any given time M would have been scanning a particular symbol and it will be in some particular state at that for that at that time the buffer would be filled in the appropriate manner and now UTM would like to know what would be the next state of M what is the symbol that will be written and what will be the direction of move. So, in general the UTM would this the head of this tape will be scanning the left most of the code of the current symbol being scanned. So, as I said and then these these are appropriately written imagine that that has happened and now by scanning the code of M UTM would know what would have been the next state. So, next state suppose is the third state. So, therefore, this has to be updated by the code of that state three which is of course, the number the the unary representation of three is four ones and so we write that and now it also knows from the code of M you see which is the next the the symbol to be printed. So, let us say the symbol to be printed is the seventh symbol. So, that is one one one one one one one. So, the number seven is of course, represented in unary by eight ones this part will come here and now what UTM would do is to appropriately update two things here see somewhere that at this position the whatever was what was there previously is the content will be the code of the symbol that was just read in its place this should come. So, essentially it should copy this part here now only problem is you know this may be of the lengths may mismatch right this may be small the code of that symbol may be small and code of this new symbol to be written there is large. So, it has to shift some symbols to accommodate all these similarly it might have to push some symbols from right hand side to create a smaller space if the new symbol to be written there had a code whose length is less than the code of the symbol that was previously there. So, this is correctly updated and again the appropriate quintuple would say that whether the head will move to the left or to the right. So, if it is move if it is supposed to move to the left you know it will supposing it was here with updated the correctly the symbol that it was reading previously and then it positions itself to the beginning of the this code of the symbol which m step would have appeared left to the present or the symbol right. So, now it comes here and we are back in the beginning of the simulation of a another next step of m because correctly now we have the present state present symbol and the head is at the right place this will go on some details need to be worked out because of the way we said that you know in not all symbols are codes of coded, but some symbols are directly written. So, in that case if it sees a symbol which is directly written and it will just move one step otherwise if it was to move left otherwise it will move back to the previous sent sign and then position itself appropriately. So, what I am trying to say that this is not difficult to see that every step of m on W can be simulated by the UTM with a number of steps. So, therefore, if ever m goes to an accepting state as it works on W UTM would know that because you see every time whenever the new state information is comes here it can check whether it is the accepting state or not if the accepting state is reached then m would accept or rather the UTM would accept its input UTM's input was recall m and W. So, what are the inputs it is accepting it is accepting those inputs such that m accepts W. So, precisely it is accepting the language LU and since we have a Turing machine to accept the language LU that shows that the language LU is recursively enumerable. So, we have shown existence of UTM proves it is very clear that the only inputs UTM would accept the UTM would accept its input only when in this in the during the simulation it finds the accepting the accepting state would have been reached by the machine which is being simulated otherwise it will just carry on with another step of simulation of this machine that is being simulated. So, since it accepts all and only inputs m W such that m accepts W it precisely accepts the language LU. So, first part of our job in proving existence of recursively enumerable languages which are not recursive is done because our candidate for that was LU and we have proved that LU is recursively enumerable. What is now left is to show that LU is not recursive or next task is to show LU is not recursive. This is very simple because you see idea is if LU was recursive then LD would become recursive. Recall what was LD? LD was this language these are all binary strings the machine whose code is X and we had proved that LD is not recursive. So, now imagine LU is recursive assume LU is recursive. So, then we would have a Turing machine m some Turing machine m which would say yes on an input like this m W it will always hold and saying yes if m accepts W and no if m does not accept W. If LU is recursive then such a Turing machine would be there because LU is recursive means LU would be accepted by a Turing machine which always holds and therefore, if it holds in a non accepting thing state you know that m does not accept W if it holds in an accepting state then m accepts W. Now, what you can do therefore, imagine something like this that suppose you had some X. Now X from here you have very simple transformer which codes X X. So, from X it creates a pair X and X. But now you can think of this X is a code of a machine and this X is a input to that machine and now here you have m and if m would have said yes that m would have accepted that means the machine whose code is X accepts X and here no means machine whose code is X does not accept X and here your final output if m would have not accepted then this algorithm would accept and if m would have accepted this algorithm does not accept. So, what I am saying is imagine a new algorithm or a Turing machine because this is very simple you just imagine a Turing machine which takes one string as input creates a pair out of it then invokes the machine which always holds and accepts LU and depending on whether that machine is accepting or rejecting the input if it is accept it would have accepted the input which input m's input is X X then this composite machine is going to reject its original input X otherwise it is no. It is very clear what is this composite machine do it. This composite machine would be accepting see it is accepting here so yes by that we mean accept it accepts if m would have rejected m would have rejected means the machine whose code is X accepts X does not accept X only that is the reason m would have rejected this m rejects its input X X if and only if machine whose code is X does not accept X that means the string X is in the language L T and otherwise the string X would is not in the language L T. So, this whole thing is a machine Turing machine that always holds and so this Turing machine always holds you see because this obviously can be done by a machine this transformation can be done fairly simply and trivially and that there is no problem there is no question of non halting in doing this transformation and this by definition always holds and depending on the answer you are just giving a certain answer just switching the two answers. So, in that case this is the machine which always holds and it precisely accepts the language L D. So, that means what that if such a machine exists in other words if L U is recursive then L D is recursive, but we know L D is not recursive because it is not even recursively innumerable. So, from here the conclusion is L U is not recursively not recursive. So, you have shown both these two things we have proved that one L U is R E and second thing we just now proved L U is not recursive. So, therefore, the class R E we can say like this the class R E is a proper superset of the class recursive. So, indeed the old picture that we drew the two circles remember that we said that this is the class of all languages this is the R E languages this is the recursive languages right. So, here is L U here is L D and so therefore, recursive is a proper subset of R E. Now, what about the complement of R E complement of L U clearly since L U is not recursive since L U is not recursive, but R E L U complement is not R E because if L U of course, we know L U is recursively innumerable if L U complement is also recursively innumerable then L U would have been recursive, but we know L U is not recursive. So, L U complement is not recursively innumerable. So, you see I mean you have these cases that both L D I mean take this language L U its complement is not recursively innumerable it comes here. So, this also shows this simple observation also shows that R E languages are not closed under this is a property of R E languages whereas, of course, recursive languages are closed under complement. We will first of all very briefly review some things which you have talked about earlier notion of membership decision problem. A membership decision problem is that the membership decision problem. So, membership of what membership of some set A is set and the kind of problem you have is that you are given an input which is x and to decide what you need to decide is whether x is in A or x is not in A. So, in case x is in A you will say yes x is in A and no you will say no if x is not in A. So, if we have an algorithm to do this correctly then we say that the membership decision problem of A is decidable and this is called a decision algorithm. Existence of a decision algorithm makes this corresponding problem decision problem membership decision problem decidable. What does it mean to say a decision problem is undecidable that means no such algorithm exists. Now, also this is there is a correspondence between this notion of problem decision problem membership decision problem being decidable and the notion of recursiveness. Consider this set or language the point is and this is fairly simple to see LA is recursive if and only if decision problem I am not writing membership decision because in the context it is clear membership decision problem for A is decidable. Let us go through the argument quickly suppose A is recursive. So, there is a Turing machine which always holds and accepts only the strings which are in A the set A. So, now you can create an algorithm for solving the decision problem is that given the input x you essentially run that Turing machine M. If the Turing machine goes to an accepting state you say yes otherwise you say no. Since M precisely M always holds. So, either it holds in an accepting state or in an you know state which is not accepting. So, in case it holds in an accepting state you know that x is in A this condition is satisfied by the input and therefore, answer of the decision is yes otherwise it is no. And similarly on the other hand if I have an algorithm for the decision problem for A then we have said if something can be done by any algorithm by church Turing thesis it can be done by a Turing machine. So, there is a Turing machine to decide whether an input x is in A or not and just turn it into a recognizer that same Turing machine by going to an accepting state if you know the input x is accepted by or input x is in the set A. So, essentially from an algorithm by invoking church Turing hypothesis we say we claim the existence of a Turing machine which solves the decision problem and from a solution of decision problem by a Turing machine we get a recognizer for the language LA. So, this is clear. So, some decision problem is undecidable. So, of course, corresponding to every decision problem we can create the set of yes instances as we did here and that is a language and if the decision problem is undecidable that means the corresponding language of yes instances is not recursive. So, what I am trying to say is that undecidability proves essentially can be couched in the language of languages show the corresponding language to be not recursive. But one particular problem of undecidability we would like to prove directly that it is undecidable because that problem is so well known and all of you might have I mean I am sure most of you would have heard of this problem and that is called the halting problem. So, halting problem is not really a language problem, but here what we want though it is about Turing machines the problem is like this. In state the problem this way that as input you will be given code of a Turing machine and some string let us say W. What you are supposed to decide output is if M holds Turing machine on W as input and output no if M does not. So, essentially we are looking for an algorithm which will decide given any Turing machine and some string which is it considered as its input whether the Turing machine would have halted on that string or not. Now this is a classical problem and it is known that halting problem is undecidable. Halting problem is undecidable we will try to prove this end of directly you will see how it is done the proof is by contradiction. So, we will assume we will start by saying that suppose halting problem is indeed decidable that means what there exists some algorithm which decides given M and W as input whether M holds on W or not. Now existence of such an algorithm immediately means through church Turing. So, this means let us say first of all existence of an algorithm to decide if M holds on W for any input M W. Now here we will invoke church Turing hypothesis to say that this algorithm can be carried out by a Turing machine. So, existence of a particular Turing machine that solves the halting problem. Let us name this Turing machine D. Now pictorially let us see what D is something very simple I mean whatever we said this D it will take as input something which is like M W and it will decide. So, remember this is a Turing machine. Let us also say at this time it says yes means the Turing machine knows that M would accept or M would halt on W and no means it says that M would not halt on W. So, let us also say that by saying yes it goes to a this Turing machine goes to a state from where there is no transition and so therefore D itself halts there. So, these two are since no transitions is are shown these two are halting states. Now since D exists imagine another machine which something like this that given any string W or think of this way that given any string which is of course you know any binary string can be a code of a Turing machine. So, imagine that given any code of a Turing machine it first of all copies this M and creates a pair. So, basically by that what we mean we essentially we have two copies of codes of M and now this machine D is there and D as before would look like this yes and it halts no it does not halts and no and again it halts. So, this is some transformer which just copies M to that output line with another copy. So, basically now we can see what is happening when would such a for what kind of M's this composite machine will go say will say yes this composite machine will say yes if and only if the machine M halts on its own description right the machine M halts on its own description that will take it to this line. So, this let us call it the machine E alright and now let me slightly change E to obtain a new machine F. So, E basically was that it will take code of a machine and it will go to the state M would halt on its own input halt on its own code as input and it will go to the state if M would not have halted on its own description as input. So, this is where old thing would have said yes this is no, but instead of writing yes and no. So, let me put this in brackets because now we no longer we are not interested in this kind of output as such that here we go into an infinite loop on any symbol. So, essentially once it comes to the state then it goes to the state and keeps moving here, but this one is as before. So, this is a different machine which we obtain from E and call this F the machine F what happens now if to F you had given the input which is the code of F. So, basically this is F consider the situation where the input is the code of the machine F alright this is the situation we are considering. So, in now there are two things which are possible that F halts on its own description this is case one case two is F does not halt on its own description. So, let us take the first case F halts on F then this machine E when so basically here what that would have done if this was given F was given as input it would have gone to this state. Now, F is very similar to E except. So, therefore, F also on input code F will come here, but once it comes here it goes into an infinite loop then assuming F halts on F we get that F does not halt on and if we assume let us therefore, may consider the other case does not halt on F. Now, if F does not halt on F E would have come to this state this line and come to this state as we said E and F the only difference is here. So, F also then on given this as input would have come here, but in this case when it comes to this state it halts. So, if we assume F does not halt on F that implies from there we are getting F halts on F. So, what is this situation? This situation is that if F exists we are getting into a contradiction because either it halts on its own description or it does not halt on its own description in either case we are getting something ridiculous because if you assume this then its opposite is true. If you assume the opposite then that would have been true. So, this is a classical way you say that we have reached a contradiction. What is it that you what is it that this entire thing contradicts some assumption that we made and what is the assumption really that we made here we said F exists, but clearly now this F cannot exist if F cannot exist if F cannot exist E cannot exist if E cannot exist of course, T does T just copies something make a copy to it only reason E cannot exist is because D cannot exist and what was D? D was a Turing machine to solve the halting problem. So, therefore we see a contradiction and which implies that D does not exist and what we are saying is by this we mean that since D does not exist there is no Turing machine to solve the halting problem and since there is no Turing machine to solve the halting problem there is no algorithm to solve the halting problem. Therefore, halting problem is undecidable should spend a couple of minutes on this proof and contrast it with some of the earlier things that we discussed. You should see it also as a diagonalization proof and you should also realize that we could have come to the same conclusion using notions of recursiveness etcetera, but this is a more direct demonstration of a famous problem being undecidable. One final remark some of you might wonder that the reason we said we got the contradiction was because we tried this kind of stunt that is we gave a machine its own description and that took us to a contradiction. So, is it the case that the halting problem is undecidable because we chose to give such a funny input, but point is if we do not give such inputs inputs which are codes of itself codes of the machine codes of the algorithm in that case otherwise can we do everything. So, this is a question you can think of and answer to this is no I mean this is not as simple as that the halting problem seen as a function is not computable only at one point. So, you can think about that and this is a classical problem and we must understand all the nuances of it in a very formal as well as grasp the intuition behind these proofs.