It can easily be seen that $S_k$ is a total function. Suppose $e = \gamma \left({P}\right)$ for some URM program $P$. At stage $0$, we are about to carry out instruction $1$ with the input $\left({n_1, n_2, \ldots, n_k}\right)$. So we have: :$S_k \left({e, n_1, n_2, \ldots, n_k, 0}\right) = \begin{cases} 2^1 3^{n_1} 5^{n_2} \cdots p_{k+1}^{n_k} & : e \in \operatorname{Prog} \\ 0 & : \text{otherwise} \end{cases}$ where $\operatorname{Prog}$ is the set of code numbers of all URM programs. We see that $S_k \left({e, n_1, n_2, \ldots, n_k, 0}\right)$ does not actually depend upon the actual program being run, beyond the fact that it matters whether it actually ''is'' a program or not. Now $\operatorname{Prog}$ is a primitive recursive set. So from results about primitive recursive functions, the relations defining the cases are primitive recursive. We can also deduce from various results about primitive recursive functions that the functions given by the formulas $2^1 3^{n_1} 5^{n_2} \cdots p_{k+1}^{n_k}$ and $0$ are primitive recursive. In particular, we use the results: * Multiplication is Primitive Recursive; * Exponentiation is Primitive Recursive; * Prime Enumeration Function is Primitive Recursive. So from Definition by Cases is Primitive Recursive, $S_k \left({e, n_1, n_2, \ldots, n_k, 0}\right)$ is primitive recursive. Now we want to be able to express $S_k \left({e, n_1, n_2, \ldots, n_k, t+1}\right)$ in terms of $e, \left({n_1, n_2, \ldots, n_k}\right), t$ and $S_k \left({e, n_1, n_2, \ldots, n_k, t}\right)$ using known primitive recursive functions. We need to consider a number of cases: #$e$ does not code a URM program; #$e = \gamma \left({P}\right)$ and the computation halts at stage $t$ or earlier; #$e = \gamma \left({P}\right)$ and the instruction to be carried out at stage $t$ is a <tt>Zero</tt> instruction; #$e = \gamma \left({P}\right)$ and the instruction to be carried out at stage $t$ is a <tt>Successor</tt> instruction; #$e = \gamma \left({P}\right)$ and the instruction to be carried out at stage $t$ is a <tt>Copy</tt> instruction; #$e = \gamma \left({P}\right)$ and the instruction to be carried out at stage $t$ is a <tt>Jump</tt> instruction. These cases are clearly mutually exclusive and exhaustive. First we need to check that each case corresponds to a primitive recursive relation. * The set $\operatorname{Prog}$ is primitive recursive so its complement is also primitive recursive. So 1. is a primitive recursive relation. * So we have that $e$ codes a URM program. Call that program $P$. From the definition of state code, we see that if a computation halts at stage $t$ or earlier, then the number of the instruction to be carried out at stage $t$ is greater than the number of instructions in $P$. From the definition of the code number of $P$, the number of instructions in $P$ is $\operatorname{len} \left({e}\right)$ where $\operatorname{len} \left({e}\right)$ is the length of $e$, which is primitive recursive. Now let $r = S_k \left({e, n_1, n_2, \ldots, n_k, t}\right)$. Let $\left({r}\right)_j$ be defined as the prime exponent function. By the definition of the state code, the number of the instruction to be carried out at stage $t$ is $\left({r}\right)_1$, which is primitive recursive. So 2. can be expressed as: :$e \in \operatorname{Prog} \text { and } \left({S_k \left({e, n_1, n_2, \ldots, n_k, t}\right)}\right)_1 > \operatorname{len} \left({e}\right)$ Both $\operatorname{Prog}$ and $\left({r}\right)_1$ are primitive recursive, so from Set Operations on Primitive Recursive Relations, 2. is a primitive recursive relation. * So, let the number of the instruction to be carried out at stage $t$ be $a = \left({S_k \left({e, n_1, n_2, \ldots, n_k, t}\right)}\right)_1$. From the definition of the code number of $P$, the code number of this instruction is $\left({e}\right)_a$. Now from Set of Codes for URM Instructions is Primitive Recursive, each of the sets $\operatorname{Zinstr}$, $\operatorname{Sinstr}$, $\operatorname{Cinstr}$ and $\operatorname{Jinstr}$ are primitive recursive. So each of 3. to 6. above can be expressed as: :$e \in \operatorname{Prog} \text { and } a \le \operatorname{len} \left({e}\right) \text { and } \left({e}\right)_a \in \operatorname{Instr}$ and is a primitive recursive relation. So relations 1. to 6. are all primitive recursive. Now we need to show how, in each case, $S_k \left({e, n_1, n_2, \ldots, n_k, t+1}\right)$ can be obtained from $e, \left({n_1, n_2, \ldots, n_k}\right), t$ and $S_k \left({e, n_1, n_2, \ldots, n_k, t}\right)$ using known primitive recursive functions. First, if $e$ does not code a URM program then $S_k \left({e, n_1, n_2, \ldots, n_k, t+1}\right) = 0$, which is primitive recursive. Second, we have adopted the convention that if $P$ has halted, then $S_k$ does not change. So if $P$ halts at or before stage $t$, we have that $S_k \left({e, n_1, n_2, \ldots, n_k, t+1}\right) = S_k \left({e, n_1, n_2, \ldots, n_k, t}\right)$ Next, we look at the individual commands. As an example we will investigate the <tt>Successor</tt> command. The others are treated similarly. Suppose the instruction to be carried out at stage $t$ is a <tt>Successor</tt> command. We know that the code number $c$ is given by $c = \left({e}\right)_a$ where $a = \left({S_k \left({e, n_1, n_2, \ldots, n_k, t}\right)}\right)_1$. Suppose the instruction is $S \left({n}\right)$. Then $c = 6 n$. So $n = \operatorname{quot} \left({6, n}\right)$ which is recursive from Quotient is Primitive Recursive. This instruction adds $1$ to the number in $R_n$. This increases the exponent $p_{n+1}$ in the state code by $1$. This is achieved by multiplying $S_k \left({e, n_1, n_2, \ldots, n_k, t}\right)$ by $p \left({n+1}\right)$, where $p \left({n+1}\right)$ is the prime enumeration function which is primitive recursive. Since the instruction to be carried out at stage $t$ is a <tt>Successor</tt> the instruction number at stage $t+1$ is $a+1$ so the factor $2^a$ in $S_k \left({e, n_1, n_2, \ldots, n_k, t}\right)$ is replaced by $2^{a+1}$. So: :$S_k \left({e, n_1, n_2, \ldots, n_k, t+1}\right) = 2 \times p_{n+1} \times S_k \left({e, n_1, n_2, \ldots, n_k, t}\right)$ where $n = \operatorname{quot} \left({6, n}\right)$, $c = \left({e}\right)_a$ and $a = \left({S_k \left({e, n_1, n_2, \ldots, n_k, t}\right)}\right)_1$. This is the required expression for $S_k \left({e, n_1, n_2, \ldots, n_k, t+1}\right)$ obtained by substitution from primitive recursive functions. The proofs for $\operatorname{Zinstr}$, $\operatorname{Cinstr}$ and $\operatorname{Jinstr}$ are along the same lines. In each case, the value of $S_k \left({e, n_1, n_2, \ldots, n_k, t+1}\right)$ can be obtained by substitution from primitive recursive functions (but I'd hate to have to do the calculations on my fingers). Thus by Definition by Cases is Primitive Recursive, $S_k \left({e, n_1, n_2, \ldots, n_k, t+1}\right)$ is primitive recursive. Hence $S_k$ is defined by primitive recursion from functions known to be primitive recursive. Hence the result. {{qed}}