URM Computable Function is Recursive

Theorem
Every URM computable function is recursive.

Proof
Let $f: \N^k \to \N$ be a URM computable function.

Then by hypothesis there is a URM program that computes $f$.

Let $P$ be the URM program with the smallest code number that computes $f$.

Let $e = \gamma \left({P}\right)$ be the code number of $P$.

Consider the function $g: \N^k \to \N$ given by:
 * $g \left({n_1, n_2, \ldots, n_k}\right) \approx \mu t \left({\left({S_k \left({e, n_1, n_2, \ldots, n_k, t}\right)}\right)_1 > \operatorname{len} \left({e}\right)}\right)$

where:
 * $\operatorname{len} \left({e}\right)$ is the length of $e$;
 * $\mu t$ is the minimization operation on $S_k$;
 * $\approx$ denotes partial function equality;
 * $S_k \left({e, n_1, n_2, \ldots, n_k, t}\right)$ is the state code at stage $t$ of the computation of $P$ with input $\left({n_1, n_2, \ldots, n_k}\right)$;
 * the number $\left({S_k \left({e, n_1, n_2, \ldots, n_k, t}\right)}\right)_1$ is the code number of the instruction about to be carried out at stage $t$.

So the inequality:
 * $\left({S_k \left({e, n_1, n_2, \ldots, n_k, t}\right)}\right)_1 > \operatorname{len} \left({e}\right)$

expresses the fact that at stage $t$ the computation has halted.

So the value of $g \left({n_1, n_2, \ldots, n_k}\right)$ is the state code of the first stage at which computation has halted, if there is one, and undefined otherwise.

Since the functions in this inequality, and the sign $>$ itself, are all primitive recursive, it follows that the inequality expresses a primitive recursive relation on $e, n_1, n_2, \ldots, n_k, t$.

Thus $g$ is a recursive function by definition, as it can be obtained by minimization on a recursive relation.

Now consider the function $h: \N^k \to \N$ given by:
 * $h \left({n_1, n_2, \ldots, n_k}\right) \approx S_k \left({e, n_1, n_2, \ldots, n_k, g \left({n_1, n_2, \ldots, n_k}\right)}\right)$.

This is recursive because it was obtained by substitution from known recursive functions.

Now $h \left({n_1, n_2, \ldots, n_k}\right)$ is defined iff the computation halts, and it gives the value of the state code when it has halted.

The output of this computation, which gives the value of $f$, is the number in register $R_1$.

But the number in $R_1$ is the exponent of $p_2 = 3$ in the expression of the state code $h \left({n_1, n_2, \ldots, n_k}\right)$ in the form $p_1^a p_2^{r_1} p_3^{r_2} \cdots p_{k+1}^{r_k}$.

Thus the function $f$ is given by:
 * $f \left({n_1, n_2, \ldots, n_k}\right) \approx \left({h \left({n_1, n_2, \ldots, n_k}\right)}\right)_2$.

It follows that $f$ is a recursive function, since it is obtained by substitution from known recursive functions.

Attempt at Disproof
It is tempting to apply the same argument as in Not All URM Computable Functions are Primitive Recursive show that there exist recursive functions that are not URM computable.

However, that argument does not work here, as we show:

From Universal URM Computable Functions‎, we have a URM computable function $\Phi_1: \N^2 \to \N$ such that for each URM computable function $f: \N \to \N$ there exists a natural number $e$ such that:
 * $\forall n \in \N: f \left({n}\right) \approx \Phi_1 \left({e, n}\right)$.

Now suppose the function $g$ is obtained from $\Phi_1$ by putting:
 * $g \left({n}\right) \approx \Phi_1 \left({n, n}\right) + 1$

Then $g$ is URM computable and so there exists $e_0 \in \N$ such that:
 * $\forall n \in \N: g \left({n}\right) \approx \Phi_1 \left({e_0, n}\right)$.

Hence
 * $g \left({e_0}\right) \approx \Phi_1 \left({e_0, e_0}\right)$.

whereas we have just constructed $g$ so that:
 * $g \left({e_0}\right) \approx \Phi_1 \left({e_0, e_0}\right) + 1$.

So this gives us:
 * $\Phi_1 \left({e_0, e_0}\right) \approx \Phi_1 \left({e_0, e_0}\right) + 1$

Have we just proved a contradiction?

No, because $\Phi_1$ is a partial function, and all this tells us is that either both sides are defined and equal, or neither side is defined.

The first is impossible, and the second just leads us to the innocuous conclusion that $\Phi_1 \left({e_0, e_0}\right)$ is not defined, rather than that there is a URM computable function which is not recursive.

Note
Putting all the above equations together, we note that:
 * $f \left({n_1, n_2, \ldots, n_k}\right) \approx \left({S_k \left({e, n_1, n_2, \ldots, n_k, \mu t \left({\left({S_k \left({e, n_1, n_2, \ldots, n_k, t}\right)}\right)_1 > \operatorname{len} \left({e}\right)}\right)}\right)}\right)_2$.

This works for every recursive function of $k$ variables.

The only thing that changes as we vary $f$ is the number $e$.

Thus the formula gives what is known as a normal form for recursive functions.

Hence, see Kleene's Normal Form Theorem.