\begin{lemma}[Returned-record semantics of decimal right shift]
For a decimal sequence $d$, let
\[
 V(d)=\operatorname{fold}_{10}
   (d.\mathit{digits}[0:d.\mathit{num\_digits}])
   10^{d.\mathit{decimal\_point}-d.\mathit{num\_digits}}.
\]
Let $0\le k\le60$, suppose $V(d)>0$, and suppose every cell in the stored
prefix is a decimal digit.  If the extracted right shift by $k$ returns
$d'$, then either
\[
 d'.\mathit{num\_digits}=0,\qquad d'.\mathit{decimal\_point}=0,
 \qquad d'.\mathit{truncated}=\mathrm{false},             \tag{R}
\]
or there is a real $\rho$ such that
\[
 0\le \rho<10^{d'.\mathit{decimal\_point}-768},
\]
\[
 V(d')=V(d)/2^k-\rho
\]
and
\[
 d'.\mathit{truncated}=\mathrm{true}
 \quad\Longleftrightarrow\quad
 d.\mathit{truncated}=\mathrm{true}\ \text{or}\ \rho>0.
\]
\end{lemma}
\begin{proof}
Put $n=d.\mathit{num\_digits}$, $p=d.\mathit{decimal\_point}$,
$B=2^k$, and let $I$ be the base-ten fold of the stored prefix.  Since
$10^{p-n}>0$, the hypothesis $V(d)>0$ gives $I>0$.  In particular the
prefix contains a nonzero decimal cell.

Unfold \noderef{num_imp_dec2flt_decimal_seq_DecimalSeq_right_shift}.  The
first result loop and its nested zero-extension loop have exactly the
postcondition proved by
\noderef{DecimalRightShiftPrefixLoopSemantics}.  Apply that helper to the
successful call from read index zero, accumulator zero, and false all-zero
flag.  Mapping all 768 cells and then taking $n$ commutes with taking the U8
cells first and then mapping their natural values.  The helper therefore
returns the original record, keeps the all-zero flag false, and supplies an
index $r\ge1$ and accumulator $c$ satisfying
\[
                 B\le c<10B.                             \tag{1}
\]
If $r\le n$, it also gives $r\le768$ and says that $c$ is exactly the fold of
the first $r$ stored digits.  If $r>n$, it gives $n\le768$, $r\le n+k$, and
$c=I10^{r-n}$.  Thus in either phase $r\le828$, so the extracted cast of $r$
to I32, the subtraction of one, and the subsequent decimal-point subtraction
have precisely their ordinary integer meanings.  In particular, they compute
the prospective output point
\[
                          p'=p-(r-1).                    \tag{2}
\]
The constant in
\noderef{num_imp_dec2flt_decimal_seq_DecimalSeq_DECIMAL_POINT_RANGE} is
2047.  If $p'<-2047$, the next branch returns exactly the record (R): it explicitly
sets count and point to zero and the Boolean to false.  This establishes the
first alternative of the lemma without making any claim about the discarded
mathematical value.

Assume henceforth that this reset test is false.  The function forms
$1\ll k$ and subtracts one.  Apply
\noderef{DecimalRightShiftU64DyadicBridge} directly to these successful
extracted Usize-count operations and to each successful quotient and mask
operation in the two output loops.  It gives $B=2^k$, the mask $M=B-1$,
and, for every U64 accumulator $x$ occurring in those applications,
\[
 x\mathbin{\mathtt{>>>}}k=\lfloor x/B\rfloor,\qquad
 x\mathbin{\mathtt{\&}}M=x\bmod B.                       \tag{3}
\]
The same bridge supplies the Euclidean package
\[
 x=(x/B)B+(x\bmod B),\qquad 0\le x\bmod B<B,             \tag{4}
\]
as well as the uniform checked-arithmetic bound
$10(x\bmod B)+a<2^{64}$ for every decimal digit $a<10$.

For the positional account, let $a_0$ be the immutable original digit array,
extend its stored word by an infinite zero tail, and let $A_s$ be the fold of
the first $s$ extended digits.  Thus $A_s=I10^{s-n}$ for $s\ge n$, and
\noderef{DecimalRightShiftPrefixLoopSemantics} gives $c=A_r$, $r\ge1$,
$c<10B$, and, in the case $r\le n$, also $r\le768$.

If $r<n$, apply \noderef{DecimalRightShiftMainLoopSemantics} with limit $n$,
array $a_0$, initial read cursor $r$, initial write cursor zero, and
accumulator $c$.  Its hypotheses are precisely the prefix facts just listed,
the original prefix digit hypothesis, and the successful power, mask, and
main-loop calls obtained by unfolding the right shift.  The helper proves
$n\le768$ and returns a list $E$ of exactly $n-r$ decimal quotient digits,
write count $w=n-r$, terminal accumulator $c_*$ with $c_*<10B$, the entire
emitted prefix in the output array, and preservation of every cell at or
above $w$, in particular the original suffix at and above $n$.  Its exact
long-division equation is
\[
 c10^{n-r}+\operatorname{fold}_{10}(a_0[r:n])
       =B\bigl(10\operatorname{fold}_{10}(E)\bigr)+c_* .       \tag{5}
\]
Because $c=A_r$, the left side is $A_n=I$, so (5) is the required terminal
positional invariant.  The relevant main-loop invariant carries $c_s<10B$,
the cursor equation $w=s-r$, the emitted prefix, and equality of the unread
suffix with $a_0$.  Since $r\ge1$, it gives $w<s$, so the body reads the
immutable original digit $a_0[s]<10$, not a mutable-array surrogate.  With
(3)--(4), its recurrence is
\[
 c_s=Bq_s+e_s,\qquad c_{s+1}=10e_s+a_0[s]
       \le10(B-1)+9<10B                                   \tag{6}
\]
both validates every quotient cast and preserves the strict bound.

If $r\ge n$, the main loop has no body step and returns immediately with
$w=0$ and accumulator $c=A_r$.  This is the same terminal positional
invariant, with an empty emitted list.  If $r=n$, the prefix helper's first
case gives $n\le768$; if $r>n$, its second case gives that bound.  Both cases
also give $c<10B$.  Thus in every case the state entering the final
zero-extension loop has an emitted decimal list, the exact long-division
identity, a write count at most 768, and an accumulator strictly below
$10B$.

There may remain a nonzero remainder accumulator after the input is
exhausted.  Apply \noderef{DecimalRightShiftFinalLoopSemantics} to the
successful final zero-extension call, using the already established
$w\le768$, $c<10B$, and the same successful power and mask operations.  It
supplies a finite decimal-digit list $Z$, terminal array and cursor, and the
exact equation
\[
                   c10^{|Z|}=B\bigl(10F(Z)\bigr).          \tag{11}
\]
Its cursor clause is $w'=\min(w+|Z|,768)$.  Its array clauses say that every
emitted destination below 768 contains the corresponding digit, that cells
below the initial cursor are preserved, and that cells at or above the final
cursor are preserved.  Finally its Boolean clause says exactly that the final
Boolean is the incoming Boolean or some nonzero digit of $Z$ had destination
at least 768.  The helper proves the U64 bounds, quotient cast, exact cap
constant from
\noderef{num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS}, and finite
dyadic termination from the extracted loop body and
\noderef{DecimalRightShiftU64DyadicBridge}; hence these conclusions cover the
whole successful final-loop execution.

At termination the accumulator in (5) is zero.  If $L$ digits have been
emitted, the extended index is $r+L$, so
\[
 A_{r+L}=I10^{r+L-n}=B(10Q_L).
\]
It follows that
\[
 I/B=Q_L10^{n-r-L+1}.                                   \tag{12}
\]
This exponent is exactly the adjustment needed by the prospective point
$p'=p-r+1$.

Let $b_0,\ldots,b_{L-1}$ be the finite decimal expansion emitted by the two
output loops before the cap, let $m=\min(L,768)$, and let
$J$ be the fold of its first $m$ digits.  Equations (2), (5), (6), and (11)
are exactly base-ten long division, so the uncapped expansion represents
$V(d)/B$ at point $p'$.  Define the omitted suffix value
\[
 \rho=\left(\sum_{j=768}^{L-1}b_j10^{L-1-j}\right)
             10^{p'-L},                                  \tag{13}
\]
using zero when $L\le768$.  Then $\rho\ge0$, and it is positive exactly
when at least one omitted output digit is positive.  Splitting the expansion
at index $m$ gives the pre-trim identity
\[
             J10^{p'-m}=V(d)/B-\rho.                     \tag{14}
\]
The pre-trim count is at most 768 by the cap invariant.  Therefore
\noderef{DecimalSeqTrimSemantics} applies to the terminal trim and preserves
both (14) and the truncation Boolean; it also preserves the prospective point
$p'$, so $d'.\mathit{decimal\_point}=p'$.

For the strict loss bound, first suppose the omitted suffix fold is zero.
Then $\rho=0<10^{p'-768}$ because the base 10 is positive.  Otherwise the
suffix is nonempty.  Hence $L>m$, and $m=\min(L,768)$ forces $m=768$.
Every emitted cell is a decimal digit by the two loop postconditions.  A
direct induction on the $L-768$ omitted cells, using
$10A+z<10\cdot10^s$ whenever $A<10^s$ and $z<10$, gives
\[
 \operatorname{fold}_{10}(b_{768},\ldots,b_{L-1})<10^{L-768}.
\]
Multiplication by the positive scale $10^{p'-L}$ now yields
\[
 \rho<10^{L-768}10^{p'-L}=10^{p'-768}
      =10^{d'.\mathit{decimal\_point}-768}.
\]
This estimate concerns only the suffix lost in this right shift.  It makes no
claim about a sum of losses from distinct shifts.  The final Boolean analysis
above is
\[
 d'.\mathit{truncated}
 \Longleftrightarrow d.\mathit{truncated}\ \text{or}\ \rho>0.
\]
Together with $B=2^k$, (14), and the strict estimate, this is precisely the
nonreset alternative of the statement.
\end{proof}
