\begin{helper}[Prefix-search semantics for decimal right shift]
Let $d$ be a decimal-sequence record, put $n=d.\mathit{num\_digits}$,
let $x$ be the list of natural values of all 768 cells of
$d.\mathit{digits}$, and put
\[
 I=\operatorname{fold}_{10}(x[0:n]),\qquad B=2^k.
\]
Assume $0\le k\le60$, $I>0$, and every cell in the stored prefix
$d.\mathit{digits}[0:n]$ is below ten.  If the extracted
\texttt{right\_shift\_loop0}, started on $d$ with shift $k$, read index zero,
zero accumulator, and false all-zero flag, returns $(d',r,c,z)$, then
\[
 d'=d,\qquad z=\mathrm{false},\qquad r\ge1,qquad B\le c<10B.       \tag{1}
\]
Moreover exactly the applicable one of the following phase descriptions
holds:
\[
\begin{array}{ll}
 r\le n: & r\le768\quad\hbox{and}\quad
           c=\operatorname{fold}_{10}(x[0:r]);\tag{2}\\
 n<r: & n\le768,\quad r\le n+k,\quad
           c=I10^{r-n}.\tag{3}
\end{array}
\]
\end{helper}
\begin{proof}
Unfold both loops in
\noderef{num_imp_dec2flt_decimal_seq_DecimalSeq_right_shift}.  We use the
partial result-loop induction principle \noderef{ResultLoopPartial}; normal
return is an explicit hypothesis, so each induction only has to preserve its
invariant and analyze a finishing body result.

First analyze the nested zero-extension loop.  Suppose it starts at cursor
$s\le768$ with $0<c_0<B$ and $c_0>0$.  At a state $(u,C)$ use the invariant
\[
 s\le u\le s+k,qquad 0<C<10B,qquad C=c_0 10^{u-s}.       \tag{4}
\]
If the modeled right shift of $C$ is nonzero, its natural value is
$\lfloor C/B\rfloor$, so $B\le C$ and the loop finishes.  It cannot finish at
$u=s$: there (4) gives $C=c_0<B$.  Hence a finish satisfies $s<u$, as well as
the other clauses of (4).

If that quotient is zero, Euclidean division by the positive $B$ gives
$C<B$.  The body multiplies by ten and increments the cursor.  The
multiplication is checked and exact because
\[
 C\cdot10<B\cdot10\le10\cdot2^{60}<2^{64}.              \tag{5}
\]
To justify the cursor bound, put $t=u-s$.  If $t\ge k$, then, since
$c_0\ge1$ and $2^k\le10^k\le10^t$, equation (4) would give $C\ge B$,
contrary to the zero quotient.  Thus $t<k$, so the incremented cursor is at
most $s+k$; it is also at most $768+60$, far below the Usize maximum.  The
new accumulator is
$10C=c_0 10^{t+1}$, is positive, and is below $10B$, so (4) is preserved.
Applying \noderef{ResultLoopPartial} proves that a normal nested-loop return
has
\[
 s<u\le s+k,qquad B\le C<10B,qquad C=c_0 10^{u-s}.     \tag{6}
\]

Now apply the same principle to \texttt{right\_shift\_loop0}.  At a state
$(u,C,\zeta)$ use
\[
 \zeta=\mathrm{false},qquad u\le n,qquad u\le768,qquad
 C=\operatorname{fold}_{10}(x[0:u]),qquad C<10B.        \tag{7}
\]
The initial state satisfies (7): the empty fold and accumulator are zero,
and $B>0$.

The first operation in the body returns $\lfloor C/B\rfloor$.  If it is
nonzero, then $B\le C<10B$ and the body finishes with the unchanged record,
cursor, accumulator, and false flag.  This cursor cannot be zero, because the
empty prefix fold is zero.  Thus (1) and (2) hold in this branch.

Suppose instead the quotient is zero, so $C<B$.  The flag clause in (7)
selects the false branch.  If $u<n$, successful execution must make the
fixed-array read at $u$ succeed.  Since the array has exactly 768 cells, this
proves $u<768$.  Let the read digit be $a$.  It belongs to the assumed prefix,
so $a<10$.  The checked multiplication and addition are exact, because
\[
                  10C+a<10B+10\le10\cdot2^{60}+10<2^{64}.
\]
The checked Usize increment is safe since $u<768$.  The new accumulator is
$10C+a$, which is below $10B$, and the elementary fold recurrence
\[
 \operatorname{fold}_{10}(x[0:u+1])
   =10\operatorname{fold}_{10}(x[0:u])+a
\]
preserves (7) at $u+1$.

It remains to analyze $u=n$.  Here (7) says $C=I>0$, so the branch that sets
the all-zero flag true is impossible.  The body calls the nested loop with
$s=n$, $c_0=I$, and $I<B$.  Reaching this point through successful fixed-array
reads gives $n\le768$.  Applying (6) gives precisely (1) and (3), while the
outer body returns the original record and false flag unchanged.  These cases
exhaust every normally returning body result, so the outer application of
\noderef{ResultLoopPartial} proves the claim.
\end{proof}
