\begin{lemma}[Normal left shift on the loop-one domain]
Let $d$ have at most 768 retained cells, all retained cells be decimal digits,
and let its retained word have length equal to the count and begin with a
digit in $[1,9]$.  Suppose $-324\leq p\leq0$, and let $0\leq k\leq60$.
Then the complete extracted decimal left shift returns normally.  There is a
natural digit growth $q\leq19$ such that its returned record $d'$ is nonempty
and
\[
 d'.p=p+q,\qquad -324\leq d'.p\leq19.                     \tag{1}
\]
The Lean conclusion contains the exact successful-call equation and (1).
\end{lemma}
\begin{proof}
Write $x$ for the retained digit list, $n=|x|$ for its count,
$I=\operatorname{fold}_{10}(x)$, $p$ for the input point, and $B=2^k$.
The supplied list equality says that $x=z::z_s$, where $1\leq z<10$ and
$|x|=n$.  Hence $1\leq n\leq768$.  The usual induction on the tail of this
decimal word, using that every member of $x$ is below ten, gives the sharp
input bounds
\[
                         10^{n-1}\leq I<10^n.           \tag{2}
\]
We now construct, in order, every subcall appearing in the unfolded
definition
\noderef{num_imp_dec2flt_decimal_seq_DecimalSeq_left_shift}.

First consider the digit-growth routine.  If $k=0$, direct unfolding at the
zero table entry gives the empty comparison slice and the normal result
$q=0$.  In this case $IB=I$, so (2) says
\[
                  10^{n+q-1}\leq IB<10^{n+q}.          \tag{3}
\]
(Here $n\geq1$ makes the natural subtraction in the left exponent equal to
$n-1$.)  Suppose instead that $k>0$.  The finite certificate
\noderef{DecimalLeftShiftTableCertificate} supplies the table integer $h$
and the bounds
\[
                         10^{h-1}<B<10^h.               \tag{4}
\]
Applying the exact growth theorem
\noderef{DecimalLeftShiftDigitGrowth} constructs the normal routine return
and gives precisely the following alternatives:
\[
 \begin{array}{c|c}
 q=h     & 10^{n+h-1}\leq IB,\\
 q=h-1   & IB<10^{n+h-1}.
 \end{array}                                             \tag{5}
\]
In the first alternative, the upper halves of (2) and (4) give
$IB<10^n10^h=10^{n+q}$.  In the second, (5) is the required upper bound
$IB<10^{n+q}$, while the lower halves of (2) and (4) give
\[
             IB>10^{n-1}10^{h-1}=10^{n+q-1}.
\]
Thus (3) holds in both alternatives (with a strict, hence weak, lower bound
in the second).  Moreover
$10^{h-1}<B\leq2^{60}<10^{19}$ implies $h\leq19$ by strict monotonicity of
the natural powers of ten.  Since (5) always has $q\leq h$, we have
\[
                             q\leq19.                   \tag{6}
\]
This also holds in the zero-shift case.

The first checked count addition succeeds and has natural value
$w=n+q\leq768+19=787$, well below the Usize maximum.  Construct the first
carry loop by induction on its decreasing read cursor, starting with carry
zero and cursors $n,w$.  Maintain that the carry $C$ is below $B$, and that
only destinations between the current write cursor and $w$ have changed.
When the read cursor is positive, $n\leq w$ and the equal decrement history
of the two cursors show that the write cursor is positive too, so both Usize
subtractions succeed.  The new read index is below $n\leq768$ and below or
equal to the new destination; all earlier destinations were larger, and the
read precedes the possible write at the new destination.  Thus the read still
sees the corresponding original decimal digit $a<10$.  The U64 cast is exact
and the modeled shift and addition have the natural value
\[
                   T=C+aB<10B\leq10\,2^{60}<2^{64}.    \tag{7}
\]
Division by ten is legal.  Its quotient $C'=\lfloor T/10\rfloor$ obeys
$C'<B$, while $10C'\leq T<2^{64}$ makes the checked multiplication exact and
the checked subtraction returns the remainder $R=T-10C'<10$.  The U8 cast of
$R$ is therefore exact.  A destination below 768 is a valid array index; a
destination at least 768 takes the nonwriting sticky branch.  Consequently
the loop returns normally after exactly $n$ steps, with final cursor
$w-n=q$.

Apply \noderef{DecimalLeftShiftFirstLoopSemantics} to that constructed
return, and call its returned array $A_0$.  The theorem gives a length-$n$
decimal list $v$, final carry $c<B$, and, with
$W=\operatorname{fold}_{10}(v)$,
\[
                  IB=c10^n+W,\qquad 0\leq W<10^n.       \tag{8}
\]
It also says that first-loop cell $q+j$ equals $v_j$ whenever $j<n$ and
$q+j<768$.  The strict bound on $W$ follows directly by induction from the
stated length and digit bounds on $v$.

