\begin{lemma}[Exact semantics of decimal-sequence trimming]
Let $d$ be a decimal sequence whose stored count is at most the length of its
768-cell digit array, and suppose the extracted \texttt{trim} operation
returns $d'$.  Then the digit array, decimal point, and truncation Boolean of
$d'$ equal those of $d$.  Its count $n'$ is at most the old count $n$; every
cell with index $n'\le q<n$ is zero; and either $n'=0$ or cell $n'-1$ is
nonzero.  Finally, for
\[
 V(e)=\operatorname{fold}_{10}(e.\mathit{digits}[0:e.\mathit{num\_digits}])
       10^{e.\mathit{decimal\_point}-e.\mathit{num\_digits}},
\]
one has $V(d')=V(d)$.
\end{lemma}
\begin{proof}
Write $n$ for the initial count, $a$ for the digit array, and
\[
 F(i)=\operatorname{fold}_{10}(a[0:i]).
\]
Apply the result-loop induction principle \noderef{ResultLoopPartial} to the
extracted trim loop with invariant
\[
 i\le n,\qquad i\le |a|,\qquad
 (\forall q,\ i\le q<n\Rightarrow a[q]=0),\qquad
 F(n)=F(i)10^{n-i}.                                    \tag{1}
\]
At the initial state $i=n$, both bounds are immediate, the quantified index
interval is empty, and the fold equation is $F(n)=F(n)10^0$.

Consider one normally returning loop-body step.  If $i=0$, the body finishes
with zero.  If $i>0$, unsigned subtraction of one is in range and returns
$i-1$.  The invariant gives $i\le|a|$, so $i-1<|a|$ and the array read at
$i-1$ is also in range.  If that cell is nonzero, the body finishes with
$i$.  Thus (1) still holds and the returned count has the required nonzero
last cell.

If instead $a[i-1]=0$, the body continues at $i-1$.  The two bounds in (1)
are preserved by decrementing.  The old zero-suffix assertion already covers
all $q\ge i$; its one new index $q=i-1$ is zero by the branch test, so it now
covers every $q\ge i-1$.  For the fold equation, the last-cell decomposition
of the base-ten fold gives
\[
 F(i)=10F(i-1)+a[i-1]=10F(i-1).
\]
Substituting this into (1), and using
$n-(i-1)=(n-i)+1$, gives
\[
 F(n)=10F(i-1)10^{n-i}=F(i-1)10^{n-(i-1)}.
\]
This proves preservation of the entire invariant.  The cited loop-induction
principle therefore shows that a normal terminal count $n'$ satisfies (1),
and the body's only terminal cases show additionally that $n'=0$ or the last
retained cell is nonzero.

The outer extracted operation first asserts $n\le768$.  The stated array
bound proves this because the fixed array length is 768.  It then runs the
loop and updates only \texttt{num\_digits}; hence the returned digit array,
decimal point, and truncation Boolean are unchanged.  Equation (1) at $n'$
is
\[
                         F(n)=F(n')10^{n-n'}.           \tag{2}
\]
Since $n'\le n$, integer exponent arithmetic gives
\[
 p-n'=(p-n)+(n-n').                                    \tag{3}
\]
Cast (2) to the reals, expand $10^{p-n'}$ using (3), and reassociate the
products.  The factor $10^{n-n'}$ introduced into the retained fold is
exactly cancelled by the reduction of the stored count in the decimal
exponent.  Therefore
\[
 F(n')10^{p-n'}=F(n)10^{p-n},
\]
which is precisely $V(d')=V(d)$.
\end{proof}
