\begin{lemma}[Safe partial-number parsing of an invalid unsigned input]
Let $s$ be a source-valid, nonempty byte slice of length at most
$9223372036854120459$.  If its complete byte sequence is not the rendering
of any valid numeric lexeme having no leading sign, then the extracted
\texttt{parse\_partial\_number} returns normally.  Moreover, whenever its
return is \texttt{Some} of a decimal record and consumed length, that length
is not the full input length.
\end{lemma}
\begin{proof}
Write $M=2^{63}-1=9223372036854775807$,
$B=9223372036854120459=M-655348$, and $L=|s|$.  By
\noderef{Assumptions}, \texttt{usize} and \texttt{isize} are 64-bit.  Thus
$L\leq B<M$; every input length and guarded index below fits
\texttt{usize}, and every cast of a length to nonnegative \texttt{isize} is
exact.  By \noderef{SourceValidByteSlice}, the separate source-validity
premise is compatible with this stronger bound.  The last premise, using
the definitions in \noderef{DecimalGoalVocabularyDefault}, says precisely
that the whole input is not a valid unsigned numeric rendering.

First consider the two loops in
\noderef{num_imp_dec2flt_parse_try_parse_digits}.  The eight-byte loop reads
only after its remaining-length guard proves that the first eight bytes
exist.  The implementation in
\noderef{SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_read_u64}
therefore copies an in-bounds prefix and returns its little-endian word; a
continuing iteration drops exactly those eight bytes.  Each continuation
strictly reduces the remaining length, so the loop terminates.

The test in \noderef{num_imp_dec2flt_common_is_8digits} has no false
positive.  Indeed, write the bytes of its word as $b_0,\ldots,b_7$.  Its
three constants consist bytewise of \texttt{0x46}, \texttt{0x30}, and
\texttt{0x80}.  Let $d_i$ be the borrow entering byte $i$ of subtraction by
\texttt{0x30}, initially zero.  If the test is true, the high bit of every
result byte is zero.  Inductively, $b_i<48$ would give a subtraction result
in $[208,255]$, a contradiction; hence there is no outgoing borrow and
$48\leq b_i\leq175$.  Let $c_i$ be the carry entering byte $i$ of addition
by \texttt{0x46}, again initially zero.  Under the preceding bound,
$b_i\geq58$ would give a result in $[128,245]$, a contradiction.  Thus there
is no outgoing carry and $48\leq b_i\leq57$.  These two inductions cover all
eight bytes, including cross-byte carries and borrows.

Consequently every call of
\noderef{num_imp_dec2flt_parse_parse_8digits} receives a word whose bytes
are decimal digits.  Its checked subtraction by eight copies of
\texttt{0x30} has no borrow and produces a word $v'<2^{60}$.  The checked
multiplication by ten is below $10\cdot2^{60}<2^{64}$.  The checked shift by
eight is defined and below $2^{52}$, so the following checked addition is
below $10\cdot2^{60}+2^{52}<2^{64}$.  Its shifts by $16$ and $32$ are also
defined; intervening masked products and their addition are wrapping.  The
word after the final right shift is at most $2^{32}-1$, so its checked cast
to \texttt{u32}, and the widening back to \texttt{u64}, are exact.

The eight-byte accumulator operations are wrapping.  In the scalar loop,
the index test justifies every byte access, subtraction and accumulator
arithmetic are wrapping, the byte-to-\texttt{u64} cast is exact, and the
checked count increment remains at most the slice length.  The final suffix
therefore starts at an in-bounds count.  This establishes normal termination
of a digit scan on arbitrary bytes, not just on digit-only slices, and also
shows that its returned slice is a suffix of its argument consisting of the
unconsumed bytes.

Unfold \noderef{num_imp_dec2flt_parse_parse_partial_number}.  Its opening
nonempty assertion holds.  Every call of
\noderef{SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from}
compares the original slice, or the slice after a point, with a suffix just
constructed.  Both length casts lie in $[0,L]$, and their checked difference
is the corresponding consumed length.  Let $I$ and $F$ be the numbers of
integer and fractional digits scanned and put $D=I+F$.  We have
$0\leq I,F,D\leq L$.  If a point was consumed, $-F$ lies in the signed
range and its cast to \texttt{i64} is exact.  The checked addition producing
$D$ is safe.  If $D=0$, the function returns \texttt{None} normally.

Assume henceforth that $D>0$.  With no following \texttt{e} or \texttt{E},
there is no explicit-exponent arithmetic.  Otherwise unfold
\noderef{num_imp_dec2flt_parse_parse_scientific}.  Removing an optional sign
is guarded.  An empty signed suffix, or a nondigit first byte, returns
\texttt{None} normally.  The option branch and residual operations modeled
by \noderef{ModelOptionBranch} and \noderef{ModelOptionFromResidual} then
make the partial parser return \texttt{None} normally.

If exponent digits are present, let $q\geq1$ be their consumed count.  At
each iteration the index is below the suffix length and its increment stays
at most $L$.  While the nonnegative accumulator $a$ is below $65536$, its
checked update satisfies
$10a+d\leq10\cdot65535+9=655359<2^{63}$; afterward the guard leaves it
unchanged.  Final negation is therefore safe.  This is also the loop
invariant formalized by
\noderef{NumberHelperScientificExponentBounds}: the returned explicit
exponent $E$ satisfies $|E|\leq655359$.

