\begin{lemma}[Branch-complete number-scan accounting]
Let a nonempty source-valid byte slice $s$ render a valid unsigned numeric
lexeme $x$, and suppose \texttt{parse\_number($s$)} returns a record $r$.
Concatenate the integer and fractional digit lists to obtain $S$, delete the
maximal leading zero run to obtain $S^+$, and put
\[
 z=|S|-|S^+|,\qquad P=|x.\mathit{integerDigits}|-z,
 \qquad h=\min(|S^+|,19),
\]
where the subtraction defining $P$ is in the integers.  Let $E$ be the
accumulated signed scientific exponent of $x$.  Then
\[
 r.\mathit{exponent}=P-h+E,\qquad
 0\le h\le19,\qquad -655359\le E\le655359.
\]
In addition, if the returned record has \texttt{many\_digits=true}, its
mantissa is strictly positive.
The definitions and equalities are exactly the nested \texttt{let}s and
conjunctions in Lean.
\end{lemma}
\begin{proof}
Write $I$ and $F$ for the integer and fractional digit lists, taking
$F=[]$ when the fractional field is absent.  Validity in
\noderef{DecimalGoalVocabularyDefault} says every member of $I,F$ is below
ten, at least one of them is nonempty, and any scientific-exponent digit
list is nonempty and decimal.  The render equality therefore decomposes the
slice into the ASCII bytes for $I$, an optional point followed by the bytes
for $F$, and an optional exponent marker, sign, and exponent digits.  The
unsigned-sign hypothesis excludes a leading sign byte.

Put $D=|I|+|F|=|S|$.  Apply
\noderef{NumberHelperDigitScanSourceLength} to the integral digit-byte run.
Its stopping-tail clause says that the returned slice is exactly the suffix
beginning at the point, exponent marker, or end of input; no claim about the
wrapping accumulator is needed.  If the point is present, apply the same
lemma to the fractional run to obtain exactly the suffix beginning at the
exponent marker or end.  The point and exponent marker are nondigits, so the
lemma's stopping hypotheses hold.  By
\noderef{NumberHelperOffsetSourceLength}, the corresponding extracted
offsets have values $|I|$ and $|F|$.  The source-validity bound
\noderef{SourceValidByteSlice} gives every required slice length at most
$2^{63}-1$, so these offsets and their casts are represented.  Unfolding the
ordinary branches of
\noderef{num_imp_dec2flt_parse_parse_partial_number} now shows that the
pre-scientific record exponent is $0$ when $F=[]$ and $-|F|$ when a fraction
is present: the latter is the checked negation of the nonnegative offset,
followed by its exact cast to I64.  Thus in both layouts that exponent is
$-|F|$.

We next audit the many-digit decision.  The extracted initial digit count is
$D$.  The branch $D\le19$ goes directly to the ordinary record, and already
implies $|S^+|\le19$.  Suppose therefore that $D>19$.  Before calling the
adjustment, the extracted subtraction produces
$n=D-19\ge0$.  In the rendered byte layout, let $Q$ be the maximal prefix
consisting only of zero bytes 48 and the optional point byte 46, and let $T$
be the remaining tail.  Maximality gives exactly the stopping alternative
required by \noderef{NumberHelperAdjustManyExact}: $T=[]$, or its first byte
is neither 48 nor 46.  The zero bytes in $Q$ are precisely the $z$ leading
zeros of $S$, even when the run crosses the point, hence
$\operatorname{count}(Q,48)=z$.  Also $0\le n\le |s|$.  Finally
\[
 n-z\ge-z\ge-D\ge-|s|\ge-(2^{63}-1)>-2^{63},
\]
which supplies the helper's Isize lower-bound premise.  Its remaining
length, initial-count, and upper-bound premises follow respectively from
source validity, $n\ge0$, and $n\le|s|$.  Therefore
\noderef{NumberHelperAdjustManyExact} returns the exact corrected count
\[
 a=n-z=D-z-19=|S^+|-19.                    \tag{1}
\]
Consequently the extracted positive test chooses the retry exactly when
$|S^+|>19$; otherwise it chooses the ordinary record and
$|S^+|\le19$.

Consider first an ordinary record.  If $S^+\ne[]$, its length is at most
19, so $h=|S^+|$.  Since deletion of the maximal zero prefix gives
\[
 h=|S^+|=D-z=|I|+|F|-z,
\]
the definition $P=|I|-z$ yields the required, correctly oriented equality
\[
 P-h=(|I|-z)-(|I|+|F|-z)=-|F|.             \tag{2}
\]
This is exactly the ordinary pre-scientific exponent above.  If every
significand digit is zero, then instead $S^+=[]$, $h=0$, and
$z=D=|I|+|F|$; hence $P=|I|-z=-|F|$ and again $P-h=-|F|$.  This explicitly
covers the all-zero integral, fractional, and point-crossing layouts without
using a nonempty-tail argument.

Now suppose the retry is selected, so (1) gives $|S^+|>19$ and $h=19$.
Apply \noderef{NumberHelperManyRetryAccounting} with the exact integral and
fractional suffixes established above, the maximal decomposition
$S=ZS^+$, and the successful extracted retry.  Its two layout clauses state
uniformly that the retry consumes exactly the first nineteen post-zero digit
positions, even when they cross the optional point, and that the returned
mantissa $m$ and pre-scientific exponent $q$ satisfy
\[
 10^{18}\le m<10^{19},\qquad
 q=e+|I|-z-19=e+P-h,                       \tag{3}
\]
where $e$ is the exponent passed to the retry.  Thus this branch supplies
both the exact exponent accounting and $m>0$, the latter proving the final
mantissa implication whenever \texttt{many\_digits=true}.

It remains to identify $e$ and the final scientific addition.  If there is
no exponent suffix, the extracted branches pass $e=0$ to the retry and make
no addition to an ordinary record; put $E=0$.  Then (2) and (3) respectively
give $r.\mathit{exponent}=P-h+E$, and the requested bounds on $E$ are
immediate.

If an exponent suffix is present, apply
\noderef{NumberHelperScientificExact}.  Its exact result is the signed fold
specified in the statement, so it is precisely $E$.  At an updating step
the old accumulator satisfies $a<65536$, hence $a\le65535$, and its decimal
digit $r$ satisfies $0\le r\le9$; therefore
$10a+r\le10\cdot65535+9=655359$.  Once the accumulator is at least 65536 the
fold leaves it unchanged.  Induction over the nonempty exponent digit list
therefore gives $0\le |E|\le655359$, and the optional minus sign gives
$-655359\le E\le655359$.  In the retry branch the extracted call passes this
$E$ as the incoming $e$, so (3) is the conclusion directly.  In the
ordinary fractional branch the checked final I64 addition combines
$-|F|$ with $E$; in the integral branch it combines $0$ with $E$.
Case analysis on that checked operation in
\noderef{num_imp_dec2flt_parse_parse_partial_number} rules out failure and divergence
because the whole call is assumed to return $r$, and its successful case has
integer value $(P-h)+E$ by (2).  Hence every present-suffix branch also has
$r.\mathit{exponent}=P-h+E$.  Finally $h=\min(|S^+|,19)$ is a natural number
between zero and 19, completing every conjunct.
\end{proof}