We next derive the exact bounds needed to initialize the second loop.  If
$c\geq10^q$, (8) would give
$IB\geq c10^n\geq10^{n+q}$, contradicting (3).  Hence
\[
                              c<10^q.                   \tag{9}
\]
In particular, $q=0$ forces $c=0$.  If $q>0$ and
$c<10^{q-1}$, integrality gives $c+1\leq10^{q-1}$; combining this with
$W<10^n$ in (8) yields
\[
 IB=c10^n+W<(c+1)10^n\leq10^{q-1}10^n
    =10^{n+q-1},
\]
contrary to (3).  Therefore
\[
                    q>0\quad\Longrightarrow\quad
                    10^{q-1}\leq c.                    \tag{10}
\]

The zero-prefix premise of
\noderef{DecimalLeftShiftSecondLoopSemantics} is now satisfied.  It is
vacuous when $q=0$.  When $q>0$, take $j<q$ (the additional requirement
$j<768$ is immaterial).  Then $q-j-1\leq q-1$, so monotonicity and (10) give
$10^{q-j-1}\leq10^{q-1}\leq c$.  Thus the premise's antecedent
$c<10^{q-j-1}$ is impossible, and the required implication holds regardless
of the current array cell.

For completeness, the second loop itself has a normal return.  Starting from
(9), maintain at cursor $s$ a carry $C<10^s$.  A positive $C$ forces $s>0$,
so the checked cursor decrement succeeds.  Division by ten gives quotient
$C'$ and remainder $R<10$ with $C'<10^{s-1}$; as in (7), $10C'\leq C<2^{64}$
discharges the checked multiplication and subtraction, and the U8 cast is
exact.  The body either writes at the in-range destination $s-1<768$ or
takes the nonwriting sticky branch.  Each continuing step decreases both the
cursor and the carry, so after at most $q$ steps the carry is zero and the
loop returns.  Call its returned array $A_1$.  Applying the cited second-loop
theorem gives a length-$q$ decimal list $u$ such that
\[
                         c=\operatorname{fold}_{10}(u). \tag{11}
\]
Its cell clause puts $u_j$ in final cell $j$ whenever $j<q$ and $j<768$;
its unchanged-suffix clause preserves every first-loop cell with index at
least $q$.

The two lists therefore splice without a gap: for every physical index, the
final array contains the entries of $u$ in positions $[0,q)$ and the entries
of $v$ in positions $[q,q+n)$.  Algebraically, the standard concatenation
identity for decimal folds, (11), and (8) give
\[
 \begin{aligned}
 \operatorname{fold}_{10}(u{+\!+}v)
   &=\operatorname{fold}_{10}(u)10^{|v|}
       +\operatorname{fold}_{10}(v)\\
   &=c10^n+W=IB,
 \end{aligned}                                          \tag{12}
\]
and $|u{+\!+}v|=q+n$.  We also need the promised positive physical first
cell.  If $q>0$, (10)--(11) imply
$10^{q-1}\leq\operatorname{fold}_{10}(u)$.  Were $u_0=0$, its remaining
$q-1$ decimal digits would instead make that fold strictly below
$10^{q-1}$, a contradiction.  Hence $u_0>0$, and the second-loop cell clause
writes this value at physical index zero.  If $q=0$, (9) gives $c=0$, so
(3), (8), and (11) give
$10^{n-1}\leq W=\operatorname{fold}_{10}(v)$.  A zero head of the length-$n$
list $v$ would make its fold less than $10^{n-1}$; thus $v_0>0$.  The
first-loop cell clause puts $v_0$ at index $q=0$, and the second-loop
unchanged-suffix clause preserves it.  In either case the final loop array
has a strictly positive cell at index zero:
\[
                              A_1[0]>0.                 \tag{13}
\]

The second checked addition again has value $n+q\leq787$.  Capping it at 768
produces a pre-trim count
\[
                         m=\min(n+q,768).
\]
Because $n\geq1$, both arguments of this minimum are positive, so $m>0$;
in particular (13) lies inside the retained prefix.  The Usize-to-I32 cast of
$q$ is exact by (6).  The checked point addition is also exact, because
\[
                         -324\leq p+q\leq19             \tag{14}
\]
lies strictly inside the I32 range.

It remains only to construct and analyze trim on the record with digit array
$A_1$.  Its input count is $m\leq768$, the length of the fixed array.  Induct
on that count: at a
positive count, decrementing it succeeds and the inspected index is below
768; a nonzero terminal digit returns immediately, while a zero digit
continues at the smaller count.  Thus the trim call returns normally after at
most $m$ inspections.  Apply \noderef{DecimalSeqTrimSemantics}.  It preserves
the array and the point $p+q$, and its zero-suffix clause says that every cell
from the returned count $m'$ through $m-1$ is zero.  If $m'=0$, then $m>0$
lets us instantiate that clause at index zero, contradicting the positive
cell (13).  Hence $m'\ne0$.

Substituting the constructed digit-growth, two loop, arithmetic, and trim
returns into the unfolded left-shift definition proves its exact successful
call equation.  Equations (6), (14), trim's point preservation, and $m'\ne0$
give respectively every remaining clause of the conclusion and of (1).
\end{proof}