The first-pass exponent is $-F+E$.  Its upper side is at most $655359$.
If $E\geq0$, its lower side is at least $-F\geq-B>-2^{63}$; if $E<0$ and
$F=0$, it is at least $-655359$.  Suppose $E<0$ and $F>0$.  Were the suffix
after the exponent empty, the already scanned bytes would consist of the
integer digits, point, $F$ fractional digits, exponent marker, minus sign,
and $q$ exponent digits.  Since $D>0$, these components form a valid complete
unsigned numeric lexeme under
\noderef{DecimalGoalVocabularyDefault}, contrary to the hypothesis.  Hence
at least one unmatched byte remains, and counting the point, marker, minus,
$q$ digits, and that byte gives $F\leq L-(q+4)$.  For $q\leq5$, decimal
accumulation gives $|E|\leq10^q-1$; for $q\geq6$, it gives
$|E|\leq655359$.  Therefore
\[
 F+|E|\leq
 \begin{cases}
 L-(q+4)+(10^q-1)\leq L+99990,&q\leq5,\\
 L-(q+4)+655359\leq L+655349,&q\geq6.
 \end{cases}
\]
The second expression is maximal at $q=6$, and
$L+655349\leq B+655349=M+1=2^{63}$.  Equality is permitted for the
negative endpoint, so $-F+E$ cannot overflow.  All first-pass exponent
additions, offsets, and casts are thus normal.

It remains to check the $D>19$ path.  The checked subtraction starts
\noderef{num_imp_dec2flt_parse_adjust_many_digit_count} at
$n_0=D-19\geq1$.  Every access is index-guarded.  Its constant subtraction
is $48-1=47$; saturating subtraction of $47$ from a point gives zero and
from a zero digit gives one, both exactly castable to \texttt{isize}.
After $i$ index-advancing iterations, let $z_i$ be the number of visited zero
digits.  Induction over the point and zero branches gives
\[
 n_i=D-19-z_i,\qquad 0\leq z_i\leq i\leq L.
\]
Hence $n_i\geq1-L> -2^{63}$ and $n_i\leq D-19\leq L<2^{63}$, proving every
checked signed subtraction safe; every index increment is at most $L$.

If the final $n_i$ is positive, then $z_i<D-19<D$.  The scan cannot have
passed every significand digit, since doing so would require all of them to
be zero and hence $z_i\geq D$.  It stops at a nonzero digit within the
original significand, with at least $D-z_i\geq20$ digit bytes remaining.
If its final value is nonpositive, no retry occurs.

For a retry, \noderef{num_imp_dec2flt_parse_MIN_19DIGIT_INT} is exactly
$10^{18}$.  In \noderef{num_imp_dec2flt_parse_try_parse_19digits}, a checked
update occurs only below this threshold, and is at most
$10(10^{18}-1)+9=10^{19}-1<2^{64}$.  All byte casts and splits are exact or
guarded.  If the first retry reaches the threshold, the offset from its
suffix to the saved integer end is a nonnegative number at most $L$, so its
casts are safe.  If it remains below the threshold, it cannot have consumed
nineteen of the at least twenty remaining digits: starting with a nonzero
digit, the exact recurrence after nineteen digits is at least $10^{18}$.
Thus it must stop at the saved point.  Skipping that point is in bounds, and
the second retry consumes at most $F$ fractional digits.  Its offset $R$ is
in $[0,F]$, so checked negation and conversion give a base in $[-F,0]$.

Finally unfold \noderef{num_imp_dec2flt_parse_parse_many_digits}.  In its
nonnegative integer-offset branch without an explicit exponent, the base is
at most $L$; a negative exponent only lowers it by at most $655359$.  With a
positive $q$-digit exponent, at least nineteen digits, the marker, and the
$q$ exponent digits lie outside that remaining offset.  The final sum is at
most $L-q-20+(10^q-1)\leq L+99974$ for $q\leq5$, and at most
$L-q-20+655359\leq L+655333$ for $q\geq6$; both are below $2^{63}$ at
$L\leq B$.  In the fractional branch the base is $-R$ with $R\leq F$.
Its upper side is at most $655359$, and its lower side follows from the
already proved $F+|E|\leq2^{63}$.  Thus every retry addition is safe.

We have exhausted the assertions, guarded slices and indexes, checked
offsets and casts, count arithmetic, negations, digit updates, and exponent
additions in the partial parser, so it returns \texttt{ok} of some option.
Suppose this option were \texttt{Some} with consumed length $L$.  The scans
then provide at least one significand digit; a point, if present, occurs in
its single scanned position; and an exponent, if present, has its marker,
optional sign, and at least one scanned digit.  Translating each digit byte
$48+d$ back to $d<10$ constructs a \texttt{DecimalLexeme} with
\texttt{leadingSign = None}, satisfying
\noderef{DecimalGoalVocabularyDefault}.  Full consumption makes its rendered
bytes exactly $s$.  This contradicts the assumed absence of such a lexeme.
Therefore every \texttt{Some} result has consumed length different from the
full input length, as required.
\end{proof}
