A Turing machine algorithm which determines other algorithms Let $X$ be a Turing machine algorithm, which run as following:

For a Turing machine algorithm A,
X(A)=0 if A(A)=0
X(A)$\neq$0 if A(A)$\neq$0

We can code X easily. However, what's the result of X(X)?
It runs forever? or We don't know the result?
 A: The most naive machine $X$ that meets your requirements simply does the following:


*

*$X$: If the input represents a Turing machine $A$, then simulate $A$'s behavior on the input (that is, simulate it on $\langle A \rangle$) and halt with the simulated output.


(The machine's behavior if the input doesn't represent a Turing machine is not relevant.)  If $X$ is implemented this way, then $X(\langle X \rangle)$ runs forever: the machine will only terminate after the simulated machine terminates, which will happen only after the simulation's simulated machine terminates, etc… turtles all the way down.  However, we can also devise a machine $X'$ such that $X'(\langle X'\rangle)$ halts with output $0$ (or any other output you like), but still behaves the same for all other inputs, and so still meets all your requirements (which, after all, are trivially satisfied when the input is the machine's own description).  First we need something like this:


*

*$Q$: If the first and second inputs are equal, then halt with output $0$.  Otherwise, simulate $X$'s behavior on the second input and halt with the simulated output.


Then we want to build $X'$ out of this, by passing $\langle X'\rangle$ as the first input to $Q$, and the input to $X'$ as the second input to $Q$.  But how do we get $X'$ to have access to its own description?
It turns out that there is a general procedure for constructing Turing machines like this.  Specifically, for any Turing machine $Y$ that takes two inputs, there is a related Turing machine $G_Y$ that takes one input, such that $G_Y(a) = Y(\langle G_Y \rangle, a)$ for any input $a$.  I'll leave the procedure as an exercise (as it's fairly detailed, and anyway you can look it up).  But it should be clear that $X'=G_Q$ behaves just like the original $X$ except for a single input: its own description, on which it halts immediately with output $0$.
