[step:Define the halting-step witness function via minimisation]
Define an auxiliary function
\begin{align*}
f' : \mathbb{W}^3 &\rightharpoonup \mathbb{W}, \\
(v, u, y) &\mapsto \begin{cases} \varepsilon & \text{if } h(v, u, y) \downarrow \text{ and the state field of } h(v, u, y) \text{ equals } \operatorname{code}(q_{H, v}), \\ a & \text{if } h(v, u, y) \downarrow \text{ and the state field of } h(v, u, y) \ne \operatorname{code}(q_{H, v}), \\ \uparrow & \text{if } h(v, u, y) \uparrow, \end{cases}
\end{align*}
where $q_{H, v}$ is the halt state of the machine encoded by $v$ (and $\operatorname{code}(q_{H, v})$ is readable from $v$). Note: we swapped the roles of $\varepsilon$ and $a$ relative to a naive halting indicator, because our minimisation operator $\mu$ searches for the shortlex-least $y$ with $f'(v, u, y) = \varepsilon$, and we want to minimise over halting steps.
[claim:$f'$ is computable]
Given computable $h$ (from [Computability of the Configuration Function](/theorems/1818)), we construct a register machine $M_{f'}$ that, on input $(v, u, y)$:
(a) Runs $M_h$ on $(v, u, y)$, obtaining configuration code $c$ in a scratch register; if $M_h$ diverges, $M_{f'}$ diverges (matching the "undefined" case).
(b) Extracts the state field of $c$ (the prefix before the first $|$) into a scratch register $R_\text{st}$, using the left-to-right scan with separator detection already described in Step 3 of the proof of [Truncated Computation Function](/theorems/1819).
(c) Extracts $\operatorname{code}(q_{H, v})$ from $v$ (here $v$ must first be restored from a master copy, having been destructively consumed by $M_h$). Parsing $v$ to locate the halt-state sub-field is a fixed regular operation on $v$: scan for the "halt state" marker in the standard encoding format, and copy the following sub-word into a scratch register $R_\text{halt}$. If parsing $v$ fails, this mirrors the "malformed $v$" failure that $M_h$ would have already triggered in (a) via divergence; but for robustness, if parsing reaches end-of-input without finding the halt-state marker, enter a divergent loop.
(d) Compare $R_\text{st}$ to $R_\text{halt}$ letter-by-letter: this is a word-equality test, a computable finite operation as in Step 4 of the proof of [Computability of the Configuration Function](/theorems/1818). If equal, write $\varepsilon$ to register $0$ (erase register $0$) and halt; if not equal, write $a$ to register $0$ and halt.
Each step is a bounded sequence of register operations or a finite call to a computable sub-machine. Hence $M_{f'}$ computes $f'$, and $f'$ is computable.
[/claim]
Define
\begin{align*}
h' : \mathbb{W}^2 &\rightharpoonup \mathbb{W}, \\
(v, u) &\mapsto (\mu f')(v, u) = \min\{y \in \mathbb{W} : f'(v, u, y) = \varepsilon \text{ and } f'(v, u, y') \downarrow \text{ for all } y' < y\},
\end{align*}
where $<$ is the shortlex order and $\min$ is the shortlex-least element (well-defined by the well-orderedness of $(\mathbb{W}, <)$ from [Shortlex Order and Computable Successor](/theorems/1815)).
[claim:$h'$ is computable, and $h'(v, u)$ is defined iff $(v, u)$ encodes a valid machine-and-input pair such that the encoded machine halts on the encoded input]
Computability: $h'$ is the minimisation $\mu f'$ of the computable function $f'$ (previous claim). By closure of computable functions under minimisation (L3 of [Recursive Implies Computable](/theorems/1817)), $h'$ is computable.
Definedness: we analyse when $(\mu f')(v, u)$ is defined.
- If $(v, u)$ does not encode a valid machine-and-input pair, then $h(v, u, \varepsilon) \uparrow$, so $f'(v, u, \varepsilon) \uparrow$. The minimisation fails the "defined at all $y' < y$" clause at the very first step $y' = \varepsilon$, so $(\mu f')(v, u) \uparrow$.
- If $(v, u) = (\operatorname{code}(M), \operatorname{code}(w))$ with $M$ of arity $k$ and $w \in \mathbb{W}^k$, then by the specification of $h$, $h(v, u, y) \downarrow$ for every $y \in \mathbb{W}$, with $h(v, u, y) = \operatorname{code}(C(M, w, |y|))$. Therefore $f'(v, u, y) \downarrow$ for every $y$, and $f'(v, u, y) = \varepsilon$ iff $C(M, w, |y|)$ is in state $q_H$. So:
- If $M$ halts on $w$, let $n^\star$ be the least step count at which $M$ reaches $q_H$ (so $C(M, w, n^\star)$ is in state $q_H$ and $C(M, w, n) \ne q_H$ for $n < n^\star$, where by "the configuration after $n < n^\star$ steps is not in state $q_H$" we mean the running state, not the adopted "stay after halt" convention — but since $n^\star$ is minimal, no earlier $n$ is in state $q_H$ under either interpretation). The set $\{y \in \mathbb{W} : |y| = n^\star\}$ consists of words of length $n^\star$; among these, the shortlex-least is $a_0^{n^\star}$ where $a_0$ is the shortlex-minimum letter. Smaller $y$ (in shortlex order) have $|y| < n^\star$, for which $f'(v, u, y) = a \ne \varepsilon$; the shortlex-least $y$ at which $f' = \varepsilon$ is $a_0^{n^\star}$. Hence $h'(v, u) = a_0^{n^\star}$.
- If $M$ does not halt on $w$, then $C(M, w, n)$ is not in state $q_H$ for any $n$, so $f'(v, u, y) = a$ for every $y$. The minimum set is empty, so $(\mu f')(v, u) \uparrow$, i.e. $h'(v, u) \uparrow$.
Hence $h'(v, u) \downarrow$ iff $(v, u)$ encodes a valid pair and $M$ halts on $w$; moreover, when defined, $|h'(v, u)|$ equals the first halting step count $n^\star$.
[/claim]
[/step]