\begin{lemma}[Extracted left-shift loop is a padded lexicographic comparison]
Let $d$ be an extracted decimal sequence with logical length at most its
physical length $768$.  Let $s$ be a byte slice, let $\ell\le |s|$, and let
$m>0$ be a machine-size natural number.  Form the extracted iterator that
enumerates the first $\ell$ entries of $s$.  Put
\[
 x=\operatorname{map}(\mathrm{val},\operatorname{take}_{d.n}(d.\mathrm{digits})),
 \qquad
 y=\operatorname{map}(\mathrm{val},\operatorname{take}_{\ell}(s)).
\]
Then the extracted decimal-left-shift loop returns normally.  Its returned
value is $m-1$ exactly when
$\operatorname{take}_{\ell}(x)$ is strictly lexicographically smaller than
$y$, and is $m$ otherwise.
\end{lemma}
\begin{proof}
Use the remaining iterator count as a decreasing natural measure.  At a
loop state with enumeration count $i$, maintain the following invariant:
the underlying slice is $s$; its iterator position and enumeration count
both equal $i$; the remaining count plus $i$ equals $\ell$; $i\le\ell$;
and the original lexicographic relation is equivalent to the relation
between the two lists after dropping their first $i$ entries.

If the remaining count is zero, the invariant gives $i=\ell$.  The right
list has length exactly $\ell$ because $\ell\le|s|$, while the taken left
list has length at most $\ell$.  Dropping $\ell$ entries therefore leaves
two empty lists, whose strict lexicographic relation is false.  The loop
returns $m$, which is the required non-strict-branch result.

Otherwise checked subtraction of one from the remaining machine integer
succeeds.  Since $i<\ell\le|s|$, the slice iterator reads entry $s_i$ in
bounds; checked increment of the enumeration count succeeds because
$i<\ell$ and every slice length is representable by \texttt{usize}.  If
$i\ge d.n$, the logical decimal list has no entry at position $i$, whereas
the right list does.  Thus the dropped left list is empty and the dropped
right list begins with $s_i$, so the strict lexicographic relation holds.
The hypothesis $m>0$ makes the loop's checked subtraction $m-1$ succeed.

Suppose instead $i<d.n$.  The hypothesis $d.n\le768$, together with the
declared physical array length of \texttt{DecimalSeq}, makes the array read
of digit $d_i$ in bounds.  If $d_i=s_i$, the standard cons-list
lexicographic equivalence removes those equal heads; advancing both lists
and decrementing the iterator count preserves every invariant clause.  If
$d_i<s_i$, the lexicographic relation holds at these first unequal heads,
and the loop returns the checked value $m-1$.  Finally, if the digits are
unequal and $d_i\not<s_i$, their natural values satisfy $s_i<d_i$.  The
reverse lexicographic relation then holds at the heads, so asymmetry rules
out the target relation, and the loop returns $m$.  These branches are
exactly the extracted loop body, cover every comparison and iterator
result, and establish both normal return and the stated conditional value.
\end{proof}
