[step:Define $h(v) := \operatorname{code}(M_v \circ M)$ and show $h$ is computable]
Define
\begin{align*}
h : \mathbb{W} &\to \mathbb{W}, \\
v &\mapsto \operatorname{code}(M_v \circ M).
\end{align*}
By the conclusion of Step 3, $f_{h(v), k}(w) = g(w, v)$ for every $v, w$, matching the specification. It remains to show $h$ is total and computable.
*Totality.* $M_v$ is defined for every $v \in \mathbb{W}$ (the construction in Step 2 uses only finite data read off from $v$), and the concatenation with $M$ is defined for every pair of machines. Hence $\operatorname{code}(M_v \circ M)$ is defined for every $v$.
*Computability.* We exhibit a register machine computing $h$ by composing two computable sub-routines.
[claim:The function $\varphi : \mathbb{W} \to \mathbb{W}$, $v \mapsto \operatorname{code}(M_v)$ is computable]
The encoding $\operatorname{code}(M_v)$ is a word over the code alphabet that lists $M_v$'s states and instructions in a fixed format. By the construction of Step 2, $M_v$'s data depend on $v$ only through the letters $v_1, \ldots, v_{|v|}$ and the length $|v|$. Concretely, $\operatorname{code}(M_v)$ has the form
\begin{align*}
\operatorname{code}(M_v) &= A \cdot B(v_1) \cdot B(v_2) \cdots B(v_{|v|}) \cdot C
\end{align*}
where:
- $A$ is a fixed prefix encoding $M_v$'s fixed preamble — the declarations of states $q_{v,0}, q_{v,1}, \ldots$ up to the number of states needed, the fixed arity $k$, and the fixed start state $q_{v, 0}$. Under a fixed encoding convention the state names $q_{v, i}$ can be encoded by a finite template indexed by $i$; the number of states depends on $|v|$, so $A$ actually depends on $|v|$ only through its length (we address this by making the state-declaration block be built letter-by-letter from $v$ below).
- $B(a)$, for each letter $a \in \Sigma$, is the fixed block encoding one instruction "at the next fresh state, write $a$ to register $k$ and transition to the next fresh state". Each $B(a)$ is a fixed finite word depending only on $a$ and on a counter tracking which fresh state to use.
- $C$ is a fixed suffix encoding the halt transition and the end-of-program marker.
Because the dependence on $v$ enters only through its letters and its length, $\operatorname{code}(M_v)$ can be assembled by a register machine $M_\varphi$ that:
(a) Reads $v$ letter-by-letter from its input register. Using the left-to-right reading technique of Step 3 of the proof of [Regular Languages are Computable](/theorems/1814) — reverse $v$ into a scratch register $R_v^*$ using the letter-by-letter reversal routine, then repeatedly pop the last letter of $R_v^*$ — each letter of $v$ is read exactly once.
(b) Maintains two scratch counters: a state-index counter $R_i$ (initialised to $0$, incremented after each letter) and an output register $R_\text{out}$ for the assembled code.
(c) Before reading any letters, writes the preamble $A$ into $R_\text{out}$, where $A$ depends on $|v|$. To handle this cleanly we emit $A$ in a streaming fashion interleaved with the letter-processing: first emit a fixed header (arity, encoding-format markers, start state), then emit state-declaration sub-blocks $D(0), D(1), \ldots, D(|v|)$ one per letter of $v$ (each $D(i)$ is a fixed word possibly parametrised by $i$ via a literal encoding of $i$ derivable from the counter $R_i$ by a fixed word-for-integer routine; under the standard encoding convention, state indices are encoded in unary or shortlex, and the $i$-th state's declaration sub-block is emittable from $R_i$'s contents by a fixed routine).
(d) For each letter $a$ of $v$ read in (a), emits the instruction block $B(a)$ appended to $R_\text{out}$. The block $B(a)$ depends only on the fixed letter $a$ and on the current value of $R_i$ (to reference the correct "fresh" state); both are available to the machine at emission time.
(e) After all letters of $v$ have been processed, emits the suffix $C$ (the halt transition) into $R_\text{out}$.
(f) Copies $R_\text{out}$ into register $0$ and halts.
Each of (a)–(f) is a fixed finite sub-routine plus a loop bounded by $|v|$; at each loop iteration the work is bounded (one letter read, a fixed block emission, one increment of $R_i$). By the composition and primitive-recursion closures of Step 4 (L1) and Step 5 (L2) of the proof of [Recursive Implies Computable](/theorems/1817), or more directly by exhibiting $M_\varphi$ as an explicit register machine as above, $\varphi$ is computable and total. Moreover, because the loop in (a)–(e) runs exactly $|v|$ iterations and every sub-routine halts, $M_\varphi$ halts on every input.
[/claim]
[claim:The function $\psi : \mathbb{W} \to \mathbb{W}$, $c \mapsto \operatorname{code}(N_c \circ M)$ (where $N_c$ is the machine decoded from $c$, and $\circ$ denotes concatenation with the fixed $M$) is computable]
The [concatenation lemma](/theorems/1810) asserts that given codes $c_1, c_2$ of two register machines $N_1, N_2$ with matching arities, the code $\operatorname{code}(N_1 \circ N_2)$ is computable from $(c_1, c_2)$; equivalently, the map $(c_1, c_2) \mapsto \operatorname{code}(N_1 \circ N_2)$ is a (total) computable function of two arguments. Specialising the second argument to the fixed literal $c_2 = \operatorname{code}(M)$ (a finite fixed constant), the map $\psi : c \mapsto \operatorname{code}(N_c \circ M)$ is the composition of $c \mapsto (c, \operatorname{code}(M))$ (prepending a fixed constant — computable by a fixed sequence of "write letter" instructions followed by the identity on the input) with the two-argument concatenation map. By L1 of the proof of [Recursive Implies Computable](/theorems/1817) (closure of computable functions under composition), $\psi$ is computable. Totality of $\psi$ follows from totality of concatenation on well-formed codes (both $c$ and $\operatorname{code}(M)$ are well-formed codes of arity $k$ and $k + 1$ respectively, matching the concatenation rule).
[/claim]
Now $h = \psi \circ \varphi$: for every $v$,
\begin{align*}
h(v) = \operatorname{code}(M_v \circ M) = \psi(\operatorname{code}(M_v)) = \psi(\varphi(v)).
\end{align*}
Both $\varphi$ (Claim 1) and $\psi$ (Claim 2) are total computable, so $h$ is total computable by L1 of the proof of [Recursive Implies Computable](/theorems/1817).
[/step]