NumberHelperAccumulatedValue

Lean checked

Statement

This explanation was written alongside the formalization to describe the statement and its reasoning.

Theorem

For every nonempty unsigned numeric byte slice and returned record d, if many_digits is false then d.\mathit{mantissa}\,10^{d.\mathit{exponent}} equals the literal's accumulated-exponent value; if it is true, that value lies in the half-open interval from d.\mathit{mantissa}\,10^{d.\mathit{exponent}} to (d.\mathit{mantissa}+1)10^{d.\mathit{exponent}}.

Lean statement

Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.

import Tablet.Assumptions
import Tablet.DecimalGoalVocabularyDefault
import Tablet.ModelOptionBranch
import Tablet.ModelOptionFromResidual
import Tablet.ModelSliceSplitFirst
import Tablet.ModelU64BitAnd
import Tablet.ModelU64BitOr
import Tablet.ModelU8IsAsciiDigit
import Tablet.NumberHelperAdjustManyExact
import Tablet.NumberHelperDecimalPrefixInterval
import Tablet.NumberHelperDigitScanExact
import Tablet.NumberHelperDigitScanSourceLength
import Tablet.NumberHelperFractionalManyExact
import Tablet.NumberHelperIntegralManyExact
import Tablet.NumberHelperOffsetSourceLength
import Tablet.NumberHelperParseEightDigitsExact
import Tablet.NumberHelperScientificExact
import Tablet.NumberHelperSplitExponentSuffix
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_read_u64
import Tablet.SourceValidByteSlice
import Tablet.U64_Insts_CoreOpsBitBitAndU64U64
import Tablet.U64_Insts_CoreOpsBitBitOrU64U64
import Tablet.num_imp_dec2flt_common_is_8digits
import Tablet.num_imp_dec2flt_decimal_Decimal
import Tablet.num_imp_dec2flt_parse_MIN_19DIGIT_INT
import Tablet.num_imp_dec2flt_parse_adjust_many_digit_count
import Tablet.num_imp_dec2flt_parse_parse_8digits
import Tablet.num_imp_dec2flt_parse_parse_8digits_MASK
import Tablet.num_imp_dec2flt_parse_parse_8digits_MUL1
import Tablet.num_imp_dec2flt_parse_parse_8digits_MUL2
import Tablet.num_imp_dec2flt_parse_parse_many_digits
import Tablet.num_imp_dec2flt_parse_parse_number
import Tablet.num_imp_dec2flt_parse_parse_partial_number
import Tablet.num_imp_dec2flt_parse_parse_scientific
import Tablet.num_imp_dec2flt_parse_try_parse_19digits
import Tablet.num_imp_dec2flt_parse_try_parse_digits

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 1000000
set_option maxRecDepth 10000

namespace dec2flt_model

-- [TABLET NODE: NumberHelperAccumulatedValue]
theorem NumberHelperAccumulatedValue :
    ∀ (s : Slice Std.U8) (x : DecimalLexeme) d, SourceValidByteSlice s -> s.val ≠ [] -> x.leadingSign = none ->
      DecimalGoalVocabularyDefault.validNumeric x -> DecimalGoalVocabularyDefault.bytes s = DecimalGoalVocabularyDefault.renderNumeric x ->
      num.imp.dec2flt.parse.parse_number s = ok (some d) ->
      (d.many_digits = false ∧ DecimalGoalVocabularyDefault.decimalMagnitude d = DecimalGoalVocabularyDefault.accumulatedMagnitude x) ∨
      (d.many_digits = true ∧ DecimalGoalVocabularyDefault.decimalMagnitude d <= DecimalGoalVocabularyDefault.accumulatedMagnitude x ∧
        DecimalGoalVocabularyDefault.accumulatedMagnitude x <
          ((d.mantissa.val + 1 : Nat) : Real) * (10 : Real) ^ d.exponent.val) := by
Proof

Natural-language proof

The status above describes the Lean proof. Its explanatory prose may remain a sketch after that proof closes.

Explanatory prose status

Prose retained as authored. The explanatory prose is preserved as it stood when captured.

Proof

Fix s,x,d satisfying the hypotheses. Unfold DecimalGoalVocabularyDefault. Because the leading-sign field is none, the rendering premise says that the byte values of s are exactly
I\;[46\;F]\;[c\;\sigma\;H], \tag{1}
where I is the list of integer digit bytes, F is the list of fractional digit bytes when the optional fraction is present (and is empty otherwise), and the bracketed components are omitted when their corresponding option is absent. Here c is 101 or 69 according as the exponent spelling uses e or E, \sigma is empty, [43], or [45], and H is the nonempty exponent-digit list. Validity says that every digit value is in \{0,\ldots,9\} and that at least one digit occurs in I F.
Remove 48 from every byte in I F and use the same letters for the resulting digit lists. Define
\begin{split} D&=|I|+|F|,\qquad F_{\!\ell}=|F|,\\ Z&=\operatorname{foldl}(a,r\mapsto10a+r,0,I F),\\ E&=\mathsf{accumulatedExplicitExponent}(x), \end{split} \tag{2}
and let z be the number of leading zeroes in I F, so 0\le z\le D and z=D exactly in the all-zero case. Directly from the unfolded vocabulary,
\mathsf{accumulatedMagnitude}(x)=Z\,10^{E-F_{\!\ell}}. \tag{3}
The powers here and below are integer powers in the reals.
We first establish the scanner facts needed to justify that the extracted wrapping arithmetic really has the advertised decimal meaning. In a bulk iteration of num imp dec2flt parse try parse digits, the guard gives at least eight remaining bytes. Therefore SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice read u64 has an in-bounds prefix of length eight, its copy has equally sized source and destination, and its little-endian result is
v=\sum_{j=0}^{7}b_j2^{8j}. \tag{4}
The later range-from-eight operation is in bounds under the same guard and deletes exactly this prefix.
The test num imp dec2flt common is 8digits uses wrapping addition by 0x4646464646464646, wrapping subtraction by 0x3030303030303030, disjunction, and the high-bit mask 0x8080808080808080. The conjunction and disjunction have their exact bounded-word meanings by U64 Insts CoreOpsBitBitAndU64U64, U64 Insts CoreOpsBitBitOrU64U64, ModelU64BitAnd, and ModelU64BitOr. To check the test bytewise, let r_j be the borrow entering byte j of the subtraction and q_j the carry entering byte j of the addition. Both start at zero. If r_j=0 and b_j<48, the subtraction byte is in [208,255], contradicting the accepted zero high bit. Induction from the low byte therefore gives b_j\ge48 and r_{j+1}=0; the same high-bit condition first gives b_j\le175. If now q_j=0 and b_j\ge58, the addition byte lies in [128,245], another contradiction. Hence b_j\le57 and q_{j+1}=0. Conversely bytes in [48,57] create neither carries nor borrows and make every masked high bit zero. Thus the test accepts exactly eight ASCII digits b_j=48+r_j' with 0\le r_j'\le9.
For such a block, unfold num imp dec2flt parse parse 8digits. Its checked subtraction by 0x3030303030303030 has no borrow and gives v'=\sum_j r_j'2^{8j}\le\texttt{0x0909090909090909}<2^{60}. Thus 10v'<2^{64} and
q=10v'+(v'\mathbin{\mathtt{>>>}}8)<10\cdot2^{60}+2^{52}<2^{64};
the checked product and sum succeed, and the shifts by 8, 16, and 32 are all defined 64-bit shifts. There is no byte carry in q: its bytes are 10r_j'+r_{j+1}' for j<7 and 10r_7' in the top byte. By num imp dec2flt parse parse 8digits MASK, num imp dec2flt parse parse 8digits MUL1, and num imp dec2flt parse parse 8digits MUL2, the three constants are
M=2^{32}\!\cdot255+255,\qquad M_1=100+10^6 2^{32},\qquad M_2=1+10^4 2^{32}.
After the masks write the two words as
a=A+B2^{32},\quad b=C+G2^{32},
with A=10r_0'+r_1', C=10r_2'+r_3', B=10r_4'+r_5', and G=10r_6'+r_7'. Reducing the two deliberately wrapping products modulo 2^{64} gives
aM_1\equiv100A+(10^6A+100B)2^{32},\qquad bM_2\equiv C+(10^4C+G)2^{32}.
The low coefficient 100A+C is at most 9999, and the high coefficient 10^6A+100B+10^4C+G is at most 99999999, both below 2^{32}. Consequently the wrapping sum has no additional wrap, its shift by 32 is
10^7r_0'+10^6r_1'+\cdots+10r_6'+r_7'<10^8,
and the checked cast to u32 and widening to u64 are exact. This proves the exact eight-digit decoding, with every checked operation in that path discharged.
It follows by induction over the bulk and scalar loops of num imp dec2flt parse try parse digits that the returned slice is the suffix at the first nondigit, for an arbitrarily long digit run. The bulk update appends the decoded block by the wrapping operation a\mapsto10^8a+B; the scalar update recognizes a digit because wrapping subtraction by 48 is below 10 exactly on bytes 48 through 57, casts that digit exactly, and appends it by a\mapsto10a+r. Both updates may wrap on a long run, but neither can fail. Moreover, whenever every position before the first nonzero contributes zero to accumulator zero and at most nineteen positions remain from that first nonzero onward, the updates are ordinary integer arithmetic: every intermediate value is below
10^{19}=10000000000000000000<2^{64}.
All bulk suffixes use the length-eight guard; every scalar access and count increment uses count < len; and the final suffix begins at a count no greater than the slice length. Since each loop removes or counts a positive number of bytes when continuing, these inductions also cover loop termination.
Apply the suffix part of this invariant first to I and then, when the byte 46 is present, to F. The exact empty-versus-head/tail behavior of ModelSliceSplitFirst identifies that point and its following suffix. Thus the two scanner results delimit precisely the runs in (1). For the two calls of SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice offset from, the difference of suffix lengths is respectively |I| and |F|. By SourceValidByteSlice, |s|\le2^{63}-1, and Assumptions fixes Usize and Isize at 64 bits. Hence both suffix lengths cast to Isize, their nonnegative differences are in range, the fractional difference can be negated and cast to i64, and the checked sum forming n_digits1 succeeds with exact value D\le|s|. Before a scientific suffix is added, the exponent variable is therefore exactly -F_{\!\ell}.
We next compute that suffix. Unfold num imp dec2flt parse parse scientific. By ModelSliceSplitFirst, its first split removes exactly a present minus or plus byte and removes nothing when \sigma is empty. Since H is nonempty, the zero index is in bounds, and ModelU8IsAsciiDigit makes the initial digit test true. In the loop, at a state (a,j) with j<|H|, the indexed byte is 48+r_j and wrapping subtraction returns r_j<10. The update is exactly
a\longmapsto \begin{cases}10a+r_j,&a<65536,\\a,&a\ge65536, \end{cases} \tag{5}
and the count increases by one. Induction gives the same guarded fold as the definition of E in DecimalGoalVocabularyDefault. Whenever the multiplication is taken, 0\le a\le65535, so 10a+r_j\le655359<2^{63}; its checked multiplication, digit cast, and addition all succeed. The guarded count is at most |H|\le|s|<2^{64}, so its checked increment and the final range-from-count slice also succeed. After every digit is consumed, the sign branch either retains this value or negates a number at most 655359, safely and exactly. The result is some E and the suffix following all of H.
The definition num imp dec2flt parse parse partial number invokes this computation only after seeing exactly byte 101 or 69. At its option try step, ModelOptionBranch maps the proved some E to Continue E; ModelOptionFromResidual confirms that only the excluded none case could take the residual route. The checked addition to the pre-scientific exponent, on the hypothesized normally returned record path, is therefore the ordinary signed sum E-F_{\!\ell}. In the absent-exponent case the remaining slice is already empty and E=0. Equation (1) excludes every other suffix byte. All final offsets are differences of suffix lengths bounded by |s| and cast exactly by the same 64-bit argument. Consequently the returned length is |s|.
It remains to identify which mantissa branch is used. When D\le19, the ordinary-scanner condition proved above applies to all of I F, so the accumulator is exactly Z. The corresponding record literal has
d.\mathit{many\_digits}=\texttt{false},\quad d.\mathit{mantissa}=Z,\quad d.\mathit{exponent}=E-F_{\!\ell}. \tag{6}
Suppose D>19. The initial checked subtraction produces D-19. In num imp dec2flt parse adjust many digit count, scanning byte 46 subtracts \operatorname{sat}(46-47)=0, scanning byte 48 subtracts \operatorname{sat}(48-47)=1, and the index advances in either case. The first other byte changes the flag to false without advancing, and the next iteration returns. Thus it passes exactly the leading zero digits of I F while ignoring their possible intervening point, and returns
A=D-19-z. \tag{7}
This remains true when every significand digit is zero: the scan then reaches the exponent marker or the end after subtracting all D zeroes. Every access is guarded by the source length; the scan index is at most |s|; and all signed states lie between -19 and D-19, within 64-bit Isize. Thus every index increment, cast, and checked subtraction succeeds.
If A\le0, (7) gives D-z\le19. The scanner stays at accumulator zero through the first z digits and has at most nineteen positions afterward, so the ordinary-scanner invariant again gives mantissa Z. The third record branch has exactly the same fields as (6). This includes the all-zero case, where z=D, Z=0, and A=-19.
Now suppose A>0. Equation (7) gives
D-z\ge20. \tag{8}
We trace the retry rather than assuming its intended behavior. The constant in num imp dec2flt parse MIN 19DIGIT INT is 10^{18}. In num imp dec2flt parse try parse 19digits, a loop state a<10^{18} is split exactly into empty or head/tail by ModelSliceSplitFirst. A nondigit stops without consuming it. A digit r gives checked arithmetic
10a\le(10^{18}-1)10<2^{64},\qquad 10a+r\le10^{19}-1<2^{64}. \tag{9}
The digit cast is exact, so the update appends that digit ordinarily. The next iteration stops as soon as a\ge10^{18}. Starting before the first nonzero, leading zeroes leave a=0; after the first nonzero, exactly nineteen digit positions make 10^{18}\le a<10^{19}. Thus, under (8), the combined retry obtains precisely the first nineteen digits beginning at the first nonzero, as a number m with
10^{18}\le m<10^{19}. \tag{10}
For completeness, unfold num imp dec2flt parse parse many digits and separate its two routes. Its first call starts at the beginning of s. If it reaches nineteen post-leading-zero positions before byte 46, its result already satisfies the 10^{18} guard and is retained. Its remaining suffix is before the saved integer-end suffix; hence the offset offset_from(int_end,start1) is the exact number
|I|-z-19 =-F_{\!\ell}+(D-z-19). \tag{11}
If the first call returns below 10^{18}, (8) shows that it cannot have reached the end of all significand digits; it stopped exactly at byte 46. Therefore the range-from-one operation is in bounds and starts at the first fraction digit. The second call starts with the already accumulated integer digits, passes any still-leading fractional zeroes, and stops after the nineteenth post-leading-zero position. If it consumes r fractional positions, its suffix offset is r; the extracted negation consequently gives
-r=-F_{\!\ell}+(D-z-19), \tag{12}
because D-z-19 fractional positions remain. Equations (9) discharge every checked mantissa multiplication and addition on both routes. The first range-from-one is guarded by the proved point byte, each split is exact, and both offsets and their negation are within [-(2^{63}-1),2^{63}-1] by Assumptions and SourceValidByteSlice; their casts to i64 are exact. Finally, normal return of the hypothesized record implies that the checked addition of E succeeds. Since checked signed addition agrees with integer addition when it succeeds, (11) and (12) both give
d.\mathit{many\_digits}=\texttt{true},\quad d.\mathit{mantissa}=m,\quad d.\mathit{exponent}=E-F_{\!\ell}+k,\qquad k=D-z-19>0. \tag{13}
These cases exhaust every record literal in num imp dec2flt parse parse partial number: no exponent, lower-case e, and upper-case E, each followed by the D\le19, D>19,A>0, or D>19,A\le0 decision. Unfolding num imp dec2flt decimal Decimal identifies the displayed literal's mantissa, exponent, and many-digits entries with the corresponding projections used in the theorem. Unfolding num imp dec2flt parse parse number, an ok (some d) result can only bind such a some (d,\ell) and pass the final test \ell=|s|; it does not alter the record. The execution just analyzed does pass that test, and any failed checked operation would instead have propagated a failure, so no unaccounted failing path can produce the assumed result.
In either false branch, (3) and (6) immediately give
\mathsf{decimalMagnitude}(d) =Z10^{E-F_{\!\ell}} =\mathsf{accumulatedMagnitude}(x).
In the true branch, deleting the z leading zeroes does not change Z. Let R be the ordinary value of the remaining k digits after the nineteen digits represented by m. Positional notation gives
Z=m10^k+R,\qquad 0\le R<10^k. \tag{14}
For every integer q, the real number 10^q is strictly positive and the integer-power law gives 10^k10^q=10^{q+k}. Multiplying (14) by the positive 10^{E-F_{\!\ell}} and using (3) and (13) yields
m10^{d.\mathit{exponent}} \le \mathsf{accumulatedMagnitude}(x) <(m+1)10^{d.\mathit{exponent}}.
Unfolding decimalMagnitude and using d.\mathit{mantissa}.\mathit{val}=m is exactly the required half-open interval. Together with the two false branches, this proves the stated disjunction.

Lean proof


  intro s x d hsource hne hsign hvalid hbytes hparse
  rcases x with ⟨sign, ints, frac, expo⟩
  simp only at hsign
  subst sign
  simp [DecimalGoalVocabularyDefault] at hvalid hbytes ⊢
  rcases hvalid with ⟨hints, hfrac, hsome, hexpo⟩
  have hlen : s.val.length <= 9223372036854775807 := by
    simpa [SourceValidByteSlice] using hsource
  have byte_digits : forall (bs : List Std.U8) (ds : List Nat),
      List.map (fun b : Std.U8 => b.val) bs =
        List.map (fun d : Nat => 48 + d) ds ->
      (forall d, List.Mem d ds -> d < 10) ->
      forall b, List.Mem b bs -> 48 <= b.val /\ b.val <= 57 := by
    intro bs ds hmap hds b hb
    have hbmap : b.val ∈ List.map (fun b : Std.U8 => b.val) bs :=
      List.mem_map_of_mem hb
    rw [hmap] at hbmap
    obtain ⟨digit, hdigit, hdigitVal⟩ := List.mem_map.mp hbmap
    have := hds digit hdigit
    omega
  let digitStep : Nat -> Std.U8 -> Nat :=
    fun a b => 10 * a + (b.val - 48)
  let natStep : Nat -> Nat -> Nat := fun a digit => 10 * a + digit
  have unrender_digits : forall (bs : List Std.U8) (ds : List Nat),
      List.map (fun b : Std.U8 => b.val) bs =
        List.map (fun digit : Nat => 48 + digit) ds ->
      (forall digit, List.Mem digit ds -> digit < 10) ->
      List.map (fun b : Std.U8 => b.val - 48) bs = ds := by
    intro bs ds hmap hds
    calc
      List.map (fun b : Std.U8 => b.val - 48) bs =
          List.map (fun n : Nat => n - 48)
            (List.map (fun b : Std.U8 => b.val) bs) := by
              simp [List.map_map]
      _ = List.map (fun n : Nat => n - 48)
            (List.map (fun digit : Nat => 48 + digit) ds) := by rw [hmap]
      _ = ds := by
        have cancel : forall xs : List Nat,
            List.map (fun n : Nat => n - 48)
                (List.map (fun digit : Nat => 48 + digit) xs) = xs := by
          intro xs
          induction xs with
          | nil => rfl
          | cons digit xs ih =>
            simp only [List.map_cons, Nat.add_sub_cancel_left]
            exact congrArg (List.cons digit) ih
        exact cancel ds
  have u8_list_eq_of_val_map : forall xs ys : List Std.U8,
      xs.map (fun b : Std.U8 => b.val) =
        ys.map (fun b : Std.U8 => b.val) -> xs = ys := by
    intro xs
    induction xs with
    | nil =>
      intro ys h
      cases ys <;> simp_all
    | cons x xs ih =>
      intro ys h
      cases ys with
      | nil => simp at h
      | cons y ys =>
        simp only [List.map_cons, List.cons.injEq] at h
        have hxy : x = y := UScalar.eq_of_val_eq h.1
        subst y
        rw [ih ys h.2]
  have split_val_map : forall (preVals suffix : List Nat)
      (bs : List Std.U8),
      bs.map (fun b : Std.U8 => b.val) = preVals ++ suffix ->
      exists prefixBytes suffixBytes,
        bs = prefixBytes ++ suffixBytes /\
        prefixBytes.map (fun b : Std.U8 => b.val) = preVals /\
        suffixBytes.map (fun b : Std.U8 => b.val) = suffix := by
    intro preVals
    induction preVals with
    | nil =>
      intro suffix bs h
      exact ⟨[], bs, by simp, rfl, by simpa using h⟩
    | cons value preVals ih =>
      intro suffix bs h
      cases bs with
      | nil => simp at h
      | cons b bs =>
        simp only [List.map_cons, List.cons_append, List.cons.injEq] at h
        obtain ⟨prefixBytes, suffixBytes, hsplit, hp, hs⟩ :=
          ih suffix bs h.2
        exact ⟨b :: prefixBytes, suffixBytes, by simp [hsplit],
          by simp [h.1, hp], hs⟩
  have fold_map : forall (bs : List Std.U8) (a : Nat),
      bs.foldl digitStep a =
        (bs.map (fun b : Std.U8 => b.val - 48)).foldl natStep a := by
    intro bs a
    induction bs generalizing a with
    | nil => rfl
    | cons b bs ih =>
      simp only [List.foldl_cons, List.map_cons]
      exact ih _
  have guarded_fold_map : forall (bs : List Std.U8) (a : Nat),
      bs.foldl (fun a b => if a < 65536 then
          10 * a + (b.val - 48) else a) a =
        (bs.map (fun b : Std.U8 => b.val - 48)).foldl
          (fun a digit => if a < 65536 then 10 * a + digit else a) a := by
    intro bs a
    induction bs generalizing a with
    | nil => rfl
    | cons b bs ih =>
      simp only [List.foldl_cons, List.map_cons]
      exact ih _
  have signed_if_eq_match : forall (sign : Option Bool) (n : Int),
      (if sign = some true then -n else n) =
        match sign with
        | some true => -n
        | _ => n := by
    intro sign n
    cases sign with
    | none => rfl
    | some negative => cases negative <;> rfl
  have fold_upper : forall (bs : List Std.U8) (a : Nat),
      (forall b, List.Mem b bs -> 48 <= b.val /\ b.val <= 57) ->
      bs.foldl digitStep a < (a + 1) * 10 ^ bs.length := by
    intro bs
    induction bs with
    | nil => intro a h; simp
    | cons b bs ih =>
      intro a h
      have hb := h b List.mem_cons_self
      have hbs : forall c, List.Mem c bs -> 48 <= c.val /\ c.val <= 57 := by
        intro c hc
        exact h c (List.mem_cons_of_mem b hc)
      simp only [List.foldl_cons, List.length_cons, Nat.pow_succ]
      have hrec := ih (digitStep a b) hbs
      have hcoeff : digitStep a b + 1 <= 10 * (a + 1) := by
        simp only [digitStep]
        omega
      have hmul := Nat.mul_le_mul_right (10 ^ bs.length) hcoeff
      exact hrec.trans_le (by
        simpa [Nat.mul_assoc, Nat.mul_comm, Nat.mul_left_comm] using hmul)
  have fold_lower : forall (bs : List Std.U8) (a : Nat),
      a * 10 ^ bs.length <= bs.foldl digitStep a := by
    intro bs
    induction bs with
    | nil => intro a; simp
    | cons b bs ih =>
      intro a
      simp only [List.foldl_cons, List.length_cons, Nat.pow_succ]
      calc
        a * (10 ^ bs.length * 10) = (10 * a) * 10 ^ bs.length := by ring
        _ <= digitStep a b * 10 ^ bs.length := by
          apply Nat.mul_le_mul_right
          simp [digitStep]
        _ <= bs.foldl digitStep (digitStep a b) := ih _
  have fold_ge_start : forall (bs : List Std.U8) (a : Nat),
      a <= bs.foldl digitStep a := by
    intro bs
    induction bs with
    | nil => intro a; rfl
    | cons b bs ih =>
      intro a
      apply le_trans (b := digitStep a b)
      · simp [digitStep]
        omega
      · exact ih _
  have split_zeros : forall bs : List Std.U8,
      (forall b, List.Mem b bs -> 48 <= b.val /\ b.val <= 57) ->
      exists zeros tail,
        bs = zeros ++ tail /\
        (forall b, List.Mem b zeros -> b = 48#u8) /\
        (tail = [] \/ exists b rest, tail = b :: rest /\ b != 48#u8) := by
    intro bs
    induction bs with
    | nil =>
      intro h
      exact ⟨[], [], rfl, (by intro b hb; cases hb), Or.inl rfl⟩
    | cons b bs ih =>
      intro h
      by_cases hb : b = 48#u8
      · obtain ⟨zeros, tail, hsplit, hzeros, htail⟩ := ih (by
          intro c hc
          exact h c (List.mem_cons_of_mem b hc))
        refine ⟨b :: zeros, tail, by simp [hsplit], ?_, htail⟩
        intro c hc
        rcases List.mem_cons.mp hc with rfl | hc
        · exact hb
        · exact hzeros c hc
      · exact ⟨[], b :: bs, rfl, (by intro c hc; cases hc), Or.inr ⟨b, bs, rfl, by
          simpa only [bne_iff_ne] using hb⟩⟩
  have zero_fold : forall zeros : List Std.U8,
      (forall b, List.Mem b zeros -> b = 48#u8) ->
      zeros.foldl digitStep 0 = 0 := by
    intro zeros hzeros
    induction zeros with
    | nil => rfl
    | cons b bs ih =>
      have hb := hzeros b List.mem_cons_self
      have hbs : forall c, List.Mem c bs -> c = 48#u8 := by
        intro c hc
        exact hzeros c (List.mem_cons_of_mem b hc)
      simp [hb, digitStep, ih hbs]
  have count_zeros : forall zeros : List Std.U8,
      (forall b, List.Mem b zeros -> b = 48#u8) ->
      zeros.count 48#u8 = zeros.length := by
    intro zeros
    induction zeros with
    | nil => intro h; rfl
    | cons b bs ih =>
      intro h
      have hb := h b List.mem_cons_self
      have hbs : forall c, List.Mem c bs -> c = 48#u8 := by
        intro c hc
        exact h c (List.mem_cons_of_mem b hc)
      simp [hb, ih hbs]
  have split_significand_zeros : forall
      (integer fraction tail : List Std.U8),
      (forall b, List.Mem b integer -> 48 <= b.val /\ b.val <= 57) ->
      (forall b, List.Mem b fraction -> 48 <= b.val /\ b.val <= 57) ->
      (tail = [] \/ exists b rest, tail = b :: rest /\
        b ≠ 48#u8 /\ b ≠ 46#u8) ->
      exists rawZeros rawTail sigZeros sigTail,
        integer ++ 46#u8 :: (fraction ++ tail) = rawZeros ++ rawTail /\
        (forall b, List.Mem b rawZeros -> b = 48#u8 \/ b = 46#u8) /\
        (rawTail = [] \/ exists b rest, rawTail = b :: rest /\
          b ≠ 48#u8 /\ b ≠ 46#u8) /\
        integer ++ fraction = sigZeros ++ sigTail /\
        (forall b, List.Mem b sigZeros -> b = 48#u8) /\
        (sigTail = [] \/ exists b rest, sigTail = b :: rest /\
          b ≠ 48#u8) /\
        rawZeros.count 48#u8 = sigZeros.length := by
    intro integer fraction tail hinteger hfraction htail
    obtain ⟨intZeros, intSig, hintSplit, hintZeros, hintSig⟩ :=
      split_zeros integer hinteger
    rcases hintSig with hintNil | ⟨b, intRest, hintSigEq, hb⟩
    · obtain ⟨fracZeros, fracSig, hfracSplit, hfracZeros, hfracSig⟩ :=
      split_zeros fraction hfraction
      have hfracSigNe : fracSig = [] \/ exists c rest,
          fracSig = c :: rest /\ c ≠ 48#u8 := by
        rcases hfracSig with hnil | ⟨c, rest, heq, hc⟩
        · exact Or.inl hnil
        · exact Or.inr ⟨c, rest, heq,
            by simpa only [bne_iff_ne] using hc⟩
      refine ⟨intZeros ++ 46#u8 :: fracZeros, fracSig ++ tail,
        intZeros ++ fracZeros, fracSig, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩
      · rw [hintSplit, hintNil, hfracSplit]
        simp [List.append_assoc]
      · intro c hc
        rcases List.mem_append.mp hc with hc | hc
        · exact Or.inl (hintZeros c hc)
        · rcases List.mem_cons.mp hc with rfl | hc
          · exact Or.inr rfl
          · exact Or.inl (hfracZeros c hc)
      · rcases hfracSigNe with hnil | ⟨c, rest, hfracSigEq, hc⟩
        · rw [hnil]
          simpa using htail
        · right
          refine ⟨c, rest ++ tail, by simp [hfracSigEq], ?_, ?_⟩
          · exact hc
          · have hcdigit := hfraction c (by
              rw [hfracSplit, hfracSigEq]
              exact List.mem_append_right fracZeros List.mem_cons_self)
            intro hpoint
            subst c
            norm_num at hcdigit
      · rw [hintSplit, hintNil, hfracSplit]
        simp [List.append_assoc]
      · intro c hc
        rcases List.mem_append.mp hc with hc | hc
        · exact hintZeros c hc
        · exact hfracZeros c hc
      · exact hfracSigNe
      · rw [List.count_append, List.count_cons, count_zeros intZeros hintZeros,
          count_zeros fracZeros hfracZeros]
        norm_num
    · refine ⟨intZeros, intSig ++ 46#u8 :: (fraction ++ tail),
        intZeros, intSig ++ fraction, ?_, ?_, ?_, ?_, hintZeros, ?_, ?_⟩
      · rw [hintSplit]
        simp [List.append_assoc]
      · intro c hc
        exact Or.inl (hintZeros c hc)
      · right
        refine ⟨b, intRest ++ 46#u8 :: (fraction ++ tail),
          by simp [hintSigEq], ?_, ?_⟩
        · simpa only [bne_iff_ne] using hb
        · have hbdigit := hinteger b (by
            rw [hintSplit, hintSigEq]
            exact List.mem_append_right intZeros List.mem_cons_self)
          intro hpoint
          subst b
          norm_num at hbdigit
      · rw [hintSplit]
        simp [List.append_assoc]
      · exact Or.inr ⟨b, intRest ++ fraction, by simp [hintSigEq],
          by simpa only [bne_iff_ne] using hb⟩
      · exact count_zeros intZeros hintZeros
  have finish_value : forall (record : num.imp.dec2flt.decimal.Decimal)
      (bytes : List Std.U8) (digits : List Nat) (e : Int),
      bytes.map (fun b : Std.U8 => b.val - 48) = digits ->
      (forall digit, List.Mem digit digits -> digit < 10) ->
      ((record.many_digits = false /\
          record.mantissa.val = bytes.foldl digitStep 0 /\
          record.exponent.val = e) \/
        (record.many_digits = true /\ exists consumed remaining,
          bytes = consumed ++ remaining /\
          record.mantissa.val = consumed.foldl digitStep 0 /\
          record.exponent.val = e + remaining.length)) ->
      (record.many_digits = false /\
          DecimalGoalVocabularyDefault.decimalMagnitude record =
            ((digits.foldl natStep 0 : Nat) : Real) * (10 : Real) ^ e) \/
        (record.many_digits = true /\
          DecimalGoalVocabularyDefault.decimalMagnitude record <=
            ((digits.foldl natStep 0 : Nat) : Real) * (10 : Real) ^ e /\
          ((digits.foldl natStep 0 : Nat) : Real) * (10 : Real) ^ e <
            ((record.mantissa.val + 1 : Nat) : Real) *
              (10 : Real) ^ record.exponent.val) := by
    intro record bytes digits e hmap hdigits hrepresentation
    rcases hrepresentation with ⟨hmany, hmantissa, hexponent⟩ |
        ⟨hmany, consumed, remaining, hpartition, hmantissa, hexponent⟩
    · left
      refine ⟨hmany, ?_⟩
      simp only [DecimalGoalVocabularyDefault]
      rw [hmantissa, hexponent, fold_map, hmap]
    · right
      let headDigits := consumed.map (fun b : Std.U8 => b.val - 48)
      let suffixDigits := remaining.map (fun b : Std.U8 => b.val - 48)
      have hsuffixDigits : forall digit, List.Mem digit suffixDigits ->
          digit < 10 := by
        intro digit hdigit
        apply hdigits digit
        rw [← hmap, hpartition, List.map_append]
        exact List.mem_append_right headDigits hdigit
      have hrenderPartition : headDigits ++ suffixDigits = digits := by
        rw [← List.map_append, ← hpartition]
        exact hmap
      obtain ⟨hintervalLower, hintervalUpper⟩ :=
        NumberHelperDecimalPrefixInterval headDigits suffixDigits
          hsuffixDigits e
      rw [hrenderPartition] at hintervalLower hintervalUpper
      have hconsumedFold := fold_map consumed 0
      dsimp [headDigits, suffixDigits] at hintervalLower hintervalUpper
      rw [← hconsumedFold] at hintervalLower hintervalUpper
      refine ⟨hmany, ?_, ?_⟩
      · simpa [DecimalGoalVocabularyDefault, natStep, hmantissa, hexponent,
          hrenderPartition] using hintervalLower
      · simpa [DecimalGoalVocabularyDefault, natStep, hmantissa, hexponent,
          hrenderPartition] using hintervalUpper
  cases frac with
  | none =>
    simp at hfrac hsome
    cases expo with
    | none =>
      simp at hbytes hexpo
      have hsdigits := byte_digits s.val ints hbytes hints
      obtain ⟨mantissa, rest, hscan, hrest⟩ :=
        NumberHelperDigitScanSourceLength s 0#u64 s.val [] (by simp)
          hsdigits (by simp) hlen
      let empty : Slice Std.U8 := ⟨[], by simp⟩
      have hrestEq : rest = empty := (Slice.eq_iff _ _).2 (by
        simpa [empty] using hrest)
      obtain ⟨nDigits, hoff, hnDigitsVal⟩ :=
        NumberHelperOffsetSourceLength s rest hlen (by simp [hrest])
      have hnDigitsEq : nDigits.val = s.val.length := by
        simpa [hrest] using hnDigitsVal
      have hsplit : core.slice.Slice.split_first rest = ok none := by
        rw [hrestEq]
        simp [core.slice.Slice.split_first, ModelSliceSplitFirst, empty]
      have hnotempty : Not (s.val = []) := by simpa using hne
      have hsLenEq : s.val.length = ints.length := by
        have := congrArg List.length hbytes
        simpa using this
      have hnpos : 0 < nDigits.val := by
        rw [hnDigitsEq, hsLenEq]
        exact_mod_cast List.length_pos_of_ne_nil hsome
      have haddzero : (nDigits + 0#isize) = ok nDigits := by
        have hb := IScalar.hBounds nDigits
        obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
          (IScalar.add_spec (x := nDigits) (y := 0#isize) (by
            simp [IScalar.min, IScalarTy.numBits,
              Dec2Flt.configured_x86_64_numBits]
            omega) (by
            simp [IScalar.max, IScalarTy.numBits,
              Dec2Flt.configured_x86_64_numBits] at hb ⊢
            omega))
        rw [hz]
        congr 2
        apply IScalar.eq_of_val_eq
        simpa using hzval
      have hcastlen : lift (IScalar.hcast .Usize nDigits) =
          ok (Slice.len s) := by
        have hbound : 0 <= nDigits.val /\
            nDigits.val <= UScalar.max .Usize := by
          rw [hnDigitsEq]
          simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
          omega
        obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
          (IScalar.hcast_inBounds_spec .Usize nDigits hbound)
        rw [hz]
        congr 2
        apply UScalar.eq_of_val_eq
        rw [hnDigitsEq] at hzval
        simpa [Slice.len_val] using hzval
      have hdigitMap : s.val.map (fun b : Std.U8 => b.val - 48) = ints :=
        unrender_digits s.val ints hbytes hints
      have hfoldEq : s.val.foldl digitStep 0 = ints.foldl natStep 0 := by
        rw [fold_map, hdigitMap]
      simp [num.imp.dec2flt.parse.parse_number,
        num.imp.dec2flt.parse.parse_partial_number, hscan, hoff, hsplit,
        hnotempty, haddzero, hnpos.ne', hcastlen] at hparse
      by_cases hsmall : nDigits.val <= 19
      · simp [hsmall] at hparse
        subst d
        left
        refine ⟨rfl, ?_⟩
        have hfoldLt : s.val.foldl digitStep 0 < 10 ^ s.val.length := by
          simpa using fold_upper s.val 0 hsdigits
        have hfoldBound : s.val.foldl digitStep 0 <= U64.max := by
          have hlen19 : s.val.length <= 19 := by omega
          have hpow : 10 ^ s.val.length <= 10 ^ 19 := by
            exact Nat.pow_le_pow_right (by norm_num) hlen19
          have : s.val.foldl digitStep 0 < 10 ^ 19 := hfoldLt.trans_le hpow
          rw [U64.max_eq]
          norm_num
          omega
        obtain ⟨exactMantissa, exactRest, hexactScan, hexactRest,
            hexactValue⟩ := NumberHelperDigitScanExact s 0#u64 s.val []
          (by simp) hsdigits (by simp) hlen (by simpa [digitStep] using hfoldBound)
        have hmantissa : mantissa.val = s.val.foldl digitStep 0 := by
          rw [hscan] at hexactScan
          simp at hexactScan
          rcases hexactScan with ⟨rfl, rfl⟩
          simpa [digitStep] using hexactValue
        simp only [num.imp.dec2flt.decimal.Decimal.many_digits,
          num.imp.dec2flt.decimal.Decimal.mantissa,
          num.imp.dec2flt.decimal.Decimal.exponent]
        norm_num
        rw [hmantissa, hfoldEq]
      · have hlarge : 19 < nDigits.val := by omega
        simp [hsmall] at hparse
        have hsubBounds : IScalar.min .Isize <= nDigits.val - 19 /\
            nDigits.val - 19 <= IScalar.max .Isize := by
          have hb := IScalar.hBounds nDigits
          simp [IScalar.min, IScalar.max, IScalarTy.numBits,
            Dec2Flt.configured_x86_64_numBits] at hb ⊢
          omega
        obtain ⟨nMore, hnMore, hnMoreVal⟩ := Aeneas.Std.WP.spec_imp_exists
          (IScalar.sub_spec (x := nDigits) (y := 19#isize)
            (by norm_num; omega)
            (by norm_num; omega))
        norm_num at hnMoreVal
        rw [hnMore] at hparse
        simp at hparse
        obtain ⟨zeros, tail, hsZeros, hzeros, htail⟩ :=
          split_zeros s.val hsdigits
        have hcount : zeros.count 48#u8 = zeros.length :=
          count_zeros zeros hzeros
        have htailSharp : tail = [] \/ exists b rest,
            tail = b :: rest /\ b ≠ 48#u8 /\ b ≠ 46#u8 := by
          rcases htail with hnil | ⟨b, restTail, htailEq, hb⟩
          · exact Or.inl hnil
          · right
            refine ⟨b, restTail, htailEq, ?_, ?_⟩
            · simpa only [bne_iff_ne] using hb
            · have hbdigit := hsdigits b (by
                rw [hsZeros]
                exact List.mem_append_right zeros (by simp [htailEq]))
              intro h46
              subst b
              norm_num at hbdigit
        have hnMoreNonneg : 0 <= nMore.val := by
          rw [hnMoreVal]
          omega
        have hnMoreLe : nMore.val <= s.val.length := by
          rw [hnMoreVal]
          omega
        have hadjustLower : IScalar.min .Isize <=
            nMore.val - (zeros.count 48#u8 : Int) := by
          rw [hnMoreVal, hcount]
          have hzerosLen : zeros.length <= s.val.length := by
            rw [hsZeros]
            simp
          simp [IScalar.min, IScalarTy.numBits,
            Dec2Flt.configured_x86_64_numBits]
          omega
        obtain ⟨adjusted, hadjust, hadjustVal⟩ :=
          NumberHelperAdjustManyExact s nMore zeros tail hsZeros (by
            intro b hb
            exact Or.inl (hzeros b hb)) htailSharp hlen hnMoreNonneg
              hnMoreLe hadjustLower
        rw [hadjust] at hparse
        by_cases hpositive : 0 < adjusted.val
        · simp [hpositive] at hparse
          cases hmany : num.imp.dec2flt.parse.parse_many_digits s rest 0#i64 with
          | fail err => simp [hmany] at hparse
          | div => simp [hmany] at hparse
          | ok result =>
            rcases result with ⟨manyMantissa, manyExponent⟩
            simp [hmany] at hparse
            have htailLen : 19 < tail.length := by
              rw [hadjustVal, hnMoreVal, hnDigitsEq, hcount] at hpositive
              rw [hsZeros] at hpositive
              simp only [List.length_append] at hpositive
              omega
            have htailCons : exists first tailRest,
                tail = first :: tailRest /\
                first ≠ 48#u8 /\ first ≠ 46#u8 := by
              rcases htailSharp with hnil | hcons
              · rw [hnil] at htailLen
                simp at htailLen
              · exact hcons
            rcases htailCons with
              ⟨first, tailRest, htailEq, hfirstNe, hfirstPoint⟩
            have hfirstDigit := hsdigits first (by
              rw [hsZeros, htailEq]
              exact List.mem_append_right zeros List.mem_cons_self)
            have hthreshold : 1000000000000000000 <=
                s.val.foldl (fun a b => 10 * a + (b.val - 48)) 0 := by
              have hzero := zero_fold zeros hzeros
              have hlower := fold_lower tailRest (first.val - 48)
              rw [hsZeros, List.foldl_append, hzero, htailEq,
                List.foldl_cons] 
              change 1000000000000000000 <=
                tailRest.foldl digitStep (digitStep 0 first)
              have hfirstPos : 1 <= first.val - 48 := by
                have hneVal : first.val ≠ 48 := by
                  intro h
                  apply hfirstNe
                  apply UScalar.eq_of_val_eq
                  simpa using h
                omega
              have hpowLower : 1000000000000000000 <=
                  10 ^ tailRest.length := by
                have hlenRest : 18 <= tailRest.length := by
                  rw [htailEq] at htailLen
                  simp only [List.length_cons] at htailLen
                  omega
                have hp := Nat.pow_le_pow_right (by norm_num : 0 < 10) hlenRest
                norm_num at hp ⊢
                exact hp
              have hstep : 10 ^ tailRest.length <=
                  (first.val - 48) * 10 ^ tailRest.length := by
                nlinarith
              exact hpowLower.trans (hstep.trans (by
                simpa [digitStep] using hlower))
            obtain ⟨consumed, remaining, hpartition, hmanyMantissa,
                hmanyExponent⟩ := NumberHelperIntegralManyExact s rest
              0#i64 manyExponent manyMantissa s.val [] (by simp) hrest
                hsdigits (by simp) hlen hthreshold hmany
            let headDigits := consumed.map (fun b : Std.U8 => b.val - 48)
            let suffixDigits := remaining.map (fun b : Std.U8 => b.val - 48)
            have hsuffixDigits : forall digit, List.Mem digit suffixDigits ->
                digit < 10 := by
              intro digit hdigit
              obtain ⟨b, hb, rfl⟩ := List.mem_map.mp hdigit
              have hbAll : List.Mem b s.val := by
                rw [hpartition]
                exact List.mem_append_right consumed hb
              have hbDigit := hsdigits b hbAll
              omega
            have hrenderPartition : headDigits ++ suffixDigits = ints := by
              rw [← List.map_append, ← hpartition]
              exact hdigitMap
            obtain ⟨hintervalLower, hintervalUpper⟩ :=
              NumberHelperDecimalPrefixInterval headDigits suffixDigits
                hsuffixDigits 0
            have hconsumedFold := fold_map consumed 0
            dsimp [headDigits, suffixDigits] at hintervalLower hintervalUpper
            rw [← hconsumedFold] at hintervalLower hintervalUpper
            subst d
            right
            refine ⟨rfl, ?_, ?_⟩
            · simpa [headDigits, suffixDigits, natStep,
                hmanyMantissa, hmanyExponent, hrenderPartition] using
                hintervalLower
            · simpa [headDigits, suffixDigits, natStep,
                hmanyMantissa, hmanyExponent, hrenderPartition] using
                hintervalUpper
        · simp [hpositive] at hparse
          have htailLen : tail.length <= 19 := by
            rw [hadjustVal, hnMoreVal, hnDigitsEq, hcount] at hpositive
            rw [hsZeros] at hpositive
            simp only [List.length_append] at hpositive
            omega
          have htailDigits : forall b, List.Mem b tail ->
              48 <= b.val /\ b.val <= 57 := by
            intro b hb
            apply hsdigits b
            rw [hsZeros]
            exact List.mem_append_right zeros hb
          have hzero := zero_fold zeros hzeros
          have hfoldLtTail : tail.foldl digitStep 0 < 10 ^ tail.length := by
            simpa using fold_upper tail 0 htailDigits
          have hfoldLt : s.val.foldl digitStep 0 < 10 ^ 19 := by
            rw [hsZeros, List.foldl_append, hzero]
            exact hfoldLtTail.trans_le
              (Nat.pow_le_pow_right (by norm_num) htailLen)
          have hfoldBound : s.val.foldl digitStep 0 <= U64.max := by
            rw [U64.max_eq]
            norm_num
            omega
          obtain ⟨exactMantissa, exactRest, hexactScan, hexactRest,
              hexactValue⟩ := NumberHelperDigitScanExact s 0#u64 s.val []
            (by simp) hsdigits (by simp) hlen
              (by simpa [digitStep] using hfoldBound)
          have hmantissa : mantissa.val = s.val.foldl digitStep 0 := by
            rw [hscan] at hexactScan
            simp at hexactScan
            rcases hexactScan with ⟨rfl, rfl⟩
            simpa [digitStep] using hexactValue
          subst d
          left
          refine ⟨rfl, ?_⟩
          norm_num
          rw [hmantissa, hfoldEq]
    | some e =>
      let upper : Bool := e.1
      let expSign : Option Bool := e.2.1
      let expDigits : List Nat := e.2.2
      change expDigits ≠ [] /\
        (forall digit, List.Mem digit expDigits -> digit < 10) at hexpo
      rcases hexpo with ⟨hexpNe, hexpDigits⟩
      simp [upper, expSign, expDigits] at hbytes
      obtain ⟨intBytes, afterInt, hsval, hintMap, hafterMap⟩ :=
        List.map_eq_append_iff.mp hbytes
      obtain ⟨marker, suffixBytes, hafterVal, hmarkerVal, hsuffixMap⟩ :=
        List.map_eq_cons_iff.mp hafterMap
      have hmarker : marker = if upper then 69#u8 else 101#u8 := by
        by_cases hu : upper = true
        · rw [if_pos hu]
          apply UScalar.eq_of_val_eq
          simpa [hu, upper] using hmarkerVal
        · rw [if_neg hu]
          apply UScalar.eq_of_val_eq
          simpa [hu, upper] using hmarkerVal
      subst marker
      have hsdecomp : s.val = intBytes ++
          (if upper then 69#u8 else 101#u8) :: suffixBytes := by
        rw [hsval, hafterVal]
      have hintDigits := byte_digits intBytes ints hintMap hints
      have hintTailProp :
          ((if upper then 69#u8 else 101#u8) :: suffixBytes).length <=
            Usize.max := by
        have hp := s.property
        rw [hsdecomp] at hp
        simp only [List.length_append] at hp ⊢
        omega
      let intTail : Slice Std.U8 :=
        ⟨(if upper then 69#u8 else 101#u8) :: suffixBytes,
          hintTailProp⟩
      have hintTailNotDigit : forall b restBytes,
          intTail.val = b :: restBytes ->
          Not (48 <= b.val /\ b.val <= 57) := by
        intro b restBytes hb
        simp [intTail] at hb
        rcases hb with ⟨rfl, _⟩
        cases upper <;> norm_num
      obtain ⟨mantissa, intRest, hscan, hintRest⟩ :=
        NumberHelperDigitScanSourceLength s 0#u64 intBytes intTail.val
          (by simpa [intTail] using hsdecomp) hintDigits hintTailNotDigit hlen
      have hintRestEq : intRest = intTail :=
        (Slice.eq_iff _ _).2 (by simpa using hintRest)
      subst intRest
      obtain ⟨nDigits, hoffInt, hnDigitsVal⟩ :=
        NumberHelperOffsetSourceLength s intTail hlen (by
          rw [hsdecomp]
          simp [intTail])
      have hnDigitsEq : nDigits.val = intBytes.length := by
        rw [hnDigitsVal, hsdecomp]
        simp [intTail]
      have hsuffixProp : suffixBytes.length <= Usize.max := by
        have hp := intTail.property
        simp [intTail] at hp
        omega
      let suffix : Slice Std.U8 := ⟨suffixBytes, hsuffixProp⟩
      have hsplitMarker : core.slice.Slice.split_first intTail =
          ok (some (if upper then 69#u8 else 101#u8, suffix)) := by
        simp [core.slice.Slice.split_first, ModelSliceSplitFirst,
          intTail, suffix]
      obtain ⟨expBytes, hsuffixDecomp, hexpMap⟩ :=
        NumberHelperSplitExponentSuffix expSign suffixBytes expDigits hsuffixMap
      have hexpByteDigits := byte_digits expBytes expDigits hexpMap hexpDigits
      have hexpDigitMap : expBytes.map (fun b : Std.U8 => b.val - 48) =
          expDigits := unrender_digits expBytes expDigits hexpMap hexpDigits
      have hexpByteNeProp : expBytes ≠ [] := by
        intro hempty
        rw [hempty] at hexpDigitMap
        simp at hexpDigitMap
        exact hexpNe hexpDigitMap
      have hexpByteNe : expBytes != [] := by
        simpa only [bne_iff_ne] using hexpByteNeProp
      have hsignByteMap :
          (match expSign with
          | none => ([] : List Std.U8)
          | some negative => [if negative then 45#u8 else 43#u8]).map
              (fun b : Std.U8 => b.val) =
            (match expSign with
            | none => []
            | some negative => [if negative then 45 else 43]) := by
        cases expSign with
        | none => rfl
        | some negative => cases negative <;> rfl
      have hsuffixDecomp' : suffix.val =
          (match expSign with
          | none => []
          | some negative => [if negative then 45#u8 else 43#u8]) ++
            expBytes := by
        change suffixBytes = _
        apply u8_list_eq_of_val_map
        dsimp [expSign, expDigits] at hsignByteMap ⊢
        rw [hsuffixMap, List.map_append, hsignByteMap, hexpMap]
        rfl
      obtain ⟨parsedExp, scientificRest, hscientific, hscientificRest,
          hparsedExp⟩ := NumberHelperScientificExact suffix expSign expBytes
        hexpByteNe hexpByteDigits hsuffixDecomp'
      have hparsedExpValue : parsedExp.val =
          if expSign = some true then
            -((expDigits.foldl
              (fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int)
          else ((expDigits.foldl
            (fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int) := by
        rw [hparsedExp, guarded_fold_map, hexpDigitMap]
      have hparsedExpTarget : parsedExp.val =
          (match expSign with
          | some true => -((expDigits.foldl
              (fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int)
          | _ => ((expDigits.foldl
              (fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int)) := by
        rw [hparsedExpValue]
        exact signed_if_eq_match expSign _
      have hnotempty : Not (s.val = []) := by simpa using hne
      have hnpos : 0 < nDigits.val := by
        rw [hnDigitsEq]
        have hintLen : intBytes.length = ints.length := by
          have := congrArg List.length hintMap
          simpa using this
        rw [hintLen]
        exact_mod_cast List.length_pos_of_ne_nil hsome
      have haddzero : (nDigits + 0#isize) = ok nDigits := by
        have hb := IScalar.hBounds nDigits
        obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
          (IScalar.add_spec (x := nDigits) (y := 0#isize) (by
            simp [IScalar.min, IScalarTy.numBits,
              Dec2Flt.configured_x86_64_numBits]
            omega) (by
            simp [IScalar.max, IScalarTy.numBits,
              Dec2Flt.configured_x86_64_numBits] at hb ⊢
            omega))
        rw [hz]
        congr 2
        apply IScalar.eq_of_val_eq
        simpa using hzval
      have haddExp : (0#i64 + parsedExp) = ok parsedExp := by
        have hb : IScalar.min .I64 <= (0#i64).val + parsedExp.val /\
            (0#i64).val + parsedExp.val <= IScalar.max .I64 := by
          have hp := IScalar.hBounds parsedExp
          rw [IScalar.min_IScalarTy_I64_eq, I64.min_eq,
            IScalar.max_IScalarTy_I64_eq, I64.max_eq]
          norm_num at hp ⊢
          omega
        obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
          (IScalar.add_spec hb.1 hb.2)
        rw [hz]
        congr 2
        apply IScalar.eq_of_val_eq
        norm_num at hzval
        exact hzval
      obtain ⟨fullOffset, hoffFull, hfullOffsetVal⟩ :=
        NumberHelperOffsetSourceLength s scientificRest hlen (by
          simp [hscientificRest])
      have hfullCast : lift (IScalar.hcast .Usize fullOffset) =
          ok (Slice.len s) := by
        have hbound : 0 <= fullOffset.val /\
            fullOffset.val <= UScalar.max .Usize := by
          rw [hfullOffsetVal, hscientificRest]
          simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
          omega
        obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
          (IScalar.hcast_inBounds_spec .Usize fullOffset hbound)
        rw [hz]
        congr 2
        apply UScalar.eq_of_val_eq
        rw [hfullOffsetVal, hscientificRest] at hzval
        simpa [Slice.len_val] using hzval
      simp [num.imp.dec2flt.parse.parse_number,
        num.imp.dec2flt.parse.parse_partial_number, hnotempty, hscan,
        hoffInt, haddzero, hnpos.ne', hsplitMarker, hscientific,
        core.option.Option.Insts.CoreOpsTry_traitTry.branch,
        ModelOptionBranch, haddExp, hoffFull, hfullCast] at hparse
      cases hupper : upper <;>
        simp [hupper, hsplitMarker, hscientific,
          UScalar.ofNatCore,
          core.option.Option.Insts.CoreOpsTry_traitTry.branch,
          ModelOptionBranch, ModelOptionFromResidual,
          haddExp, hoffFull, hfullCast] at hparse
      all_goals
        have hdigitMap : intBytes.map (fun b : Std.U8 => b.val - 48) = ints :=
          unrender_digits intBytes ints hintMap hints
        have hfoldEq : intBytes.foldl digitStep 0 =
            ints.foldl natStep 0 := by
          rw [fold_map, hdigitMap]
        by_cases hsmall : nDigits.val <= 19
        · simp [haddzero, hnpos.ne', hsmall] at hparse
          have hfoldLt : intBytes.foldl digitStep 0 <
              10 ^ intBytes.length := by
            simpa using fold_upper intBytes 0 hintDigits
          have hfoldBound : intBytes.foldl digitStep 0 <= U64.max := by
            have hlen19 : intBytes.length <= 19 := by
              omega
            have hpow : 10 ^ intBytes.length <= 10 ^ 19 :=
              Nat.pow_le_pow_right (by norm_num) hlen19
            have hlt : intBytes.foldl digitStep 0 < 10 ^ 19 :=
              hfoldLt.trans_le hpow
            rw [U64.max_eq]
            norm_num
            omega
          obtain ⟨exactMantissa, exactRest, hexactScan, hexactRest,
              hexactValue⟩ := NumberHelperDigitScanExact s 0#u64 intBytes
            intTail.val (by simpa [intTail] using hsdecomp) hintDigits
              hintTailNotDigit hlen (by simpa [digitStep] using hfoldBound)
          have hmantissa : mantissa.val = intBytes.foldl digitStep 0 := by
            rw [hscan] at hexactScan
            simp at hexactScan
            rcases hexactScan with ⟨rfl, rfl⟩
            simpa [digitStep] using hexactValue
          subst d
          left
          refine ⟨rfl, ?_⟩
          norm_num
          rw [hmantissa, hfoldEq, hparsedExpTarget]
          rfl
        · have hlarge : 19 < nDigits.val := by omega
          have hsubBounds : IScalar.min .Isize <= nDigits.val - 19 /\
              nDigits.val - 19 <= IScalar.max .Isize := by
            have hb := IScalar.hBounds nDigits
            simp [IScalar.min, IScalar.max, IScalarTy.numBits,
              Dec2Flt.configured_x86_64_numBits] at hb ⊢
            omega
          obtain ⟨nMore, hnMore, hnMoreVal⟩ := Aeneas.Std.WP.spec_imp_exists
            (IScalar.sub_spec (x := nDigits) (y := 19#isize)
              (by norm_num; omega) (by norm_num; omega))
          norm_num at hnMoreVal
          simp [haddzero, hnpos.ne', hsmall, hnMore] at hparse
          obtain ⟨zeros, sigTail, hintZeros, hzeros, hsigTail⟩ :=
            split_zeros intBytes hintDigits
          let rawTail : List Std.U8 := sigTail ++ intTail.val
          have hsAdjust : s.val = zeros ++ rawTail := by
            rw [hsdecomp, hintZeros]
            simp [rawTail, intTail, List.append_assoc]
          have hrawTailSharp : rawTail = [] \/ exists b rest,
              rawTail = b :: rest /\ b ≠ 48#u8 /\ b ≠ 46#u8 := by
            rcases hsigTail with hnil | ⟨b, restTail, htailEq, hb⟩
            · right
              refine ⟨if upper then 69#u8 else 101#u8, suffixBytes,
                ?_, ?_, ?_⟩
              · simp [rawTail, hnil, intTail]
              · norm_num [hupper, UScalar.ofNatCore]
              · norm_num [hupper, UScalar.ofNatCore]
            · right
              refine ⟨b, restTail ++ intTail.val, ?_, ?_, ?_⟩
              · simp [rawTail, htailEq]
              · simpa only [bne_iff_ne] using hb
              · have hbdigit := hintDigits b (by
                  rw [hintZeros, htailEq]
                  exact List.mem_append_right zeros List.mem_cons_self)
                intro hpoint
                subst b
                norm_num at hbdigit
          have hcount : zeros.count 48#u8 = zeros.length :=
            count_zeros zeros hzeros
          have hnMoreNonneg : 0 <= nMore.val := by
            rw [hnMoreVal]
            omega
          have hnMoreLe : nMore.val <= s.val.length := by
            rw [hnMoreVal, hnDigitsEq, hsdecomp]
            simp only [List.length_append]
            omega
          have hadjustLower : IScalar.min .Isize <=
              nMore.val - (zeros.count 48#u8 : Int) := by
            rw [hnMoreVal, hcount, hnDigitsEq]
            have hzerosLen : zeros.length <= intBytes.length := by
              rw [hintZeros]
              simp
            simp [IScalar.min, IScalarTy.numBits,
              Dec2Flt.configured_x86_64_numBits]
            omega
          obtain ⟨adjusted, hadjust, hadjustVal⟩ :=
            NumberHelperAdjustManyExact s nMore zeros rawTail hsAdjust (by
              intro b hb
              exact Or.inl (hzeros b hb)) hrawTailSharp hlen hnMoreNonneg
                hnMoreLe hadjustLower
          rw [hadjust] at hparse
          by_cases hpositive : 0 < adjusted.val
          · simp [hpositive] at hparse
            cases hmany : num.imp.dec2flt.parse.parse_many_digits s intTail
                parsedExp with
            | fail err => simp [hmany] at hparse
            | div => simp [hmany] at hparse
            | ok result =>
              rcases result with ⟨manyMantissa, manyExponent⟩
              simp [hmany] at hparse
              have hsigTailLen : 19 < sigTail.length := by
                rw [hadjustVal, hnMoreVal, hnDigitsEq, hcount] at hpositive
                rw [hintZeros] at hpositive
                simp only [List.length_append] at hpositive
                omega
              have hsigTailCons : exists first tailRest,
                  sigTail = first :: tailRest /\
                  first ≠ 48#u8 /\ first ≠ 46#u8 := by
                rcases hsigTail with hnil | hcons
                · rw [hnil] at hsigTailLen
                  simp at hsigTailLen
                · rcases hcons with ⟨b, restTail, hbEq, hbNe⟩
                  refine ⟨b, restTail, hbEq, ?_, ?_⟩
                  · simpa only [bne_iff_ne] using hbNe
                  · have hbdigit := hintDigits b (by
                      rw [hintZeros, hbEq]
                      exact List.mem_append_right zeros List.mem_cons_self)
                    intro hpoint
                    subst b
                    norm_num at hbdigit
              rcases hsigTailCons with
                ⟨first, tailRest, htailEq, hfirstNe, hfirstPoint⟩
              have hfirstDigit := hintDigits first (by
                rw [hintZeros, htailEq]
                exact List.mem_append_right zeros List.mem_cons_self)
              have hthreshold : 1000000000000000000 <=
                  intBytes.foldl digitStep 0 := by
                have hzero := zero_fold zeros hzeros
                have hlower := fold_lower tailRest (first.val - 48)
                rw [hintZeros, List.foldl_append, hzero, htailEq,
                  List.foldl_cons]
                change 1000000000000000000 <=
                  tailRest.foldl digitStep (digitStep 0 first)
                have hfirstPos : 1 <= first.val - 48 := by
                  have hneVal : first.val ≠ 48 := by
                    intro h
                    apply hfirstNe
                    apply UScalar.eq_of_val_eq
                    simpa using h
                  omega
                have hpowLower : 1000000000000000000 <=
                    10 ^ tailRest.length := by
                  have hlenRest : 18 <= tailRest.length := by
                    rw [htailEq] at hsigTailLen
                    simp only [List.length_cons] at hsigTailLen
                    omega
                  have hp := Nat.pow_le_pow_right
                    (by norm_num : 0 < 10) hlenRest
                  norm_num at hp ⊢
                  exact hp
                have hstep : 10 ^ tailRest.length <=
                    (first.val - 48) * 10 ^ tailRest.length := by
                  nlinarith
                exact hpowLower.trans (hstep.trans (by
                  simpa [digitStep] using hlower))
              obtain ⟨consumed, remaining, hpartition, hmanyMantissa,
                  hmanyExponent⟩ := NumberHelperIntegralManyExact s intTail
                parsedExp manyExponent manyMantissa intBytes intTail.val
                  (by simpa [intTail] using hsdecomp) rfl hintDigits
                  hintTailNotDigit hlen hthreshold hmany
              subst d
              have hresult := finish_value
                (num.imp.dec2flt.decimal.Decimal.mk manyExponent
                  manyMantissa false true)
                intBytes ints parsedExp.val hdigitMap hints
                (Or.inr ⟨rfl, consumed, remaining, hpartition,
                  hmanyMantissa, hmanyExponent⟩)
              simpa [DecimalGoalVocabularyDefault, natStep, hparsedExpTarget,
                expSign, expDigits] using hresult
          · simp [hpositive] at hparse
            have hsigTailLen : sigTail.length <= 19 := by
              rw [hadjustVal, hnMoreVal, hnDigitsEq, hcount] at hpositive
              rw [hintZeros] at hpositive
              simp only [List.length_append] at hpositive
              omega
            have hsigTailDigits : forall b, List.Mem b sigTail ->
                48 <= b.val /\ b.val <= 57 := by
              intro b hb
              apply hintDigits b
              rw [hintZeros]
              exact List.mem_append_right zeros hb
            have hzero := zero_fold zeros hzeros
            have hfoldLtTail : sigTail.foldl digitStep 0 <
                10 ^ sigTail.length := by
              simpa using fold_upper sigTail 0 hsigTailDigits
            have hfoldLt : intBytes.foldl digitStep 0 < 10 ^ 19 := by
              rw [hintZeros, List.foldl_append, hzero]
              exact hfoldLtTail.trans_le
                (Nat.pow_le_pow_right (by norm_num) hsigTailLen)
            have hfoldBound : intBytes.foldl digitStep 0 <= U64.max := by
              rw [U64.max_eq]
              norm_num
              omega
            obtain ⟨exactMantissa, exactRest, hexactScan, hexactRest,
                hexactValue⟩ := NumberHelperDigitScanExact s 0#u64 intBytes
              intTail.val (by simpa [intTail] using hsdecomp) hintDigits
                hintTailNotDigit hlen
                (by simpa [digitStep] using hfoldBound)
            have hmantissa : mantissa.val = intBytes.foldl digitStep 0 := by
              rw [hscan] at hexactScan
              simp at hexactScan
              rcases hexactScan with ⟨rfl, rfl⟩
              simpa [digitStep] using hexactValue
            subst d
            left
            refine ⟨rfl, ?_⟩
            norm_num
            rw [hmantissa, hfoldEq, hparsedExpTarget]
            rfl
  | some fracs =>
    simp at hfrac hsome
    cases expo with
    | none =>
      simp at hbytes hexpo
      obtain ⟨intBytes, afterInt, hsval, hintMap, hafterMap⟩ :=
        List.map_eq_append_iff.mp hbytes
      obtain ⟨point, fracBytes, hafterVal, hpointVal, hfracMap⟩ :=
        List.map_eq_cons_iff.mp hafterMap
      have hpoint : point = 46#u8 := by
        apply UScalar.eq_of_val_eq
        simpa using hpointVal
      subst point
      have hsdecomp : s.val = intBytes ++ 46#u8 :: fracBytes := by
        rw [hsval, hafterVal]
      have hintDigits := byte_digits intBytes ints hintMap hints
      have hfracDigits := byte_digits fracBytes fracs hfracMap hfrac
      have hintTailProp : (46#u8 :: fracBytes).length <= Usize.max := by
        have hp := s.property
        rw [hsdecomp] at hp
        simp only [List.length_append] at hp
        omega
      let intTail : Slice Std.U8 := ⟨46#u8 :: fracBytes, hintTailProp⟩
      have hintTailNotDigit : forall b rest, intTail.val = b :: rest ->
          Not (48 <= b.val /\ b.val <= 57) := by
        intro b rest hb
        simp [intTail] at hb
        rcases hb with ⟨rfl, _⟩
        norm_num
      obtain ⟨mantissa, intRest, hscanInt, hintRest⟩ :=
        NumberHelperDigitScanSourceLength s 0#u64 intBytes intTail.val
          (by simpa [intTail] using hsdecomp) hintDigits
            hintTailNotDigit hlen
      have hintRestEq : intRest = intTail :=
        (Slice.eq_iff _ _).2 (by simpa using hintRest)
      subst intRest
      obtain ⟨nDigits, hoffInt, hnDigitsVal⟩ :=
        NumberHelperOffsetSourceLength s intTail hlen (by
          rw [hsdecomp]
          simp [intTail])
      have hnDigitsEq : nDigits.val = intBytes.length := by
        rw [hnDigitsVal, hsdecomp]
        simp [intTail]
      have hfracProp : fracBytes.length <= Usize.max := by
        have hp := intTail.property
        simp [intTail] at hp ⊢
        omega
      let fracSlice : Slice Std.U8 := ⟨fracBytes, hfracProp⟩
      have hsplitPoint : core.slice.Slice.split_first intTail =
          ok (some (46#u8, fracSlice)) := by
        simp [core.slice.Slice.split_first, ModelSliceSplitFirst,
          intTail, fracSlice]
      obtain ⟨mantissa1, fracRest, hscanFrac, hfracRest⟩ :=
        NumberHelperDigitScanSourceLength fracSlice mantissa fracBytes []
          (by simp [fracSlice]) hfracDigits (by simp) (by
            simp [fracSlice]
            rw [hsdecomp] at hlen
            simp only [List.length_append, List.length_cons] at hlen
            omega)
      let empty : Slice Std.U8 := ⟨[], by simp⟩
      have hfracRestEq : fracRest = empty :=
        (Slice.eq_iff _ _).2 (by simpa [empty] using hfracRest)
      subst fracRest
      obtain ⟨nAfter, hoffFrac, hnAfterVal⟩ :=
        NumberHelperOffsetSourceLength fracSlice empty (by
          simp [fracSlice]
          rw [hsdecomp] at hlen
          simp only [List.length_append, List.length_cons] at hlen
          omega) (by simp [empty])
      have hnAfterEq : nAfter.val = fracBytes.length := by
        rw [hnAfterVal]
        simp [fracSlice, empty]
      have hnAfterNotMin : nAfter.val ≠ IScalar.min .Isize := by
        rw [hnAfterEq, IScalar.min]
        simp [IScalarTy.numBits, Dec2Flt.configured_x86_64_numBits]
      obtain ⟨negAfter, hnegAfter, hnegAfterVal⟩ :=
        Aeneas.Std.WP.spec_imp_exists (HNeg.hNeg.step nAfter hnAfterNotMin)
      have hnegCastBounds : IScalar.min .I64 <= negAfter.val /\
          negAfter.val <= IScalar.max .I64 := by
        have hp := hlen
        rw [hsdecomp] at hp
        simp only [List.length_append, List.length_cons] at hp
        rw [hnegAfterVal, hnAfterEq,
          IScalar.min_IScalarTy_I64_eq, I64.min_eq,
          IScalar.max_IScalarTy_I64_eq, I64.max_eq]
        constructor <;> omega
      obtain ⟨fracExponent, hfracExponent, hfracExponentVal⟩ :=
        Aeneas.Std.WP.spec_imp_exists
          (IScalar.cast_inBounds_spec .I64 negAfter hnegCastBounds)
      have hfracExponentEq : fracExponent.val = -(fracBytes.length : Int) := by
        rw [hfracExponentVal, hnegAfterVal, hnAfterEq]
      have htotalBounds : IScalar.min .Isize <= nDigits.val + nAfter.val /\
          nDigits.val + nAfter.val <= IScalar.max .Isize := by
        rw [hnDigitsEq, hnAfterEq]
        simp [IScalar.min, IScalar.max, IScalarTy.numBits,
          Dec2Flt.configured_x86_64_numBits]
        rw [hsdecomp] at hlen
        simp only [List.length_append, List.length_cons] at hlen
        constructor <;> omega
      obtain ⟨totalDigits, htotal, htotalVal⟩ :=
        Aeneas.Std.WP.spec_imp_exists
          (IScalar.add_spec htotalBounds.1 htotalBounds.2)
      have hintLen : intBytes.length = ints.length := by
        have hp := congrArg List.length hintMap
        simpa using hp
      have hfracLen : fracBytes.length = fracs.length := by
        have hp := congrArg List.length hfracMap
        simpa using hp
      have htotalPos : 0 < totalDigits.val := by
        rw [htotalVal, hnDigitsEq, hnAfterEq]
        rcases hsome with hneInt | hneFrac
        · have hp := List.length_pos_of_ne_nil hneInt
          omega
        · have hp := List.length_pos_of_ne_nil hneFrac
          omega
      obtain ⟨fullOffset, hoffFull, hfullOffsetVal⟩ :=
        NumberHelperOffsetSourceLength s empty hlen (by simp [empty])
      have hfullCast : lift (IScalar.hcast .Usize fullOffset) =
          ok (Slice.len s) := by
        have hbound : 0 <= fullOffset.val /\
            fullOffset.val <= UScalar.max .Usize := by
          rw [hfullOffsetVal]
          simp [empty, UScalar.max, Dec2Flt.configured_x86_64_numBits]
          omega
        obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
          (IScalar.hcast_inBounds_spec .Usize fullOffset hbound)
        rw [hz]
        congr 2
        apply UScalar.eq_of_val_eq
        rw [hfullOffsetVal] at hzval
        simpa [empty, Slice.len_val] using hzval
      have hnotempty : Not (s.val = []) := by simpa using hne
      have hsplitEmpty : core.slice.Slice.split_first empty = ok none := by
        simp [core.slice.Slice.split_first, ModelSliceSplitFirst, empty]
      unfold num.imp.dec2flt.parse.parse_number at hparse
      simp [hnotempty] at hparse
      unfold num.imp.dec2flt.parse.parse_partial_number at hparse
      simp [hnotempty, hscanInt, hoffInt, hsplitPoint, hscanFrac,
        hoffFrac, hnegAfter, hfracExponent] at hparse
      norm_num at hparse
      simp only [UScalar.ofNat, UScalar.ofNatCore] at hparse
      simp [htotal, htotalPos, hsplitEmpty, hoffFull, hfullCast] at hparse
      have hdigitInt : intBytes.map (fun b : Std.U8 => b.val - 48) = ints :=
        unrender_digits intBytes ints hintMap hints
      have hdigitFrac : fracBytes.map (fun b : Std.U8 => b.val - 48) =
          fracs := unrender_digits fracBytes fracs hfracMap hfrac
      have hsigMap : (intBytes ++ fracBytes).map
          (fun b : Std.U8 => b.val - 48) = ints ++ fracs := by
        simp [hdigitInt, hdigitFrac]
      have hsigDigits : forall b, List.Mem b (intBytes ++ fracBytes) ->
          48 <= b.val /\ b.val <= 57 := by
        intro b hb
        rcases List.mem_append.mp hb with hb | hb
        · exact hintDigits b hb
        · exact hfracDigits b hb
      have hsigFoldEq : (intBytes ++ fracBytes).foldl digitStep 0 =
          (ints ++ fracs).foldl natStep 0 := by
        rw [fold_map, hsigMap]
      have hfracExponentTarget : fracExponent.val = -(fracs.length : Int) := by
        rw [hfracExponentEq, hfracLen]
      have hexactScans : (intBytes ++ fracBytes).foldl digitStep 0 <=
          U64.max ->
          mantissa.val = intBytes.foldl digitStep 0 /\
          mantissa1.val = (intBytes ++ fracBytes).foldl digitStep 0 := by
        as_aux_lemma =>
        intro hfullBound
        have hprefixLe : intBytes.foldl digitStep 0 <=
            (intBytes ++ fracBytes).foldl digitStep 0 := by
          rw [List.foldl_append]
          exact fold_ge_start fracBytes _
        have hintBound : intBytes.foldl digitStep 0 <= U64.max :=
          hprefixLe.trans hfullBound
        obtain ⟨exactInt, exactIntRest, hexactInt, hexactIntRest,
            hexactIntValue⟩ := NumberHelperDigitScanExact s 0#u64 intBytes
          intTail.val (by simpa [intTail] using hsdecomp) hintDigits
            hintTailNotDigit hlen (by simpa [digitStep] using hintBound)
        have hmantissa : mantissa.val = intBytes.foldl digitStep 0 := by
          rw [hscanInt] at hexactInt
          simp at hexactInt
          rcases hexactInt with ⟨rfl, rfl⟩
          simpa [digitStep] using hexactIntValue
        have hfracBound : fracBytes.foldl digitStep mantissa.val <=
            U64.max := by
          rw [hmantissa, ← List.foldl_append]
          exact hfullBound
        obtain ⟨exactFrac, exactFracRest, hexactFrac, hexactFracRest,
            hexactFracValue⟩ := NumberHelperDigitScanExact fracSlice mantissa
          fracBytes [] (by simp [fracSlice]) hfracDigits (by simp) (by
            simp [fracSlice]
            rw [hsdecomp] at hlen
            simp only [List.length_append, List.length_cons] at hlen
            omega) (by simpa [digitStep] using hfracBound)
        have hmantissa1 : mantissa1.val =
            (intBytes ++ fracBytes).foldl digitStep 0 := by
          rw [hscanFrac] at hexactFrac
          simp at hexactFrac
          rcases hexactFrac with ⟨rfl, rfl⟩
          rw [List.foldl_append, ← hmantissa]
          simpa [digitStep] using hexactFracValue
        exact ⟨hmantissa, hmantissa1⟩
      by_cases hsmall : totalDigits.val <= 19
      · simp [hsmall] at hparse
        have hsigLen : (intBytes ++ fracBytes).length <= 19 := by
          rw [List.length_append]
          omega
        have hfoldLt : (intBytes ++ fracBytes).foldl digitStep 0 <
            10 ^ (intBytes ++ fracBytes).length := by
          simpa using fold_upper (intBytes ++ fracBytes) 0 hsigDigits
        have hfullBound : (intBytes ++ fracBytes).foldl digitStep 0 <=
            U64.max := by
          have hp := hfoldLt.trans_le
            (Nat.pow_le_pow_right (by norm_num) hsigLen)
          have hpowMax : 10 ^ 19 <= U64.max := by
            norm_num [U64.max_eq]
          exact (Nat.le_of_lt hp).trans hpowMax
        obtain ⟨hmantissa, hmantissa1⟩ := hexactScans hfullBound
        subst d
        left
        refine ⟨rfl, ?_⟩
        norm_num
        rw [hmantissa1, hsigFoldEq, hfracExponentTarget,
          List.foldl_append]
        simp [natStep]
      · have hlarge : 19 < totalDigits.val := by omega
        have hsubBounds : IScalar.min .Isize <= totalDigits.val - 19 /\
            totalDigits.val - 19 <= IScalar.max .Isize := by
          have hb := IScalar.hBounds totalDigits
          simp [IScalar.min, IScalar.max, IScalarTy.numBits,
            Dec2Flt.configured_x86_64_numBits] at hb ⊢
          omega
        obtain ⟨nMore, hnMore, hnMoreVal⟩ := Aeneas.Std.WP.spec_imp_exists
          (IScalar.sub_spec (x := totalDigits) (y := 19#isize)
            (by norm_num; omega) (by norm_num; omega))
        norm_num at hnMoreVal
        simp [hsmall, hnMore] at hparse
        obtain ⟨rawZeros, rawTail, sigZeros, sigTail, hsRaw,
            hrawZeros, hrawTail, hsSig, hsigZeros, hsigTailSharp, hcount⟩ :=
          split_significand_zeros intBytes fracBytes [] hintDigits
            hfracDigits (Or.inl rfl)
        have hsAdjust : s.val = rawZeros ++ rawTail := by
          rw [hsdecomp]
          simpa using hsRaw
        have hsigLenEq : intBytes.length + fracBytes.length =
            sigZeros.length + sigTail.length := by
          have hp := congrArg List.length hsSig
          simpa using hp
        have hnMoreNonneg : 0 <= nMore.val := by
          rw [hnMoreVal]
          omega
        have hnMoreLe : nMore.val <= s.val.length := by
          rw [hnMoreVal, htotalVal, hnDigitsEq, hnAfterEq, hsdecomp]
          simp only [List.length_append, List.length_cons]
          omega
        have hadjustLower : IScalar.min .Isize <=
            nMore.val - (rawZeros.count 48#u8 : Int) := by
          rw [hnMoreVal, hcount, htotalVal, hnDigitsEq, hnAfterEq]
          have hzlen : sigZeros.length <=
              (intBytes ++ fracBytes).length := by
            rw [hsSig]
            simp
          simp [IScalar.min, IScalarTy.numBits,
            Dec2Flt.configured_x86_64_numBits]
          omega
        obtain ⟨adjusted, hadjust, hadjustVal⟩ :=
          NumberHelperAdjustManyExact s nMore rawZeros rawTail hsAdjust
            hrawZeros hrawTail hlen hnMoreNonneg hnMoreLe hadjustLower
        rw [hadjust] at hparse
        by_cases hpositive : 0 < adjusted.val
        · simp [hpositive] at hparse
          cases hmany : num.imp.dec2flt.parse.parse_many_digits s intTail
              0#i64 with
          | fail err => simp [hmany] at hparse
          | div => simp [hmany] at hparse
          | ok result =>
            rcases result with ⟨manyMantissa, manyExponent⟩
            simp [hmany] at hparse
            have hsigTailLen : 19 < sigTail.length := by
              rw [hadjustVal, hnMoreVal, hcount, htotalVal, hnDigitsEq,
                hnAfterEq] at hpositive
              omega
            have hsigTailCons : exists first tailRest,
                sigTail = first :: tailRest /\ first ≠ 48#u8 := by
              rcases hsigTailSharp with hnil | hcons
              · rw [hnil] at hsigTailLen
                simp at hsigTailLen
              · exact hcons
            rcases hsigTailCons with ⟨first, tailRest, htailEq, hfirstNe⟩
            have hfirstDigit := hsigDigits first (by
              rw [hsSig, htailEq]
              exact List.mem_append_right sigZeros List.mem_cons_self)
            have hthreshold : 1000000000000000000 <=
                (intBytes ++ fracBytes).foldl digitStep 0 := by
              have hzero := zero_fold sigZeros hsigZeros
              have hlower := fold_lower tailRest (first.val - 48)
              rw [hsSig, List.foldl_append, hzero, htailEq,
                List.foldl_cons]
              change 1000000000000000000 <=
                tailRest.foldl digitStep (digitStep 0 first)
              have hfirstPos : 1 <= first.val - 48 := by
                have hneVal : first.val ≠ 48 := by
                  intro h
                  apply hfirstNe
                  apply UScalar.eq_of_val_eq
                  simpa using h
                omega
              have hpowLower : 1000000000000000000 <=
                  10 ^ tailRest.length := by
                have hlenRest : 18 <= tailRest.length := by
                  rw [htailEq] at hsigTailLen
                  simp only [List.length_cons] at hsigTailLen
                  omega
                have hp := Nat.pow_le_pow_right
                  (by norm_num : 0 < 10) hlenRest
                norm_num at hp ⊢
                exact hp
              have hstep : 10 ^ tailRest.length <=
                  (first.val - 48) * 10 ^ tailRest.length := by
                simpa using Nat.mul_le_mul_right (10 ^ tailRest.length)
                  hfirstPos
              exact hpowLower.trans (hstep.trans (by
                simpa [digitStep] using hlower))
            obtain ⟨consumed, remaining, hpartition, hmanyMantissa,
                hmanyExponent⟩ := NumberHelperFractionalManyExact s intTail
              0#i64 manyExponent manyMantissa intBytes fracBytes []
                (by simpa [List.append_assoc] using hsdecomp)
                (by simp [intTail]) hintDigits hfracDigits (by simp) hlen
                hthreshold hmany
            have hmanyExponentTarget : manyExponent.val =
                -(fracs.length : Int) + remaining.length := by
              rw [hmanyExponent, hfracLen]
              norm_num
            subst d
            have hresult := finish_value
              (num.imp.dec2flt.decimal.Decimal.mk manyExponent
                manyMantissa false true)
              (intBytes ++ fracBytes) (ints ++ fracs)
              (-(fracs.length : Int)) hsigMap (by
                intro digit hdigit
                rcases List.mem_append.mp hdigit with hdigit | hdigit
                · exact hints digit hdigit
                · exact hfrac digit hdigit)
              (Or.inr ⟨rfl, consumed, remaining, hpartition,
                hmanyMantissa, hmanyExponentTarget⟩)
            simpa [DecimalGoalVocabularyDefault, natStep,
              List.foldl_append] using hresult
        · simp [hpositive] at hparse
          have hsigTailLen : sigTail.length <= 19 := by
            rw [hadjustVal, hnMoreVal, hcount, htotalVal, hnDigitsEq,
              hnAfterEq] at hpositive
            omega
          have hsigTailDigits : forall b, List.Mem b sigTail ->
              48 <= b.val /\ b.val <= 57 := by
            intro b hb
            apply hsigDigits b
            rw [hsSig]
            exact List.mem_append_right sigZeros hb
          have hzero := zero_fold sigZeros hsigZeros
          have hfoldLtTail : sigTail.foldl digitStep 0 <
              10 ^ sigTail.length := by
            simpa using fold_upper sigTail 0 hsigTailDigits
          have hfoldLt : (intBytes ++ fracBytes).foldl digitStep 0 <
              10 ^ 19 := by
            rw [hsSig, List.foldl_append, hzero]
            exact hfoldLtTail.trans_le
              (Nat.pow_le_pow_right (by norm_num) hsigTailLen)
          have hfullBound : (intBytes ++ fracBytes).foldl digitStep 0 <=
              U64.max := by
            have hpowMax : 10 ^ 19 <= U64.max := by
              norm_num [U64.max_eq]
            exact (Nat.le_of_lt hfoldLt).trans hpowMax
          obtain ⟨hmantissa, hmantissa1⟩ := hexactScans hfullBound
          subst d
          left
          refine ⟨rfl, ?_⟩
          norm_num
          rw [hmantissa1, hsigFoldEq, hfracExponentTarget,
            List.foldl_append]
          simp [natStep]
    | some e =>
      let upper : Bool := e.1
      let expSign : Option Bool := e.2.1
      let expDigits : List Nat := e.2.2
      change expDigits ≠ [] /\
        (forall digit, List.Mem digit expDigits -> digit < 10) at hexpo
      rcases hexpo with ⟨hexpNe, hexpDigits⟩
      simp [upper, expSign, expDigits] at hbytes
      obtain ⟨intBytes, afterInt, hsval, hintMap, hafterMap⟩ :=
        List.map_eq_append_iff.mp hbytes
      obtain ⟨point, afterPoint, hafterVal, hpointVal, hafterPointMap⟩ :=
        List.map_eq_cons_iff.mp hafterMap
      have hpoint : point = 46#u8 := by
        apply UScalar.eq_of_val_eq
        simpa using hpointVal
      subst point
      obtain ⟨fracBytes, afterFrac, hafterPointVal, hfracMap,
          hafterFracMap⟩ := List.map_eq_append_iff.mp hafterPointMap
      obtain ⟨marker, suffixBytes, hafterFracVal, hmarkerVal, hsuffixMap⟩ :=
        List.map_eq_cons_iff.mp hafterFracMap
      have hmarker : marker = if upper then 69#u8 else 101#u8 := by
        by_cases hu : upper = true
        · rw [if_pos hu]
          apply UScalar.eq_of_val_eq
          simpa [hu, upper] using hmarkerVal
        · rw [if_neg hu]
          apply UScalar.eq_of_val_eq
          simpa [hu, upper] using hmarkerVal
      subst marker
      have hsdecomp : s.val = intBytes ++ 46#u8 ::
          (fracBytes ++ (if upper then 69#u8 else 101#u8) :: suffixBytes) := by
        rw [hsval, hafterVal, hafterPointVal, hafterFracVal]
      have hintDigits := byte_digits intBytes ints hintMap hints
      have hfracDigits := byte_digits fracBytes fracs hfracMap hfrac
      have hmarkerTailProp :
          ((if upper then 69#u8 else 101#u8) :: suffixBytes).length <=
            Usize.max := by
        have hp := s.property
        rw [hsdecomp] at hp
        simp only [List.length_append, List.length_cons] at hp ⊢
        omega
      let markerTail : Slice Std.U8 :=
        ⟨(if upper then 69#u8 else 101#u8) :: suffixBytes,
          hmarkerTailProp⟩
      have hmarkerTailNotDigit : forall b rest,
          markerTail.val = b :: rest ->
          Not (48 <= b.val /\ b.val <= 57) := by
        intro b rest hb
        simp [markerTail] at hb
        rcases hb with ⟨rfl, _⟩
        by_cases hu : upper = true
        · simp [hu]
        · have hu' : upper = false := Bool.eq_false_of_not_eq_true hu
          simp [hu']
      have hintTailProp :
          (46#u8 :: (fracBytes ++ markerTail.val)).length <= Usize.max := by
        have hp := s.property
        rw [hsdecomp] at hp
        simp [markerTail] at hp ⊢
        omega
      let intTail : Slice Std.U8 :=
        ⟨46#u8 :: (fracBytes ++ markerTail.val), hintTailProp⟩
      have hstart : s.val = intBytes ++ 46#u8 ::
          (fracBytes ++ markerTail.val) := by
        simpa [markerTail] using hsdecomp
      have hintTailNotDigit : forall b rest, intTail.val = b :: rest ->
          Not (48 <= b.val /\ b.val <= 57) := by
        intro b rest hb
        simp [intTail] at hb
        rcases hb with ⟨rfl, _⟩
        norm_num
      obtain ⟨mantissa, intRest, hscanInt, hintRest⟩ :=
        NumberHelperDigitScanSourceLength s 0#u64 intBytes intTail.val
          hstart hintDigits hintTailNotDigit hlen
      have hintRestEq : intRest = intTail :=
        (Slice.eq_iff _ _).2 (by simpa using hintRest)
      subst intRest
      obtain ⟨nDigits, hoffInt, hnDigitsVal⟩ :=
        NumberHelperOffsetSourceLength s intTail hlen (by
          rw [hstart]
          simp [intTail])
      have hnDigitsEq : nDigits.val = intBytes.length := by
        rw [hnDigitsVal, hstart]
        simp [intTail]
      have hfracSliceProp : (fracBytes ++ markerTail.val).length <=
          Usize.max := by
        have hp := intTail.property
        simp [intTail] at hp ⊢
        omega
      let fracSlice : Slice Std.U8 :=
        ⟨fracBytes ++ markerTail.val, hfracSliceProp⟩
      have hsplitPoint : core.slice.Slice.split_first intTail =
          ok (some (46#u8, fracSlice)) := by
        simp [core.slice.Slice.split_first, ModelSliceSplitFirst,
          intTail, fracSlice]
      obtain ⟨mantissa1, fracRest, hscanFrac, hfracRest⟩ :=
        NumberHelperDigitScanSourceLength fracSlice mantissa fracBytes
          markerTail.val (by simp [fracSlice]) hfracDigits
            hmarkerTailNotDigit (by
              simp [fracSlice]
              rw [hstart] at hlen
              simp only [List.length_append, List.length_cons] at hlen
              omega)
      have hfracRestEq : fracRest = markerTail :=
        (Slice.eq_iff _ _).2 (by simpa using hfracRest)
      subst fracRest
      obtain ⟨nAfter, hoffFrac, hnAfterVal⟩ :=
        NumberHelperOffsetSourceLength fracSlice markerTail (by
          simp [fracSlice]
          rw [hstart] at hlen
          simp only [List.length_append, List.length_cons] at hlen
          omega) (by simp [fracSlice])
      have hnAfterEq : nAfter.val = fracBytes.length := by
        rw [hnAfterVal]
        simp [fracSlice]
      have hnAfterNotMin : nAfter.val ≠ IScalar.min .Isize := by
        rw [hnAfterEq, IScalar.min]
        simp [IScalarTy.numBits, Dec2Flt.configured_x86_64_numBits]
      obtain ⟨negAfter, hnegAfter, hnegAfterVal⟩ :=
        Aeneas.Std.WP.spec_imp_exists (HNeg.hNeg.step nAfter hnAfterNotMin)
      have hnegCastBounds : IScalar.min .I64 <= negAfter.val /\
          negAfter.val <= IScalar.max .I64 := by
        have hp := hlen
        rw [hstart] at hp
        simp only [List.length_append, List.length_cons] at hp
        rw [hnegAfterVal, hnAfterEq,
          IScalar.min_IScalarTy_I64_eq, I64.min_eq,
          IScalar.max_IScalarTy_I64_eq, I64.max_eq]
        constructor <;> omega
      obtain ⟨fracExponent, hfracExponent, hfracExponentVal⟩ :=
        Aeneas.Std.WP.spec_imp_exists
          (IScalar.cast_inBounds_spec .I64 negAfter hnegCastBounds)
      have hfracExponentEq : fracExponent.val = -(fracBytes.length : Int) := by
        rw [hfracExponentVal, hnegAfterVal, hnAfterEq]
      have htotalBounds : IScalar.min .Isize <= nDigits.val + nAfter.val /\
          nDigits.val + nAfter.val <= IScalar.max .Isize := by
        rw [hnDigitsEq, hnAfterEq]
        simp [IScalar.min, IScalar.max, IScalarTy.numBits,
          Dec2Flt.configured_x86_64_numBits]
        rw [hstart] at hlen
        simp only [List.length_append, List.length_cons] at hlen
        constructor <;> omega
      obtain ⟨totalDigits, htotal, htotalVal⟩ :=
        Aeneas.Std.WP.spec_imp_exists
          (IScalar.add_spec htotalBounds.1 htotalBounds.2)
      have hintLen : intBytes.length = ints.length := by
        have hp := congrArg List.length hintMap
        simpa using hp
      have hfracLen : fracBytes.length = fracs.length := by
        have hp := congrArg List.length hfracMap
        simpa using hp
      have htotalPos : 0 < totalDigits.val := by
        rw [htotalVal, hnDigitsEq, hnAfterEq]
        rcases hsome with hneInt | hneFrac
        · have hp := List.length_pos_of_ne_nil hneInt
          omega
        · have hp := List.length_pos_of_ne_nil hneFrac
          omega
      have hsuffixProp : suffixBytes.length <= Usize.max := by
        have hp := markerTail.property
        simp [markerTail] at hp
        omega
      let suffix : Slice Std.U8 := ⟨suffixBytes, hsuffixProp⟩
      have hsplitMarker : core.slice.Slice.split_first markerTail =
          ok (some (if upper then 69#u8 else 101#u8, suffix)) := by
        simp [core.slice.Slice.split_first, ModelSliceSplitFirst,
          markerTail, suffix]
      obtain ⟨expBytes, hsuffixDecomp, hexpMap⟩ :=
        NumberHelperSplitExponentSuffix expSign suffixBytes expDigits hsuffixMap
      have hexpByteDigits := byte_digits expBytes expDigits hexpMap hexpDigits
      have hexpDigitMap : expBytes.map (fun b : Std.U8 => b.val - 48) =
          expDigits := unrender_digits expBytes expDigits hexpMap hexpDigits
      have hexpByteNeProp : expBytes ≠ [] := by
        intro hempty
        rw [hempty] at hexpDigitMap
        simp at hexpDigitMap
        exact hexpNe hexpDigitMap
      have hexpByteNe : expBytes != [] := by
        simpa only [bne_iff_ne] using hexpByteNeProp
      have hsignByteMap :
          (match expSign with
          | none => ([] : List Std.U8)
          | some negative => [if negative then 45#u8 else 43#u8]).map
              (fun b : Std.U8 => b.val) =
            (match expSign with
            | none => []
            | some negative => [if negative then 45 else 43]) := by
        cases expSign with
        | none => rfl
        | some negative => cases negative <;> rfl
      have hsuffixDecomp' : suffix.val =
          (match expSign with
          | none => []
          | some negative => [if negative then 45#u8 else 43#u8]) ++
            expBytes := by
        change suffixBytes = _
        apply u8_list_eq_of_val_map
        dsimp [expSign, expDigits] at hsignByteMap ⊢
        rw [hsuffixMap, List.map_append, hsignByteMap, hexpMap]
        rfl
      obtain ⟨parsedExp, scientificRest, hscientific, hscientificRest,
          hparsedExp⟩ := NumberHelperScientificExact suffix expSign expBytes
        hexpByteNe hexpByteDigits hsuffixDecomp'
      have hparsedExpValue : parsedExp.val =
          if expSign = some true then
            -((expDigits.foldl
              (fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int)
          else ((expDigits.foldl
            (fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int) := by
        rw [hparsedExp, guarded_fold_map, hexpDigitMap]
      have hparsedExpTarget : parsedExp.val =
          (match expSign with
          | some true => -((expDigits.foldl
              (fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int)
          | _ => ((expDigits.foldl
              (fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int)) := by
        rw [hparsedExpValue]
        exact signed_if_eq_match expSign _
      obtain ⟨fullOffset, hoffFull, hfullOffsetVal⟩ :=
        NumberHelperOffsetSourceLength s scientificRest hlen (by
          simp [hscientificRest])
      have hfullCast : lift (IScalar.hcast .Usize fullOffset) =
          ok (Slice.len s) := by
        have hbound : 0 <= fullOffset.val /\
            fullOffset.val <= UScalar.max .Usize := by
          rw [hfullOffsetVal, hscientificRest]
          simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
          omega
        obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
          (IScalar.hcast_inBounds_spec .Usize fullOffset hbound)
        rw [hz]
        congr 2
        apply UScalar.eq_of_val_eq
        rw [hfullOffsetVal, hscientificRest] at hzval
        simpa [Slice.len_val] using hzval
      have hnotempty : Not (s.val = []) := by simpa using hne
      unfold num.imp.dec2flt.parse.parse_number at hparse
      simp [hnotempty] at hparse
      unfold num.imp.dec2flt.parse.parse_partial_number at hparse
      simp [hnotempty, hscanInt, hoffInt, hsplitPoint, hscanFrac,
        hoffFrac, hnegAfter, hfracExponent] at hparse
      norm_num at hparse
      simp only [UScalar.ofNat, UScalar.ofNatCore] at hparse
      cases hupper : upper <;>
        simp [hupper, htotal, htotalPos, hsplitMarker, hscientific,
          hoffFull, hfullCast, UScalar.ofNatCore,
          core.option.Option.Insts.CoreOpsTry_traitTry.branch,
          ModelOptionBranch, ModelOptionFromResidual] at hparse
      all_goals
        cases hsum : fracExponent + parsedExp with
        | fail err => simp [hsum] at hparse
        | div => simp [hsum] at hparse
        | ok combinedExponent =>
          simp [hsum] at hparse
          have hcombinedVal : combinedExponent.val =
              fracExponent.val + parsedExp.val := by
            have h := IScalar.add_equiv fracExponent parsedExp
            rw [hsum] at h
            exact h.2.1
          have hdigitInt : intBytes.map (fun b : Std.U8 => b.val - 48) =
              ints := unrender_digits intBytes ints hintMap hints
          have hdigitFrac : fracBytes.map (fun b : Std.U8 => b.val - 48) =
              fracs := unrender_digits fracBytes fracs hfracMap hfrac
          have hsigMap : (intBytes ++ fracBytes).map
              (fun b : Std.U8 => b.val - 48) = ints ++ fracs := by
            simp [hdigitInt, hdigitFrac]
          have hsigDigits : forall b, List.Mem b (intBytes ++ fracBytes) ->
              48 <= b.val /\ b.val <= 57 := by
            intro b hb
            rcases List.mem_append.mp hb with hb | hb
            · exact hintDigits b hb
            · exact hfracDigits b hb
          have hsigFoldEq : (intBytes ++ fracBytes).foldl digitStep 0 =
              (ints ++ fracs).foldl natStep 0 := by
            rw [fold_map, hsigMap]
          have hcombinedExponentTarget : combinedExponent.val =
              parsedExp.val - (fracs.length : Int) := by
            rw [hcombinedVal, hfracExponentEq, hfracLen]
            omega
          have hexactScans : (intBytes ++ fracBytes).foldl digitStep 0 <=
              U64.max ->
              mantissa.val = intBytes.foldl digitStep 0 /\
              mantissa1.val = (intBytes ++ fracBytes).foldl digitStep 0 := by
            as_aux_lemma =>
            intro hfullBound
            have hprefixLe : intBytes.foldl digitStep 0 <=
                (intBytes ++ fracBytes).foldl digitStep 0 := by
              rw [List.foldl_append]
              exact fold_ge_start fracBytes _
            have hintBound : intBytes.foldl digitStep 0 <= U64.max :=
              hprefixLe.trans hfullBound
            obtain ⟨exactInt, exactIntRest, hexactInt, hexactIntRest,
                hexactIntValue⟩ := NumberHelperDigitScanExact s 0#u64 intBytes
              intTail.val hstart hintDigits hintTailNotDigit hlen
                (by simpa [digitStep] using hintBound)
            have hmantissa : mantissa.val =
                intBytes.foldl digitStep 0 := by
              rw [hscanInt] at hexactInt
              simp at hexactInt
              rcases hexactInt with ⟨rfl, rfl⟩
              simpa [digitStep] using hexactIntValue
            have hfracBound : fracBytes.foldl digitStep mantissa.val <=
                U64.max := by
              rw [hmantissa, ← List.foldl_append]
              exact hfullBound
            obtain ⟨exactFrac, exactFracRest, hexactFrac, hexactFracRest,
                hexactFracValue⟩ := NumberHelperDigitScanExact fracSlice
              mantissa fracBytes markerTail.val (by simp [fracSlice])
                hfracDigits hmarkerTailNotDigit (by
                  simp [fracSlice]
                  rw [hstart] at hlen
                  simp only [List.length_append, List.length_cons] at hlen
                  omega) (by simpa [digitStep] using hfracBound)
            have hmantissa1 : mantissa1.val =
                (intBytes ++ fracBytes).foldl digitStep 0 := by
              rw [hscanFrac] at hexactFrac
              simp at hexactFrac
              rcases hexactFrac with ⟨rfl, rfl⟩
              rw [List.foldl_append, ← hmantissa]
              simpa [digitStep] using hexactFracValue
            exact ⟨hmantissa, hmantissa1⟩
          by_cases hsmall : totalDigits.val <= 19
          · simp [hsmall] at hparse
            have hsigLen : (intBytes ++ fracBytes).length <= 19 := by
              rw [List.length_append]
              omega
            have hfoldLt : (intBytes ++ fracBytes).foldl digitStep 0 <
                10 ^ (intBytes ++ fracBytes).length := by
              simpa using fold_upper (intBytes ++ fracBytes) 0 hsigDigits
            have hfullBound : (intBytes ++ fracBytes).foldl digitStep 0 <=
                U64.max := by
              have hp := hfoldLt.trans_le
                (Nat.pow_le_pow_right (by norm_num) hsigLen)
              have hpowMax : 10 ^ 19 <= U64.max := by
                norm_num [U64.max_eq]
              exact (Nat.le_of_lt hp).trans hpowMax
            obtain ⟨hmantissa, hmantissa1⟩ := hexactScans hfullBound
            subst d
            left
            refine ⟨rfl, ?_⟩
            norm_num
            rw [hmantissa1, hsigFoldEq, hcombinedExponentTarget,
              List.foldl_append]
            simp [natStep, hparsedExpTarget, expSign, expDigits]
            all_goals exact Or.inl rfl
          · have hlarge : 19 < totalDigits.val := by omega
            have hsubBounds : IScalar.min .Isize <= totalDigits.val - 19 /\
                totalDigits.val - 19 <= IScalar.max .Isize := by
              have hb := IScalar.hBounds totalDigits
              simp [IScalar.min, IScalar.max, IScalarTy.numBits,
                Dec2Flt.configured_x86_64_numBits] at hb ⊢
              omega
            obtain ⟨nMore, hnMore, hnMoreVal⟩ := Aeneas.Std.WP.spec_imp_exists
              (IScalar.sub_spec (x := totalDigits) (y := 19#isize)
                (by norm_num; omega) (by norm_num; omega))
            norm_num at hnMoreVal
            simp [hsmall, hnMore] at hparse
            obtain ⟨rawZeros, rawTail, sigZeros, sigTail, hsRaw,
                hrawZeros, hrawTail, hsSig, hsigZeros, hsigTailSharp,
                hcount⟩ := split_significand_zeros intBytes fracBytes
              markerTail.val hintDigits hfracDigits (by
                right
                refine ⟨if upper then 69#u8 else 101#u8, suffixBytes,
                  by simp [markerTail], ?_, ?_⟩
                · simp [hupper]
                · simp [hupper])
            have hsAdjust : s.val = rawZeros ++ rawTail := by
              rw [hstart]
              simpa using hsRaw
            have hsigLenEq : intBytes.length + fracBytes.length =
                sigZeros.length + sigTail.length := by
              have hp := congrArg List.length hsSig
              simpa using hp
            have hnMoreNonneg : 0 <= nMore.val := by
              rw [hnMoreVal]
              omega
            have hnMoreLe : nMore.val <= s.val.length := by
              rw [hnMoreVal, htotalVal, hnDigitsEq, hnAfterEq, hstart]
              simp only [List.length_append, List.length_cons]
              omega
            have hadjustLower : IScalar.min .Isize <=
                nMore.val - (rawZeros.count 48#u8 : Int) := by
              rw [hnMoreVal, hcount, htotalVal, hnDigitsEq, hnAfterEq]
              have hzlen : sigZeros.length <=
                  (intBytes ++ fracBytes).length := by
                rw [hsSig]
                simp
              simp [IScalar.min, IScalarTy.numBits,
                Dec2Flt.configured_x86_64_numBits]
              omega
            obtain ⟨adjusted, hadjust, hadjustVal⟩ :=
              NumberHelperAdjustManyExact s nMore rawZeros rawTail hsAdjust
                hrawZeros hrawTail hlen hnMoreNonneg hnMoreLe hadjustLower
            rw [hadjust] at hparse
            by_cases hpositive : 0 < adjusted.val
            · simp [hpositive] at hparse
              cases hmany : num.imp.dec2flt.parse.parse_many_digits s intTail
                  parsedExp with
              | fail err => simp [hmany] at hparse
              | div => simp [hmany] at hparse
              | ok result =>
                rcases result with ⟨manyMantissa, manyExponent⟩
                simp [hmany] at hparse
                have hsigTailLen : 19 < sigTail.length := by
                  rw [hadjustVal, hnMoreVal, hcount, htotalVal, hnDigitsEq,
                    hnAfterEq] at hpositive
                  omega
                have hsigTailCons : exists first tailRest,
                    sigTail = first :: tailRest /\ first ≠ 48#u8 := by
                  rcases hsigTailSharp with hnil | hcons
                  · rw [hnil] at hsigTailLen
                    simp at hsigTailLen
                  · exact hcons
                rcases hsigTailCons with
                  ⟨first, tailRest, htailEq, hfirstNe⟩
                have hfirstDigit := hsigDigits first (by
                  rw [hsSig, htailEq]
                  exact List.mem_append_right sigZeros List.mem_cons_self)
                have hthreshold : 1000000000000000000 <=
                    (intBytes ++ fracBytes).foldl digitStep 0 := by
                  have hzero := zero_fold sigZeros hsigZeros
                  have hlower := fold_lower tailRest (first.val - 48)
                  rw [hsSig, List.foldl_append, hzero, htailEq,
                    List.foldl_cons]
                  change 1000000000000000000 <=
                    tailRest.foldl digitStep (digitStep 0 first)
                  have hfirstPos : 1 <= first.val - 48 := by
                    have hneVal : first.val ≠ 48 := by
                      intro h
                      apply hfirstNe
                      apply UScalar.eq_of_val_eq
                      simpa using h
                    omega
                  have hpowLower : 1000000000000000000 <=
                      10 ^ tailRest.length := by
                    have hlenRest : 18 <= tailRest.length := by
                      rw [htailEq] at hsigTailLen
                      simp only [List.length_cons] at hsigTailLen
                      omega
                    have hp := Nat.pow_le_pow_right
                      (by norm_num : 0 < 10) hlenRest
                    norm_num at hp ⊢
                    exact hp
                  have hstep : 10 ^ tailRest.length <=
                      (first.val - 48) * 10 ^ tailRest.length := by
                    simpa using Nat.mul_le_mul_right (10 ^ tailRest.length)
                      hfirstPos
                  exact hpowLower.trans (hstep.trans (by
                    simpa [digitStep] using hlower))
                obtain ⟨consumed, remaining, hpartition, hmanyMantissa,
                    hmanyExponent⟩ := NumberHelperFractionalManyExact s
                  intTail parsedExp manyExponent manyMantissa intBytes
                    fracBytes markerTail.val hstart (by simp [intTail])
                    hintDigits hfracDigits hmarkerTailNotDigit hlen
                    hthreshold hmany
                have hmanyExponentTarget : manyExponent.val =
                    parsedExp.val - (fracs.length : Int) +
                      remaining.length := by
                  rw [hmanyExponent, hfracLen]
                subst d
                have hresult := finish_value
                  (num.imp.dec2flt.decimal.Decimal.mk manyExponent
                    manyMantissa false true)
                  (intBytes ++ fracBytes) (ints ++ fracs)
                  (parsedExp.val - (fracs.length : Int)) hsigMap (by
                    intro digit hdigit
                    rcases List.mem_append.mp hdigit with hdigit | hdigit
                    · exact hints digit hdigit
                    · exact hfrac digit hdigit)
                  (Or.inr ⟨rfl, consumed, remaining, hpartition,
                    hmanyMantissa, hmanyExponentTarget⟩)
                simpa [DecimalGoalVocabularyDefault, natStep,
                  List.foldl_append, hparsedExpTarget, expSign, expDigits]
                    using hresult
            · simp [hpositive] at hparse
              have hsigTailLen : sigTail.length <= 19 := by
                rw [hadjustVal, hnMoreVal, hcount, htotalVal, hnDigitsEq,
                  hnAfterEq] at hpositive
                omega
              have hsigTailDigits : forall b, List.Mem b sigTail ->
                  48 <= b.val /\ b.val <= 57 := by
                intro b hb
                apply hsigDigits b
                rw [hsSig]
                exact List.mem_append_right sigZeros hb
              have hzero := zero_fold sigZeros hsigZeros
              have hfoldLtTail : sigTail.foldl digitStep 0 <
                  10 ^ sigTail.length := by
                simpa using fold_upper sigTail 0 hsigTailDigits
              have hfoldLt : (intBytes ++ fracBytes).foldl digitStep 0 <
                  10 ^ 19 := by
                rw [hsSig, List.foldl_append, hzero]
                exact hfoldLtTail.trans_le
                  (Nat.pow_le_pow_right (by norm_num) hsigTailLen)
              have hfullBound :
                  (intBytes ++ fracBytes).foldl digitStep 0 <= U64.max := by
                have hpowMax : 10 ^ 19 <= U64.max := by
                  norm_num [U64.max_eq]
                exact (Nat.le_of_lt hfoldLt).trans hpowMax
              obtain ⟨hmantissa, hmantissa1⟩ := hexactScans hfullBound
              subst d
              left
              refine ⟨rfl, ?_⟩
              norm_num
              rw [hmantissa1, hsigFoldEq, hcombinedExponentTarget,
                List.foldl_append]
              simp [natStep, hparsedExpTarget, expSign, expDigits]
              all_goals exact Or.inl rfl

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.Assumptions
import Tablet.DecimalGoalVocabularyDefault
import Tablet.ModelOptionBranch
import Tablet.ModelOptionFromResidual
import Tablet.ModelSliceSplitFirst
import Tablet.ModelU64BitAnd
import Tablet.ModelU64BitOr
import Tablet.ModelU8IsAsciiDigit
import Tablet.NumberHelperAdjustManyExact
import Tablet.NumberHelperDecimalPrefixInterval
import Tablet.NumberHelperDigitScanExact
import Tablet.NumberHelperDigitScanSourceLength
import Tablet.NumberHelperFractionalManyExact
import Tablet.NumberHelperIntegralManyExact
import Tablet.NumberHelperOffsetSourceLength
import Tablet.NumberHelperParseEightDigitsExact
import Tablet.NumberHelperScientificExact
import Tablet.NumberHelperSplitExponentSuffix
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_read_u64
import Tablet.SourceValidByteSlice
import Tablet.U64_Insts_CoreOpsBitBitAndU64U64
import Tablet.U64_Insts_CoreOpsBitBitOrU64U64
import Tablet.num_imp_dec2flt_common_is_8digits
import Tablet.num_imp_dec2flt_decimal_Decimal
import Tablet.num_imp_dec2flt_parse_MIN_19DIGIT_INT
import Tablet.num_imp_dec2flt_parse_adjust_many_digit_count
import Tablet.num_imp_dec2flt_parse_parse_8digits
import Tablet.num_imp_dec2flt_parse_parse_8digits_MASK
import Tablet.num_imp_dec2flt_parse_parse_8digits_MUL1
import Tablet.num_imp_dec2flt_parse_parse_8digits_MUL2
import Tablet.num_imp_dec2flt_parse_parse_many_digits
import Tablet.num_imp_dec2flt_parse_parse_number
import Tablet.num_imp_dec2flt_parse_parse_partial_number
import Tablet.num_imp_dec2flt_parse_parse_scientific
import Tablet.num_imp_dec2flt_parse_try_parse_19digits
import Tablet.num_imp_dec2flt_parse_try_parse_digits

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 1000000
set_option maxRecDepth 10000

namespace dec2flt_model

-- [TABLET NODE: NumberHelperAccumulatedValue]
theorem NumberHelperAccumulatedValue :
    ∀ (s : Slice Std.U8) (x : DecimalLexeme) d, SourceValidByteSlice s -> s.val ≠ [] -> x.leadingSign = none ->
      DecimalGoalVocabularyDefault.validNumeric x -> DecimalGoalVocabularyDefault.bytes s = DecimalGoalVocabularyDefault.renderNumeric x ->
      num.imp.dec2flt.parse.parse_number s = ok (some d) ->
      (d.many_digits = false ∧ DecimalGoalVocabularyDefault.decimalMagnitude d = DecimalGoalVocabularyDefault.accumulatedMagnitude x) ∨
      (d.many_digits = true ∧ DecimalGoalVocabularyDefault.decimalMagnitude d <= DecimalGoalVocabularyDefault.accumulatedMagnitude x ∧
        DecimalGoalVocabularyDefault.accumulatedMagnitude x <
          ((d.mantissa.val + 1 : Nat) : Real) * (10 : Real) ^ d.exponent.val) := by
-- BODY
  intro s x d hsource hne hsign hvalid hbytes hparse
  rcases x with ⟨sign, ints, frac, expo⟩
  simp only at hsign
  subst sign
  simp [DecimalGoalVocabularyDefault] at hvalid hbytes ⊢
  rcases hvalid with ⟨hints, hfrac, hsome, hexpo⟩
  have hlen : s.val.length <= 9223372036854775807 := by
    simpa [SourceValidByteSlice] using hsource
  have byte_digits : forall (bs : List Std.U8) (ds : List Nat),
      List.map (fun b : Std.U8 => b.val) bs =
        List.map (fun d : Nat => 48 + d) ds ->
      (forall d, List.Mem d ds -> d < 10) ->
      forall b, List.Mem b bs -> 48 <= b.val /\ b.val <= 57 := by
    intro bs ds hmap hds b hb
    have hbmap : b.val ∈ List.map (fun b : Std.U8 => b.val) bs :=
      List.mem_map_of_mem hb
    rw [hmap] at hbmap
    obtain ⟨digit, hdigit, hdigitVal⟩ := List.mem_map.mp hbmap
    have := hds digit hdigit
    omega
  let digitStep : Nat -> Std.U8 -> Nat :=
    fun a b => 10 * a + (b.val - 48)
  let natStep : Nat -> Nat -> Nat := fun a digit => 10 * a + digit
  have unrender_digits : forall (bs : List Std.U8) (ds : List Nat),
      List.map (fun b : Std.U8 => b.val) bs =
        List.map (fun digit : Nat => 48 + digit) ds ->
      (forall digit, List.Mem digit ds -> digit < 10) ->
      List.map (fun b : Std.U8 => b.val - 48) bs = ds := by
    intro bs ds hmap hds
    calc
      List.map (fun b : Std.U8 => b.val - 48) bs =
          List.map (fun n : Nat => n - 48)
            (List.map (fun b : Std.U8 => b.val) bs) := by
              simp [List.map_map]
      _ = List.map (fun n : Nat => n - 48)
            (List.map (fun digit : Nat => 48 + digit) ds) := by rw [hmap]
      _ = ds := by
        have cancel : forall xs : List Nat,
            List.map (fun n : Nat => n - 48)
                (List.map (fun digit : Nat => 48 + digit) xs) = xs := by
          intro xs
          induction xs with
          | nil => rfl
          | cons digit xs ih =>
            simp only [List.map_cons, Nat.add_sub_cancel_left]
            exact congrArg (List.cons digit) ih
        exact cancel ds
  have u8_list_eq_of_val_map : forall xs ys : List Std.U8,
      xs.map (fun b : Std.U8 => b.val) =
        ys.map (fun b : Std.U8 => b.val) -> xs = ys := by
    intro xs
    induction xs with
    | nil =>
      intro ys h
      cases ys <;> simp_all
    | cons x xs ih =>
      intro ys h
      cases ys with
      | nil => simp at h
      | cons y ys =>
        simp only [List.map_cons, List.cons.injEq] at h
        have hxy : x = y := UScalar.eq_of_val_eq h.1
        subst y
        rw [ih ys h.2]
  have split_val_map : forall (preVals suffix : List Nat)
      (bs : List Std.U8),
      bs.map (fun b : Std.U8 => b.val) = preVals ++ suffix ->
      exists prefixBytes suffixBytes,
        bs = prefixBytes ++ suffixBytes /\
        prefixBytes.map (fun b : Std.U8 => b.val) = preVals /\
        suffixBytes.map (fun b : Std.U8 => b.val) = suffix := by
    intro preVals
    induction preVals with
    | nil =>
      intro suffix bs h
      exact ⟨[], bs, by simp, rfl, by simpa using h⟩
    | cons value preVals ih =>
      intro suffix bs h
      cases bs with
      | nil => simp at h
      | cons b bs =>
        simp only [List.map_cons, List.cons_append, List.cons.injEq] at h
        obtain ⟨prefixBytes, suffixBytes, hsplit, hp, hs⟩ :=
          ih suffix bs h.2
        exact ⟨b :: prefixBytes, suffixBytes, by simp [hsplit],
          by simp [h.1, hp], hs⟩
  have fold_map : forall (bs : List Std.U8) (a : Nat),
      bs.foldl digitStep a =
        (bs.map (fun b : Std.U8 => b.val - 48)).foldl natStep a := by
    intro bs a
    induction bs generalizing a with
    | nil => rfl
    | cons b bs ih =>
      simp only [List.foldl_cons, List.map_cons]
      exact ih _
  have guarded_fold_map : forall (bs : List Std.U8) (a : Nat),
      bs.foldl (fun a b => if a < 65536 then
          10 * a + (b.val - 48) else a) a =
        (bs.map (fun b : Std.U8 => b.val - 48)).foldl
          (fun a digit => if a < 65536 then 10 * a + digit else a) a := by
    intro bs a
    induction bs generalizing a with
    | nil => rfl
    | cons b bs ih =>
      simp only [List.foldl_cons, List.map_cons]
      exact ih _
  have signed_if_eq_match : forall (sign : Option Bool) (n : Int),
      (if sign = some true then -n else n) =
        match sign with
        | some true => -n
        | _ => n := by
    intro sign n
    cases sign with
    | none => rfl
    | some negative => cases negative <;> rfl
  have fold_upper : forall (bs : List Std.U8) (a : Nat),
      (forall b, List.Mem b bs -> 48 <= b.val /\ b.val <= 57) ->
      bs.foldl digitStep a < (a + 1) * 10 ^ bs.length := by
    intro bs
    induction bs with
    | nil => intro a h; simp
    | cons b bs ih =>
      intro a h
      have hb := h b List.mem_cons_self
      have hbs : forall c, List.Mem c bs -> 48 <= c.val /\ c.val <= 57 := by
        intro c hc
        exact h c (List.mem_cons_of_mem b hc)
      simp only [List.foldl_cons, List.length_cons, Nat.pow_succ]
      have hrec := ih (digitStep a b) hbs
      have hcoeff : digitStep a b + 1 <= 10 * (a + 1) := by
        simp only [digitStep]
        omega
      have hmul := Nat.mul_le_mul_right (10 ^ bs.length) hcoeff
      exact hrec.trans_le (by
        simpa [Nat.mul_assoc, Nat.mul_comm, Nat.mul_left_comm] using hmul)
  have fold_lower : forall (bs : List Std.U8) (a : Nat),
      a * 10 ^ bs.length <= bs.foldl digitStep a := by
    intro bs
    induction bs with
    | nil => intro a; simp
    | cons b bs ih =>
      intro a
      simp only [List.foldl_cons, List.length_cons, Nat.pow_succ]
      calc
        a * (10 ^ bs.length * 10) = (10 * a) * 10 ^ bs.length := by ring
        _ <= digitStep a b * 10 ^ bs.length := by
          apply Nat.mul_le_mul_right
          simp [digitStep]
        _ <= bs.foldl digitStep (digitStep a b) := ih _
  have fold_ge_start : forall (bs : List Std.U8) (a : Nat),
      a <= bs.foldl digitStep a := by
    intro bs
    induction bs with
    | nil => intro a; rfl
    | cons b bs ih =>
      intro a
      apply le_trans (b := digitStep a b)
      · simp [digitStep]
        omega
      · exact ih _
  have split_zeros : forall bs : List Std.U8,
      (forall b, List.Mem b bs -> 48 <= b.val /\ b.val <= 57) ->
      exists zeros tail,
        bs = zeros ++ tail /\
        (forall b, List.Mem b zeros -> b = 48#u8) /\
        (tail = [] \/ exists b rest, tail = b :: rest /\ b != 48#u8) := by
    intro bs
    induction bs with
    | nil =>
      intro h
      exact ⟨[], [], rfl, (by intro b hb; cases hb), Or.inl rfl⟩
    | cons b bs ih =>
      intro h
      by_cases hb : b = 48#u8
      · obtain ⟨zeros, tail, hsplit, hzeros, htail⟩ := ih (by
          intro c hc
          exact h c (List.mem_cons_of_mem b hc))
        refine ⟨b :: zeros, tail, by simp [hsplit], ?_, htail⟩
        intro c hc
        rcases List.mem_cons.mp hc with rfl | hc
        · exact hb
        · exact hzeros c hc
      · exact ⟨[], b :: bs, rfl, (by intro c hc; cases hc), Or.inr ⟨b, bs, rfl, by
          simpa only [bne_iff_ne] using hb⟩⟩
  have zero_fold : forall zeros : List Std.U8,
      (forall b, List.Mem b zeros -> b = 48#u8) ->
      zeros.foldl digitStep 0 = 0 := by
    intro zeros hzeros
    induction zeros with
    | nil => rfl
    | cons b bs ih =>
      have hb := hzeros b List.mem_cons_self
      have hbs : forall c, List.Mem c bs -> c = 48#u8 := by
        intro c hc
        exact hzeros c (List.mem_cons_of_mem b hc)
      simp [hb, digitStep, ih hbs]
  have count_zeros : forall zeros : List Std.U8,
      (forall b, List.Mem b zeros -> b = 48#u8) ->
      zeros.count 48#u8 = zeros.length := by
    intro zeros
    induction zeros with
    | nil => intro h; rfl
    | cons b bs ih =>
      intro h
      have hb := h b List.mem_cons_self
      have hbs : forall c, List.Mem c bs -> c = 48#u8 := by
        intro c hc
        exact h c (List.mem_cons_of_mem b hc)
      simp [hb, ih hbs]
  have split_significand_zeros : forall
      (integer fraction tail : List Std.U8),
      (forall b, List.Mem b integer -> 48 <= b.val /\ b.val <= 57) ->
      (forall b, List.Mem b fraction -> 48 <= b.val /\ b.val <= 57) ->
      (tail = [] \/ exists b rest, tail = b :: rest /\
        b ≠ 48#u8 /\ b ≠ 46#u8) ->
      exists rawZeros rawTail sigZeros sigTail,
        integer ++ 46#u8 :: (fraction ++ tail) = rawZeros ++ rawTail /\
        (forall b, List.Mem b rawZeros -> b = 48#u8 \/ b = 46#u8) /\
        (rawTail = [] \/ exists b rest, rawTail = b :: rest /\
          b ≠ 48#u8 /\ b ≠ 46#u8) /\
        integer ++ fraction = sigZeros ++ sigTail /\
        (forall b, List.Mem b sigZeros -> b = 48#u8) /\
        (sigTail = [] \/ exists b rest, sigTail = b :: rest /\
          b ≠ 48#u8) /\
        rawZeros.count 48#u8 = sigZeros.length := by
    intro integer fraction tail hinteger hfraction htail
    obtain ⟨intZeros, intSig, hintSplit, hintZeros, hintSig⟩ :=
      split_zeros integer hinteger
    rcases hintSig with hintNil | ⟨b, intRest, hintSigEq, hb⟩
    · obtain ⟨fracZeros, fracSig, hfracSplit, hfracZeros, hfracSig⟩ :=
      split_zeros fraction hfraction
      have hfracSigNe : fracSig = [] \/ exists c rest,
          fracSig = c :: rest /\ c ≠ 48#u8 := by
        rcases hfracSig with hnil | ⟨c, rest, heq, hc⟩
        · exact Or.inl hnil
        · exact Or.inr ⟨c, rest, heq,
            by simpa only [bne_iff_ne] using hc⟩
      refine ⟨intZeros ++ 46#u8 :: fracZeros, fracSig ++ tail,
        intZeros ++ fracZeros, fracSig, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩
      · rw [hintSplit, hintNil, hfracSplit]
        simp [List.append_assoc]
      · intro c hc
        rcases List.mem_append.mp hc with hc | hc
        · exact Or.inl (hintZeros c hc)
        · rcases List.mem_cons.mp hc with rfl | hc
          · exact Or.inr rfl
          · exact Or.inl (hfracZeros c hc)
      · rcases hfracSigNe with hnil | ⟨c, rest, hfracSigEq, hc⟩
        · rw [hnil]
          simpa using htail
        · right
          refine ⟨c, rest ++ tail, by simp [hfracSigEq], ?_, ?_⟩
          · exact hc
          · have hcdigit := hfraction c (by
              rw [hfracSplit, hfracSigEq]
              exact List.mem_append_right fracZeros List.mem_cons_self)
            intro hpoint
            subst c
            norm_num at hcdigit
      · rw [hintSplit, hintNil, hfracSplit]
        simp [List.append_assoc]
      · intro c hc
        rcases List.mem_append.mp hc with hc | hc
        · exact hintZeros c hc
        · exact hfracZeros c hc
      · exact hfracSigNe
      · rw [List.count_append, List.count_cons, count_zeros intZeros hintZeros,
          count_zeros fracZeros hfracZeros]
        norm_num
    · refine ⟨intZeros, intSig ++ 46#u8 :: (fraction ++ tail),
        intZeros, intSig ++ fraction, ?_, ?_, ?_, ?_, hintZeros, ?_, ?_⟩
      · rw [hintSplit]
        simp [List.append_assoc]
      · intro c hc
        exact Or.inl (hintZeros c hc)
      · right
        refine ⟨b, intRest ++ 46#u8 :: (fraction ++ tail),
          by simp [hintSigEq], ?_, ?_⟩
        · simpa only [bne_iff_ne] using hb
        · have hbdigit := hinteger b (by
            rw [hintSplit, hintSigEq]
            exact List.mem_append_right intZeros List.mem_cons_self)
          intro hpoint
          subst b
          norm_num at hbdigit
      · rw [hintSplit]
        simp [List.append_assoc]
      · exact Or.inr ⟨b, intRest ++ fraction, by simp [hintSigEq],
          by simpa only [bne_iff_ne] using hb⟩
      · exact count_zeros intZeros hintZeros
  have finish_value : forall (record : num.imp.dec2flt.decimal.Decimal)
      (bytes : List Std.U8) (digits : List Nat) (e : Int),
      bytes.map (fun b : Std.U8 => b.val - 48) = digits ->
      (forall digit, List.Mem digit digits -> digit < 10) ->
      ((record.many_digits = false /\
          record.mantissa.val = bytes.foldl digitStep 0 /\
          record.exponent.val = e) \/
        (record.many_digits = true /\ exists consumed remaining,
          bytes = consumed ++ remaining /\
          record.mantissa.val = consumed.foldl digitStep 0 /\
          record.exponent.val = e + remaining.length)) ->
      (record.many_digits = false /\
          DecimalGoalVocabularyDefault.decimalMagnitude record =
            ((digits.foldl natStep 0 : Nat) : Real) * (10 : Real) ^ e) \/
        (record.many_digits = true /\
          DecimalGoalVocabularyDefault.decimalMagnitude record <=
            ((digits.foldl natStep 0 : Nat) : Real) * (10 : Real) ^ e /\
          ((digits.foldl natStep 0 : Nat) : Real) * (10 : Real) ^ e <
            ((record.mantissa.val + 1 : Nat) : Real) *
              (10 : Real) ^ record.exponent.val) := by
    intro record bytes digits e hmap hdigits hrepresentation
    rcases hrepresentation with ⟨hmany, hmantissa, hexponent⟩ |
        ⟨hmany, consumed, remaining, hpartition, hmantissa, hexponent⟩
    · left
      refine ⟨hmany, ?_⟩
      simp only [DecimalGoalVocabularyDefault]
      rw [hmantissa, hexponent, fold_map, hmap]
    · right
      let headDigits := consumed.map (fun b : Std.U8 => b.val - 48)
      let suffixDigits := remaining.map (fun b : Std.U8 => b.val - 48)
      have hsuffixDigits : forall digit, List.Mem digit suffixDigits ->
          digit < 10 := by
        intro digit hdigit
        apply hdigits digit
        rw [← hmap, hpartition, List.map_append]
        exact List.mem_append_right headDigits hdigit
      have hrenderPartition : headDigits ++ suffixDigits = digits := by
        rw [← List.map_append, ← hpartition]
        exact hmap
      obtain ⟨hintervalLower, hintervalUpper⟩ :=
        NumberHelperDecimalPrefixInterval headDigits suffixDigits
          hsuffixDigits e
      rw [hrenderPartition] at hintervalLower hintervalUpper
      have hconsumedFold := fold_map consumed 0
      dsimp [headDigits, suffixDigits] at hintervalLower hintervalUpper
      rw [← hconsumedFold] at hintervalLower hintervalUpper
      refine ⟨hmany, ?_, ?_⟩
      · simpa [DecimalGoalVocabularyDefault, natStep, hmantissa, hexponent,
          hrenderPartition] using hintervalLower
      · simpa [DecimalGoalVocabularyDefault, natStep, hmantissa, hexponent,
          hrenderPartition] using hintervalUpper
  cases frac with
  | none =>
    simp at hfrac hsome
    cases expo with
    | none =>
      simp at hbytes hexpo
      have hsdigits := byte_digits s.val ints hbytes hints
      obtain ⟨mantissa, rest, hscan, hrest⟩ :=
        NumberHelperDigitScanSourceLength s 0#u64 s.val [] (by simp)
          hsdigits (by simp) hlen
      let empty : Slice Std.U8 := ⟨[], by simp⟩
      have hrestEq : rest = empty := (Slice.eq_iff _ _).2 (by
        simpa [empty] using hrest)
      obtain ⟨nDigits, hoff, hnDigitsVal⟩ :=
        NumberHelperOffsetSourceLength s rest hlen (by simp [hrest])
      have hnDigitsEq : nDigits.val = s.val.length := by
        simpa [hrest] using hnDigitsVal
      have hsplit : core.slice.Slice.split_first rest = ok none := by
        rw [hrestEq]
        simp [core.slice.Slice.split_first, ModelSliceSplitFirst, empty]
      have hnotempty : Not (s.val = []) := by simpa using hne
      have hsLenEq : s.val.length = ints.length := by
        have := congrArg List.length hbytes
        simpa using this
      have hnpos : 0 < nDigits.val := by
        rw [hnDigitsEq, hsLenEq]
        exact_mod_cast List.length_pos_of_ne_nil hsome
      have haddzero : (nDigits + 0#isize) = ok nDigits := by
        have hb := IScalar.hBounds nDigits
        obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
          (IScalar.add_spec (x := nDigits) (y := 0#isize) (by
            simp [IScalar.min, IScalarTy.numBits,
              Dec2Flt.configured_x86_64_numBits]
            omega) (by
            simp [IScalar.max, IScalarTy.numBits,
              Dec2Flt.configured_x86_64_numBits] at hb ⊢
            omega))
        rw [hz]
        congr 2
        apply IScalar.eq_of_val_eq
        simpa using hzval
      have hcastlen : lift (IScalar.hcast .Usize nDigits) =
          ok (Slice.len s) := by
        have hbound : 0 <= nDigits.val /\
            nDigits.val <= UScalar.max .Usize := by
          rw [hnDigitsEq]
          simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
          omega
        obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
          (IScalar.hcast_inBounds_spec .Usize nDigits hbound)
        rw [hz]
        congr 2
        apply UScalar.eq_of_val_eq
        rw [hnDigitsEq] at hzval
        simpa [Slice.len_val] using hzval
      have hdigitMap : s.val.map (fun b : Std.U8 => b.val - 48) = ints :=
        unrender_digits s.val ints hbytes hints
      have hfoldEq : s.val.foldl digitStep 0 = ints.foldl natStep 0 := by
        rw [fold_map, hdigitMap]
      simp [num.imp.dec2flt.parse.parse_number,
        num.imp.dec2flt.parse.parse_partial_number, hscan, hoff, hsplit,
        hnotempty, haddzero, hnpos.ne', hcastlen] at hparse
      by_cases hsmall : nDigits.val <= 19
      · simp [hsmall] at hparse
        subst d
        left
        refine ⟨rfl, ?_⟩
        have hfoldLt : s.val.foldl digitStep 0 < 10 ^ s.val.length := by
          simpa using fold_upper s.val 0 hsdigits
        have hfoldBound : s.val.foldl digitStep 0 <= U64.max := by
          have hlen19 : s.val.length <= 19 := by omega
          have hpow : 10 ^ s.val.length <= 10 ^ 19 := by
            exact Nat.pow_le_pow_right (by norm_num) hlen19
          have : s.val.foldl digitStep 0 < 10 ^ 19 := hfoldLt.trans_le hpow
          rw [U64.max_eq]
          norm_num
          omega
        obtain ⟨exactMantissa, exactRest, hexactScan, hexactRest,
            hexactValue⟩ := NumberHelperDigitScanExact s 0#u64 s.val []
          (by simp) hsdigits (by simp) hlen (by simpa [digitStep] using hfoldBound)
        have hmantissa : mantissa.val = s.val.foldl digitStep 0 := by
          rw [hscan] at hexactScan
          simp at hexactScan
          rcases hexactScan with ⟨rfl, rfl⟩
          simpa [digitStep] using hexactValue
        simp only [num.imp.dec2flt.decimal.Decimal.many_digits,
          num.imp.dec2flt.decimal.Decimal.mantissa,
          num.imp.dec2flt.decimal.Decimal.exponent]
        norm_num
        rw [hmantissa, hfoldEq]
      · have hlarge : 19 < nDigits.val := by omega
        simp [hsmall] at hparse
        have hsubBounds : IScalar.min .Isize <= nDigits.val - 19 /\
            nDigits.val - 19 <= IScalar.max .Isize := by
          have hb := IScalar.hBounds nDigits
          simp [IScalar.min, IScalar.max, IScalarTy.numBits,
            Dec2Flt.configured_x86_64_numBits] at hb ⊢
          omega
        obtain ⟨nMore, hnMore, hnMoreVal⟩ := Aeneas.Std.WP.spec_imp_exists
          (IScalar.sub_spec (x := nDigits) (y := 19#isize)
            (by norm_num; omega)
            (by norm_num; omega))
        norm_num at hnMoreVal
        rw [hnMore] at hparse
        simp at hparse
        obtain ⟨zeros, tail, hsZeros, hzeros, htail⟩ :=
          split_zeros s.val hsdigits
        have hcount : zeros.count 48#u8 = zeros.length :=
          count_zeros zeros hzeros
        have htailSharp : tail = [] \/ exists b rest,
            tail = b :: rest /\ b ≠ 48#u8 /\ b ≠ 46#u8 := by
          rcases htail with hnil | ⟨b, restTail, htailEq, hb⟩
          · exact Or.inl hnil
          · right
            refine ⟨b, restTail, htailEq, ?_, ?_⟩
            · simpa only [bne_iff_ne] using hb
            · have hbdigit := hsdigits b (by
                rw [hsZeros]
                exact List.mem_append_right zeros (by simp [htailEq]))
              intro h46
              subst b
              norm_num at hbdigit
        have hnMoreNonneg : 0 <= nMore.val := by
          rw [hnMoreVal]
          omega
        have hnMoreLe : nMore.val <= s.val.length := by
          rw [hnMoreVal]
          omega
        have hadjustLower : IScalar.min .Isize <=
            nMore.val - (zeros.count 48#u8 : Int) := by
          rw [hnMoreVal, hcount]
          have hzerosLen : zeros.length <= s.val.length := by
            rw [hsZeros]
            simp
          simp [IScalar.min, IScalarTy.numBits,
            Dec2Flt.configured_x86_64_numBits]
          omega
        obtain ⟨adjusted, hadjust, hadjustVal⟩ :=
          NumberHelperAdjustManyExact s nMore zeros tail hsZeros (by
            intro b hb
            exact Or.inl (hzeros b hb)) htailSharp hlen hnMoreNonneg
              hnMoreLe hadjustLower
        rw [hadjust] at hparse
        by_cases hpositive : 0 < adjusted.val
        · simp [hpositive] at hparse
          cases hmany : num.imp.dec2flt.parse.parse_many_digits s rest 0#i64 with
          | fail err => simp [hmany] at hparse
          | div => simp [hmany] at hparse
          | ok result =>
            rcases result with ⟨manyMantissa, manyExponent⟩
            simp [hmany] at hparse
            have htailLen : 19 < tail.length := by
              rw [hadjustVal, hnMoreVal, hnDigitsEq, hcount] at hpositive
              rw [hsZeros] at hpositive
              simp only [List.length_append] at hpositive
              omega
            have htailCons : exists first tailRest,
                tail = first :: tailRest /\
                first ≠ 48#u8 /\ first ≠ 46#u8 := by
              rcases htailSharp with hnil | hcons
              · rw [hnil] at htailLen
                simp at htailLen
              · exact hcons
            rcases htailCons with
              ⟨first, tailRest, htailEq, hfirstNe, hfirstPoint⟩
            have hfirstDigit := hsdigits first (by
              rw [hsZeros, htailEq]
              exact List.mem_append_right zeros List.mem_cons_self)
            have hthreshold : 1000000000000000000 <=
                s.val.foldl (fun a b => 10 * a + (b.val - 48)) 0 := by
              have hzero := zero_fold zeros hzeros
              have hlower := fold_lower tailRest (first.val - 48)
              rw [hsZeros, List.foldl_append, hzero, htailEq,
                List.foldl_cons] 
              change 1000000000000000000 <=
                tailRest.foldl digitStep (digitStep 0 first)
              have hfirstPos : 1 <= first.val - 48 := by
                have hneVal : first.val ≠ 48 := by
                  intro h
                  apply hfirstNe
                  apply UScalar.eq_of_val_eq
                  simpa using h
                omega
              have hpowLower : 1000000000000000000 <=
                  10 ^ tailRest.length := by
                have hlenRest : 18 <= tailRest.length := by
                  rw [htailEq] at htailLen
                  simp only [List.length_cons] at htailLen
                  omega
                have hp := Nat.pow_le_pow_right (by norm_num : 0 < 10) hlenRest
                norm_num at hp ⊢
                exact hp
              have hstep : 10 ^ tailRest.length <=
                  (first.val - 48) * 10 ^ tailRest.length := by
                nlinarith
              exact hpowLower.trans (hstep.trans (by
                simpa [digitStep] using hlower))
            obtain ⟨consumed, remaining, hpartition, hmanyMantissa,
                hmanyExponent⟩ := NumberHelperIntegralManyExact s rest
              0#i64 manyExponent manyMantissa s.val [] (by simp) hrest
                hsdigits (by simp) hlen hthreshold hmany
            let headDigits := consumed.map (fun b : Std.U8 => b.val - 48)
            let suffixDigits := remaining.map (fun b : Std.U8 => b.val - 48)
            have hsuffixDigits : forall digit, List.Mem digit suffixDigits ->
                digit < 10 := by
              intro digit hdigit
              obtain ⟨b, hb, rfl⟩ := List.mem_map.mp hdigit
              have hbAll : List.Mem b s.val := by
                rw [hpartition]
                exact List.mem_append_right consumed hb
              have hbDigit := hsdigits b hbAll
              omega
            have hrenderPartition : headDigits ++ suffixDigits = ints := by
              rw [← List.map_append, ← hpartition]
              exact hdigitMap
            obtain ⟨hintervalLower, hintervalUpper⟩ :=
              NumberHelperDecimalPrefixInterval headDigits suffixDigits
                hsuffixDigits 0
            have hconsumedFold := fold_map consumed 0
            dsimp [headDigits, suffixDigits] at hintervalLower hintervalUpper
            rw [← hconsumedFold] at hintervalLower hintervalUpper
            subst d
            right
            refine ⟨rfl, ?_, ?_⟩
            · simpa [headDigits, suffixDigits, natStep,
                hmanyMantissa, hmanyExponent, hrenderPartition] using
                hintervalLower
            · simpa [headDigits, suffixDigits, natStep,
                hmanyMantissa, hmanyExponent, hrenderPartition] using
                hintervalUpper
        · simp [hpositive] at hparse
          have htailLen : tail.length <= 19 := by
            rw [hadjustVal, hnMoreVal, hnDigitsEq, hcount] at hpositive
            rw [hsZeros] at hpositive
            simp only [List.length_append] at hpositive
            omega
          have htailDigits : forall b, List.Mem b tail ->
              48 <= b.val /\ b.val <= 57 := by
            intro b hb
            apply hsdigits b
            rw [hsZeros]
            exact List.mem_append_right zeros hb
          have hzero := zero_fold zeros hzeros
          have hfoldLtTail : tail.foldl digitStep 0 < 10 ^ tail.length := by
            simpa using fold_upper tail 0 htailDigits
          have hfoldLt : s.val.foldl digitStep 0 < 10 ^ 19 := by
            rw [hsZeros, List.foldl_append, hzero]
            exact hfoldLtTail.trans_le
              (Nat.pow_le_pow_right (by norm_num) htailLen)
          have hfoldBound : s.val.foldl digitStep 0 <= U64.max := by
            rw [U64.max_eq]
            norm_num
            omega
          obtain ⟨exactMantissa, exactRest, hexactScan, hexactRest,
              hexactValue⟩ := NumberHelperDigitScanExact s 0#u64 s.val []
            (by simp) hsdigits (by simp) hlen
              (by simpa [digitStep] using hfoldBound)
          have hmantissa : mantissa.val = s.val.foldl digitStep 0 := by
            rw [hscan] at hexactScan
            simp at hexactScan
            rcases hexactScan with ⟨rfl, rfl⟩
            simpa [digitStep] using hexactValue
          subst d
          left
          refine ⟨rfl, ?_⟩
          norm_num
          rw [hmantissa, hfoldEq]
    | some e =>
      let upper : Bool := e.1
      let expSign : Option Bool := e.2.1
      let expDigits : List Nat := e.2.2
      change expDigits ≠ [] /\
        (forall digit, List.Mem digit expDigits -> digit < 10) at hexpo
      rcases hexpo with ⟨hexpNe, hexpDigits⟩
      simp [upper, expSign, expDigits] at hbytes
      obtain ⟨intBytes, afterInt, hsval, hintMap, hafterMap⟩ :=
        List.map_eq_append_iff.mp hbytes
      obtain ⟨marker, suffixBytes, hafterVal, hmarkerVal, hsuffixMap⟩ :=
        List.map_eq_cons_iff.mp hafterMap
      have hmarker : marker = if upper then 69#u8 else 101#u8 := by
        by_cases hu : upper = true
        · rw [if_pos hu]
          apply UScalar.eq_of_val_eq
          simpa [hu, upper] using hmarkerVal
        · rw [if_neg hu]
          apply UScalar.eq_of_val_eq
          simpa [hu, upper] using hmarkerVal
      subst marker
      have hsdecomp : s.val = intBytes ++
          (if upper then 69#u8 else 101#u8) :: suffixBytes := by
        rw [hsval, hafterVal]
      have hintDigits := byte_digits intBytes ints hintMap hints
      have hintTailProp :
          ((if upper then 69#u8 else 101#u8) :: suffixBytes).length <=
            Usize.max := by
        have hp := s.property
        rw [hsdecomp] at hp
        simp only [List.length_append] at hp ⊢
        omega
      let intTail : Slice Std.U8 :=
        ⟨(if upper then 69#u8 else 101#u8) :: suffixBytes,
          hintTailProp⟩
      have hintTailNotDigit : forall b restBytes,
          intTail.val = b :: restBytes ->
          Not (48 <= b.val /\ b.val <= 57) := by
        intro b restBytes hb
        simp [intTail] at hb
        rcases hb with ⟨rfl, _⟩
        cases upper <;> norm_num
      obtain ⟨mantissa, intRest, hscan, hintRest⟩ :=
        NumberHelperDigitScanSourceLength s 0#u64 intBytes intTail.val
          (by simpa [intTail] using hsdecomp) hintDigits hintTailNotDigit hlen
      have hintRestEq : intRest = intTail :=
        (Slice.eq_iff _ _).2 (by simpa using hintRest)
      subst intRest
      obtain ⟨nDigits, hoffInt, hnDigitsVal⟩ :=
        NumberHelperOffsetSourceLength s intTail hlen (by
          rw [hsdecomp]
          simp [intTail])
      have hnDigitsEq : nDigits.val = intBytes.length := by
        rw [hnDigitsVal, hsdecomp]
        simp [intTail]
      have hsuffixProp : suffixBytes.length <= Usize.max := by
        have hp := intTail.property
        simp [intTail] at hp
        omega
      let suffix : Slice Std.U8 := ⟨suffixBytes, hsuffixProp⟩
      have hsplitMarker : core.slice.Slice.split_first intTail =
          ok (some (if upper then 69#u8 else 101#u8, suffix)) := by
        simp [core.slice.Slice.split_first, ModelSliceSplitFirst,
          intTail, suffix]
      obtain ⟨expBytes, hsuffixDecomp, hexpMap⟩ :=
        NumberHelperSplitExponentSuffix expSign suffixBytes expDigits hsuffixMap
      have hexpByteDigits := byte_digits expBytes expDigits hexpMap hexpDigits
      have hexpDigitMap : expBytes.map (fun b : Std.U8 => b.val - 48) =
          expDigits := unrender_digits expBytes expDigits hexpMap hexpDigits
      have hexpByteNeProp : expBytes ≠ [] := by
        intro hempty
        rw [hempty] at hexpDigitMap
        simp at hexpDigitMap
        exact hexpNe hexpDigitMap
      have hexpByteNe : expBytes != [] := by
        simpa only [bne_iff_ne] using hexpByteNeProp
      have hsignByteMap :
          (match expSign with
          | none => ([] : List Std.U8)
          | some negative => [if negative then 45#u8 else 43#u8]).map
              (fun b : Std.U8 => b.val) =
            (match expSign with
            | none => []
            | some negative => [if negative then 45 else 43]) := by
        cases expSign with
        | none => rfl
        | some negative => cases negative <;> rfl
      have hsuffixDecomp' : suffix.val =
          (match expSign with
          | none => []
          | some negative => [if negative then 45#u8 else 43#u8]) ++
            expBytes := by
        change suffixBytes = _
        apply u8_list_eq_of_val_map
        dsimp [expSign, expDigits] at hsignByteMap ⊢
        rw [hsuffixMap, List.map_append, hsignByteMap, hexpMap]
        rfl
      obtain ⟨parsedExp, scientificRest, hscientific, hscientificRest,
          hparsedExp⟩ := NumberHelperScientificExact suffix expSign expBytes
        hexpByteNe hexpByteDigits hsuffixDecomp'
      have hparsedExpValue : parsedExp.val =
          if expSign = some true then
            -((expDigits.foldl
              (fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int)
          else ((expDigits.foldl
            (fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int) := by
        rw [hparsedExp, guarded_fold_map, hexpDigitMap]
      have hparsedExpTarget : parsedExp.val =
          (match expSign with
          | some true => -((expDigits.foldl
              (fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int)
          | _ => ((expDigits.foldl
              (fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int)) := by
        rw [hparsedExpValue]
        exact signed_if_eq_match expSign _
      have hnotempty : Not (s.val = []) := by simpa using hne
      have hnpos : 0 < nDigits.val := by
        rw [hnDigitsEq]
        have hintLen : intBytes.length = ints.length := by
          have := congrArg List.length hintMap
          simpa using this
        rw [hintLen]
        exact_mod_cast List.length_pos_of_ne_nil hsome
      have haddzero : (nDigits + 0#isize) = ok nDigits := by
        have hb := IScalar.hBounds nDigits
        obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
          (IScalar.add_spec (x := nDigits) (y := 0#isize) (by
            simp [IScalar.min, IScalarTy.numBits,
              Dec2Flt.configured_x86_64_numBits]
            omega) (by
            simp [IScalar.max, IScalarTy.numBits,
              Dec2Flt.configured_x86_64_numBits] at hb ⊢
            omega))
        rw [hz]
        congr 2
        apply IScalar.eq_of_val_eq
        simpa using hzval
      have haddExp : (0#i64 + parsedExp) = ok parsedExp := by
        have hb : IScalar.min .I64 <= (0#i64).val + parsedExp.val /\
            (0#i64).val + parsedExp.val <= IScalar.max .I64 := by
          have hp := IScalar.hBounds parsedExp
          rw [IScalar.min_IScalarTy_I64_eq, I64.min_eq,
            IScalar.max_IScalarTy_I64_eq, I64.max_eq]
          norm_num at hp ⊢
          omega
        obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
          (IScalar.add_spec hb.1 hb.2)
        rw [hz]
        congr 2
        apply IScalar.eq_of_val_eq
        norm_num at hzval
        exact hzval
      obtain ⟨fullOffset, hoffFull, hfullOffsetVal⟩ :=
        NumberHelperOffsetSourceLength s scientificRest hlen (by
          simp [hscientificRest])
      have hfullCast : lift (IScalar.hcast .Usize fullOffset) =
          ok (Slice.len s) := by
        have hbound : 0 <= fullOffset.val /\
            fullOffset.val <= UScalar.max .Usize := by
          rw [hfullOffsetVal, hscientificRest]
          simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
          omega
        obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
          (IScalar.hcast_inBounds_spec .Usize fullOffset hbound)
        rw [hz]
        congr 2
        apply UScalar.eq_of_val_eq
        rw [hfullOffsetVal, hscientificRest] at hzval
        simpa [Slice.len_val] using hzval
      simp [num.imp.dec2flt.parse.parse_number,
        num.imp.dec2flt.parse.parse_partial_number, hnotempty, hscan,
        hoffInt, haddzero, hnpos.ne', hsplitMarker, hscientific,
        core.option.Option.Insts.CoreOpsTry_traitTry.branch,
        ModelOptionBranch, haddExp, hoffFull, hfullCast] at hparse
      cases hupper : upper <;>
        simp [hupper, hsplitMarker, hscientific,
          UScalar.ofNatCore,
          core.option.Option.Insts.CoreOpsTry_traitTry.branch,
          ModelOptionBranch, ModelOptionFromResidual,
          haddExp, hoffFull, hfullCast] at hparse
      all_goals
        have hdigitMap : intBytes.map (fun b : Std.U8 => b.val - 48) = ints :=
          unrender_digits intBytes ints hintMap hints
        have hfoldEq : intBytes.foldl digitStep 0 =
            ints.foldl natStep 0 := by
          rw [fold_map, hdigitMap]
        by_cases hsmall : nDigits.val <= 19
        · simp [haddzero, hnpos.ne', hsmall] at hparse
          have hfoldLt : intBytes.foldl digitStep 0 <
              10 ^ intBytes.length := by
            simpa using fold_upper intBytes 0 hintDigits
          have hfoldBound : intBytes.foldl digitStep 0 <= U64.max := by
            have hlen19 : intBytes.length <= 19 := by
              omega
            have hpow : 10 ^ intBytes.length <= 10 ^ 19 :=
              Nat.pow_le_pow_right (by norm_num) hlen19
            have hlt : intBytes.foldl digitStep 0 < 10 ^ 19 :=
              hfoldLt.trans_le hpow
            rw [U64.max_eq]
            norm_num
            omega
          obtain ⟨exactMantissa, exactRest, hexactScan, hexactRest,
              hexactValue⟩ := NumberHelperDigitScanExact s 0#u64 intBytes
            intTail.val (by simpa [intTail] using hsdecomp) hintDigits
              hintTailNotDigit hlen (by simpa [digitStep] using hfoldBound)
          have hmantissa : mantissa.val = intBytes.foldl digitStep 0 := by
            rw [hscan] at hexactScan
            simp at hexactScan
            rcases hexactScan with ⟨rfl, rfl⟩
            simpa [digitStep] using hexactValue
          subst d
          left
          refine ⟨rfl, ?_⟩
          norm_num
          rw [hmantissa, hfoldEq, hparsedExpTarget]
          rfl
        · have hlarge : 19 < nDigits.val := by omega
          have hsubBounds : IScalar.min .Isize <= nDigits.val - 19 /\
              nDigits.val - 19 <= IScalar.max .Isize := by
            have hb := IScalar.hBounds nDigits
            simp [IScalar.min, IScalar.max, IScalarTy.numBits,
              Dec2Flt.configured_x86_64_numBits] at hb ⊢
            omega
          obtain ⟨nMore, hnMore, hnMoreVal⟩ := Aeneas.Std.WP.spec_imp_exists
            (IScalar.sub_spec (x := nDigits) (y := 19#isize)
              (by norm_num; omega) (by norm_num; omega))
          norm_num at hnMoreVal
          simp [haddzero, hnpos.ne', hsmall, hnMore] at hparse
          obtain ⟨zeros, sigTail, hintZeros, hzeros, hsigTail⟩ :=
            split_zeros intBytes hintDigits
          let rawTail : List Std.U8 := sigTail ++ intTail.val
          have hsAdjust : s.val = zeros ++ rawTail := by
            rw [hsdecomp, hintZeros]
            simp [rawTail, intTail, List.append_assoc]
          have hrawTailSharp : rawTail = [] \/ exists b rest,
              rawTail = b :: rest /\ b ≠ 48#u8 /\ b ≠ 46#u8 := by
            rcases hsigTail with hnil | ⟨b, restTail, htailEq, hb⟩
            · right
              refine ⟨if upper then 69#u8 else 101#u8, suffixBytes,
                ?_, ?_, ?_⟩
              · simp [rawTail, hnil, intTail]
              · norm_num [hupper, UScalar.ofNatCore]
              · norm_num [hupper, UScalar.ofNatCore]
            · right
              refine ⟨b, restTail ++ intTail.val, ?_, ?_, ?_⟩
              · simp [rawTail, htailEq]
              · simpa only [bne_iff_ne] using hb
              · have hbdigit := hintDigits b (by
                  rw [hintZeros, htailEq]
                  exact List.mem_append_right zeros List.mem_cons_self)
                intro hpoint
                subst b
                norm_num at hbdigit
          have hcount : zeros.count 48#u8 = zeros.length :=
            count_zeros zeros hzeros
          have hnMoreNonneg : 0 <= nMore.val := by
            rw [hnMoreVal]
            omega
          have hnMoreLe : nMore.val <= s.val.length := by
            rw [hnMoreVal, hnDigitsEq, hsdecomp]
            simp only [List.length_append]
            omega
          have hadjustLower : IScalar.min .Isize <=
              nMore.val - (zeros.count 48#u8 : Int) := by
            rw [hnMoreVal, hcount, hnDigitsEq]
            have hzerosLen : zeros.length <= intBytes.length := by
              rw [hintZeros]
              simp
            simp [IScalar.min, IScalarTy.numBits,
              Dec2Flt.configured_x86_64_numBits]
            omega
          obtain ⟨adjusted, hadjust, hadjustVal⟩ :=
            NumberHelperAdjustManyExact s nMore zeros rawTail hsAdjust (by
              intro b hb
              exact Or.inl (hzeros b hb)) hrawTailSharp hlen hnMoreNonneg
                hnMoreLe hadjustLower
          rw [hadjust] at hparse
          by_cases hpositive : 0 < adjusted.val
          · simp [hpositive] at hparse
            cases hmany : num.imp.dec2flt.parse.parse_many_digits s intTail
                parsedExp with
            | fail err => simp [hmany] at hparse
            | div => simp [hmany] at hparse
            | ok result =>
              rcases result with ⟨manyMantissa, manyExponent⟩
              simp [hmany] at hparse
              have hsigTailLen : 19 < sigTail.length := by
                rw [hadjustVal, hnMoreVal, hnDigitsEq, hcount] at hpositive
                rw [hintZeros] at hpositive
                simp only [List.length_append] at hpositive
                omega
              have hsigTailCons : exists first tailRest,
                  sigTail = first :: tailRest /\
                  first ≠ 48#u8 /\ first ≠ 46#u8 := by
                rcases hsigTail with hnil | hcons
                · rw [hnil] at hsigTailLen
                  simp at hsigTailLen
                · rcases hcons with ⟨b, restTail, hbEq, hbNe⟩
                  refine ⟨b, restTail, hbEq, ?_, ?_⟩
                  · simpa only [bne_iff_ne] using hbNe
                  · have hbdigit := hintDigits b (by
                      rw [hintZeros, hbEq]
                      exact List.mem_append_right zeros List.mem_cons_self)
                    intro hpoint
                    subst b
                    norm_num at hbdigit
              rcases hsigTailCons with
                ⟨first, tailRest, htailEq, hfirstNe, hfirstPoint⟩
              have hfirstDigit := hintDigits first (by
                rw [hintZeros, htailEq]
                exact List.mem_append_right zeros List.mem_cons_self)
              have hthreshold : 1000000000000000000 <=
                  intBytes.foldl digitStep 0 := by
                have hzero := zero_fold zeros hzeros
                have hlower := fold_lower tailRest (first.val - 48)
                rw [hintZeros, List.foldl_append, hzero, htailEq,
                  List.foldl_cons]
                change 1000000000000000000 <=
                  tailRest.foldl digitStep (digitStep 0 first)
                have hfirstPos : 1 <= first.val - 48 := by
                  have hneVal : first.val ≠ 48 := by
                    intro h
                    apply hfirstNe
                    apply UScalar.eq_of_val_eq
                    simpa using h
                  omega
                have hpowLower : 1000000000000000000 <=
                    10 ^ tailRest.length := by
                  have hlenRest : 18 <= tailRest.length := by
                    rw [htailEq] at hsigTailLen
                    simp only [List.length_cons] at hsigTailLen
                    omega
                  have hp := Nat.pow_le_pow_right
                    (by norm_num : 0 < 10) hlenRest
                  norm_num at hp ⊢
                  exact hp
                have hstep : 10 ^ tailRest.length <=
                    (first.val - 48) * 10 ^ tailRest.length := by
                  nlinarith
                exact hpowLower.trans (hstep.trans (by
                  simpa [digitStep] using hlower))
              obtain ⟨consumed, remaining, hpartition, hmanyMantissa,
                  hmanyExponent⟩ := NumberHelperIntegralManyExact s intTail
                parsedExp manyExponent manyMantissa intBytes intTail.val
                  (by simpa [intTail] using hsdecomp) rfl hintDigits
                  hintTailNotDigit hlen hthreshold hmany
              subst d
              have hresult := finish_value
                (num.imp.dec2flt.decimal.Decimal.mk manyExponent
                  manyMantissa false true)
                intBytes ints parsedExp.val hdigitMap hints
                (Or.inr ⟨rfl, consumed, remaining, hpartition,
                  hmanyMantissa, hmanyExponent⟩)
              simpa [DecimalGoalVocabularyDefault, natStep, hparsedExpTarget,
                expSign, expDigits] using hresult
          · simp [hpositive] at hparse
            have hsigTailLen : sigTail.length <= 19 := by
              rw [hadjustVal, hnMoreVal, hnDigitsEq, hcount] at hpositive
              rw [hintZeros] at hpositive
              simp only [List.length_append] at hpositive
              omega
            have hsigTailDigits : forall b, List.Mem b sigTail ->
                48 <= b.val /\ b.val <= 57 := by
              intro b hb
              apply hintDigits b
              rw [hintZeros]
              exact List.mem_append_right zeros hb
            have hzero := zero_fold zeros hzeros
            have hfoldLtTail : sigTail.foldl digitStep 0 <
                10 ^ sigTail.length := by
              simpa using fold_upper sigTail 0 hsigTailDigits
            have hfoldLt : intBytes.foldl digitStep 0 < 10 ^ 19 := by
              rw [hintZeros, List.foldl_append, hzero]
              exact hfoldLtTail.trans_le
                (Nat.pow_le_pow_right (by norm_num) hsigTailLen)
            have hfoldBound : intBytes.foldl digitStep 0 <= U64.max := by
              rw [U64.max_eq]
              norm_num
              omega
            obtain ⟨exactMantissa, exactRest, hexactScan, hexactRest,
                hexactValue⟩ := NumberHelperDigitScanExact s 0#u64 intBytes
              intTail.val (by simpa [intTail] using hsdecomp) hintDigits
                hintTailNotDigit hlen
                (by simpa [digitStep] using hfoldBound)
            have hmantissa : mantissa.val = intBytes.foldl digitStep 0 := by
              rw [hscan] at hexactScan
              simp at hexactScan
              rcases hexactScan with ⟨rfl, rfl⟩
              simpa [digitStep] using hexactValue
            subst d
            left
            refine ⟨rfl, ?_⟩
            norm_num
            rw [hmantissa, hfoldEq, hparsedExpTarget]
            rfl
  | some fracs =>
    simp at hfrac hsome
    cases expo with
    | none =>
      simp at hbytes hexpo
      obtain ⟨intBytes, afterInt, hsval, hintMap, hafterMap⟩ :=
        List.map_eq_append_iff.mp hbytes
      obtain ⟨point, fracBytes, hafterVal, hpointVal, hfracMap⟩ :=
        List.map_eq_cons_iff.mp hafterMap
      have hpoint : point = 46#u8 := by
        apply UScalar.eq_of_val_eq
        simpa using hpointVal
      subst point
      have hsdecomp : s.val = intBytes ++ 46#u8 :: fracBytes := by
        rw [hsval, hafterVal]
      have hintDigits := byte_digits intBytes ints hintMap hints
      have hfracDigits := byte_digits fracBytes fracs hfracMap hfrac
      have hintTailProp : (46#u8 :: fracBytes).length <= Usize.max := by
        have hp := s.property
        rw [hsdecomp] at hp
        simp only [List.length_append] at hp
        omega
      let intTail : Slice Std.U8 := ⟨46#u8 :: fracBytes, hintTailProp⟩
      have hintTailNotDigit : forall b rest, intTail.val = b :: rest ->
          Not (48 <= b.val /\ b.val <= 57) := by
        intro b rest hb
        simp [intTail] at hb
        rcases hb with ⟨rfl, _⟩
        norm_num
      obtain ⟨mantissa, intRest, hscanInt, hintRest⟩ :=
        NumberHelperDigitScanSourceLength s 0#u64 intBytes intTail.val
          (by simpa [intTail] using hsdecomp) hintDigits
            hintTailNotDigit hlen
      have hintRestEq : intRest = intTail :=
        (Slice.eq_iff _ _).2 (by simpa using hintRest)
      subst intRest
      obtain ⟨nDigits, hoffInt, hnDigitsVal⟩ :=
        NumberHelperOffsetSourceLength s intTail hlen (by
          rw [hsdecomp]
          simp [intTail])
      have hnDigitsEq : nDigits.val = intBytes.length := by
        rw [hnDigitsVal, hsdecomp]
        simp [intTail]
      have hfracProp : fracBytes.length <= Usize.max := by
        have hp := intTail.property
        simp [intTail] at hp ⊢
        omega
      let fracSlice : Slice Std.U8 := ⟨fracBytes, hfracProp⟩
      have hsplitPoint : core.slice.Slice.split_first intTail =
          ok (some (46#u8, fracSlice)) := by
        simp [core.slice.Slice.split_first, ModelSliceSplitFirst,
          intTail, fracSlice]
      obtain ⟨mantissa1, fracRest, hscanFrac, hfracRest⟩ :=
        NumberHelperDigitScanSourceLength fracSlice mantissa fracBytes []
          (by simp [fracSlice]) hfracDigits (by simp) (by
            simp [fracSlice]
            rw [hsdecomp] at hlen
            simp only [List.length_append, List.length_cons] at hlen
            omega)
      let empty : Slice Std.U8 := ⟨[], by simp⟩
      have hfracRestEq : fracRest = empty :=
        (Slice.eq_iff _ _).2 (by simpa [empty] using hfracRest)
      subst fracRest
      obtain ⟨nAfter, hoffFrac, hnAfterVal⟩ :=
        NumberHelperOffsetSourceLength fracSlice empty (by
          simp [fracSlice]
          rw [hsdecomp] at hlen
          simp only [List.length_append, List.length_cons] at hlen
          omega) (by simp [empty])
      have hnAfterEq : nAfter.val = fracBytes.length := by
        rw [hnAfterVal]
        simp [fracSlice, empty]
      have hnAfterNotMin : nAfter.val ≠ IScalar.min .Isize := by
        rw [hnAfterEq, IScalar.min]
        simp [IScalarTy.numBits, Dec2Flt.configured_x86_64_numBits]
      obtain ⟨negAfter, hnegAfter, hnegAfterVal⟩ :=
        Aeneas.Std.WP.spec_imp_exists (HNeg.hNeg.step nAfter hnAfterNotMin)
      have hnegCastBounds : IScalar.min .I64 <= negAfter.val /\
          negAfter.val <= IScalar.max .I64 := by
        have hp := hlen
        rw [hsdecomp] at hp
        simp only [List.length_append, List.length_cons] at hp
        rw [hnegAfterVal, hnAfterEq,
          IScalar.min_IScalarTy_I64_eq, I64.min_eq,
          IScalar.max_IScalarTy_I64_eq, I64.max_eq]
        constructor <;> omega
      obtain ⟨fracExponent, hfracExponent, hfracExponentVal⟩ :=
        Aeneas.Std.WP.spec_imp_exists
          (IScalar.cast_inBounds_spec .I64 negAfter hnegCastBounds)
      have hfracExponentEq : fracExponent.val = -(fracBytes.length : Int) := by
        rw [hfracExponentVal, hnegAfterVal, hnAfterEq]
      have htotalBounds : IScalar.min .Isize <= nDigits.val + nAfter.val /\
          nDigits.val + nAfter.val <= IScalar.max .Isize := by
        rw [hnDigitsEq, hnAfterEq]
        simp [IScalar.min, IScalar.max, IScalarTy.numBits,
          Dec2Flt.configured_x86_64_numBits]
        rw [hsdecomp] at hlen
        simp only [List.length_append, List.length_cons] at hlen
        constructor <;> omega
      obtain ⟨totalDigits, htotal, htotalVal⟩ :=
        Aeneas.Std.WP.spec_imp_exists
          (IScalar.add_spec htotalBounds.1 htotalBounds.2)
      have hintLen : intBytes.length = ints.length := by
        have hp := congrArg List.length hintMap
        simpa using hp
      have hfracLen : fracBytes.length = fracs.length := by
        have hp := congrArg List.length hfracMap
        simpa using hp
      have htotalPos : 0 < totalDigits.val := by
        rw [htotalVal, hnDigitsEq, hnAfterEq]
        rcases hsome with hneInt | hneFrac
        · have hp := List.length_pos_of_ne_nil hneInt
          omega
        · have hp := List.length_pos_of_ne_nil hneFrac
          omega
      obtain ⟨fullOffset, hoffFull, hfullOffsetVal⟩ :=
        NumberHelperOffsetSourceLength s empty hlen (by simp [empty])
      have hfullCast : lift (IScalar.hcast .Usize fullOffset) =
          ok (Slice.len s) := by
        have hbound : 0 <= fullOffset.val /\
            fullOffset.val <= UScalar.max .Usize := by
          rw [hfullOffsetVal]
          simp [empty, UScalar.max, Dec2Flt.configured_x86_64_numBits]
          omega
        obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
          (IScalar.hcast_inBounds_spec .Usize fullOffset hbound)
        rw [hz]
        congr 2
        apply UScalar.eq_of_val_eq
        rw [hfullOffsetVal] at hzval
        simpa [empty, Slice.len_val] using hzval
      have hnotempty : Not (s.val = []) := by simpa using hne
      have hsplitEmpty : core.slice.Slice.split_first empty = ok none := by
        simp [core.slice.Slice.split_first, ModelSliceSplitFirst, empty]
      unfold num.imp.dec2flt.parse.parse_number at hparse
      simp [hnotempty] at hparse
      unfold num.imp.dec2flt.parse.parse_partial_number at hparse
      simp [hnotempty, hscanInt, hoffInt, hsplitPoint, hscanFrac,
        hoffFrac, hnegAfter, hfracExponent] at hparse
      norm_num at hparse
      simp only [UScalar.ofNat, UScalar.ofNatCore] at hparse
      simp [htotal, htotalPos, hsplitEmpty, hoffFull, hfullCast] at hparse
      have hdigitInt : intBytes.map (fun b : Std.U8 => b.val - 48) = ints :=
        unrender_digits intBytes ints hintMap hints
      have hdigitFrac : fracBytes.map (fun b : Std.U8 => b.val - 48) =
          fracs := unrender_digits fracBytes fracs hfracMap hfrac
      have hsigMap : (intBytes ++ fracBytes).map
          (fun b : Std.U8 => b.val - 48) = ints ++ fracs := by
        simp [hdigitInt, hdigitFrac]
      have hsigDigits : forall b, List.Mem b (intBytes ++ fracBytes) ->
          48 <= b.val /\ b.val <= 57 := by
        intro b hb
        rcases List.mem_append.mp hb with hb | hb
        · exact hintDigits b hb
        · exact hfracDigits b hb
      have hsigFoldEq : (intBytes ++ fracBytes).foldl digitStep 0 =
          (ints ++ fracs).foldl natStep 0 := by
        rw [fold_map, hsigMap]
      have hfracExponentTarget : fracExponent.val = -(fracs.length : Int) := by
        rw [hfracExponentEq, hfracLen]
      have hexactScans : (intBytes ++ fracBytes).foldl digitStep 0 <=
          U64.max ->
          mantissa.val = intBytes.foldl digitStep 0 /\
          mantissa1.val = (intBytes ++ fracBytes).foldl digitStep 0 := by
        as_aux_lemma =>
        intro hfullBound
        have hprefixLe : intBytes.foldl digitStep 0 <=
            (intBytes ++ fracBytes).foldl digitStep 0 := by
          rw [List.foldl_append]
          exact fold_ge_start fracBytes _
        have hintBound : intBytes.foldl digitStep 0 <= U64.max :=
          hprefixLe.trans hfullBound
        obtain ⟨exactInt, exactIntRest, hexactInt, hexactIntRest,
            hexactIntValue⟩ := NumberHelperDigitScanExact s 0#u64 intBytes
          intTail.val (by simpa [intTail] using hsdecomp) hintDigits
            hintTailNotDigit hlen (by simpa [digitStep] using hintBound)
        have hmantissa : mantissa.val = intBytes.foldl digitStep 0 := by
          rw [hscanInt] at hexactInt
          simp at hexactInt
          rcases hexactInt with ⟨rfl, rfl⟩
          simpa [digitStep] using hexactIntValue
        have hfracBound : fracBytes.foldl digitStep mantissa.val <=
            U64.max := by
          rw [hmantissa, ← List.foldl_append]
          exact hfullBound
        obtain ⟨exactFrac, exactFracRest, hexactFrac, hexactFracRest,
            hexactFracValue⟩ := NumberHelperDigitScanExact fracSlice mantissa
          fracBytes [] (by simp [fracSlice]) hfracDigits (by simp) (by
            simp [fracSlice]
            rw [hsdecomp] at hlen
            simp only [List.length_append, List.length_cons] at hlen
            omega) (by simpa [digitStep] using hfracBound)
        have hmantissa1 : mantissa1.val =
            (intBytes ++ fracBytes).foldl digitStep 0 := by
          rw [hscanFrac] at hexactFrac
          simp at hexactFrac
          rcases hexactFrac with ⟨rfl, rfl⟩
          rw [List.foldl_append, ← hmantissa]
          simpa [digitStep] using hexactFracValue
        exact ⟨hmantissa, hmantissa1⟩
      by_cases hsmall : totalDigits.val <= 19
      · simp [hsmall] at hparse
        have hsigLen : (intBytes ++ fracBytes).length <= 19 := by
          rw [List.length_append]
          omega
        have hfoldLt : (intBytes ++ fracBytes).foldl digitStep 0 <
            10 ^ (intBytes ++ fracBytes).length := by
          simpa using fold_upper (intBytes ++ fracBytes) 0 hsigDigits
        have hfullBound : (intBytes ++ fracBytes).foldl digitStep 0 <=
            U64.max := by
          have hp := hfoldLt.trans_le
            (Nat.pow_le_pow_right (by norm_num) hsigLen)
          have hpowMax : 10 ^ 19 <= U64.max := by
            norm_num [U64.max_eq]
          exact (Nat.le_of_lt hp).trans hpowMax
        obtain ⟨hmantissa, hmantissa1⟩ := hexactScans hfullBound
        subst d
        left
        refine ⟨rfl, ?_⟩
        norm_num
        rw [hmantissa1, hsigFoldEq, hfracExponentTarget,
          List.foldl_append]
        simp [natStep]
      · have hlarge : 19 < totalDigits.val := by omega
        have hsubBounds : IScalar.min .Isize <= totalDigits.val - 19 /\
            totalDigits.val - 19 <= IScalar.max .Isize := by
          have hb := IScalar.hBounds totalDigits
          simp [IScalar.min, IScalar.max, IScalarTy.numBits,
            Dec2Flt.configured_x86_64_numBits] at hb ⊢
          omega
        obtain ⟨nMore, hnMore, hnMoreVal⟩ := Aeneas.Std.WP.spec_imp_exists
          (IScalar.sub_spec (x := totalDigits) (y := 19#isize)
            (by norm_num; omega) (by norm_num; omega))
        norm_num at hnMoreVal
        simp [hsmall, hnMore] at hparse
        obtain ⟨rawZeros, rawTail, sigZeros, sigTail, hsRaw,
            hrawZeros, hrawTail, hsSig, hsigZeros, hsigTailSharp, hcount⟩ :=
          split_significand_zeros intBytes fracBytes [] hintDigits
            hfracDigits (Or.inl rfl)
        have hsAdjust : s.val = rawZeros ++ rawTail := by
          rw [hsdecomp]
          simpa using hsRaw
        have hsigLenEq : intBytes.length + fracBytes.length =
            sigZeros.length + sigTail.length := by
          have hp := congrArg List.length hsSig
          simpa using hp
        have hnMoreNonneg : 0 <= nMore.val := by
          rw [hnMoreVal]
          omega
        have hnMoreLe : nMore.val <= s.val.length := by
          rw [hnMoreVal, htotalVal, hnDigitsEq, hnAfterEq, hsdecomp]
          simp only [List.length_append, List.length_cons]
          omega
        have hadjustLower : IScalar.min .Isize <=
            nMore.val - (rawZeros.count 48#u8 : Int) := by
          rw [hnMoreVal, hcount, htotalVal, hnDigitsEq, hnAfterEq]
          have hzlen : sigZeros.length <=
              (intBytes ++ fracBytes).length := by
            rw [hsSig]
            simp
          simp [IScalar.min, IScalarTy.numBits,
            Dec2Flt.configured_x86_64_numBits]
          omega
        obtain ⟨adjusted, hadjust, hadjustVal⟩ :=
          NumberHelperAdjustManyExact s nMore rawZeros rawTail hsAdjust
            hrawZeros hrawTail hlen hnMoreNonneg hnMoreLe hadjustLower
        rw [hadjust] at hparse
        by_cases hpositive : 0 < adjusted.val
        · simp [hpositive] at hparse
          cases hmany : num.imp.dec2flt.parse.parse_many_digits s intTail
              0#i64 with
          | fail err => simp [hmany] at hparse
          | div => simp [hmany] at hparse
          | ok result =>
            rcases result with ⟨manyMantissa, manyExponent⟩
            simp [hmany] at hparse
            have hsigTailLen : 19 < sigTail.length := by
              rw [hadjustVal, hnMoreVal, hcount, htotalVal, hnDigitsEq,
                hnAfterEq] at hpositive
              omega
            have hsigTailCons : exists first tailRest,
                sigTail = first :: tailRest /\ first ≠ 48#u8 := by
              rcases hsigTailSharp with hnil | hcons
              · rw [hnil] at hsigTailLen
                simp at hsigTailLen
              · exact hcons
            rcases hsigTailCons with ⟨first, tailRest, htailEq, hfirstNe⟩
            have hfirstDigit := hsigDigits first (by
              rw [hsSig, htailEq]
              exact List.mem_append_right sigZeros List.mem_cons_self)
            have hthreshold : 1000000000000000000 <=
                (intBytes ++ fracBytes).foldl digitStep 0 := by
              have hzero := zero_fold sigZeros hsigZeros
              have hlower := fold_lower tailRest (first.val - 48)
              rw [hsSig, List.foldl_append, hzero, htailEq,
                List.foldl_cons]
              change 1000000000000000000 <=
                tailRest.foldl digitStep (digitStep 0 first)
              have hfirstPos : 1 <= first.val - 48 := by
                have hneVal : first.val ≠ 48 := by
                  intro h
                  apply hfirstNe
                  apply UScalar.eq_of_val_eq
                  simpa using h
                omega
              have hpowLower : 1000000000000000000 <=
                  10 ^ tailRest.length := by
                have hlenRest : 18 <= tailRest.length := by
                  rw [htailEq] at hsigTailLen
                  simp only [List.length_cons] at hsigTailLen
                  omega
                have hp := Nat.pow_le_pow_right
                  (by norm_num : 0 < 10) hlenRest
                norm_num at hp ⊢
                exact hp
              have hstep : 10 ^ tailRest.length <=
                  (first.val - 48) * 10 ^ tailRest.length := by
                simpa using Nat.mul_le_mul_right (10 ^ tailRest.length)
                  hfirstPos
              exact hpowLower.trans (hstep.trans (by
                simpa [digitStep] using hlower))
            obtain ⟨consumed, remaining, hpartition, hmanyMantissa,
                hmanyExponent⟩ := NumberHelperFractionalManyExact s intTail
              0#i64 manyExponent manyMantissa intBytes fracBytes []
                (by simpa [List.append_assoc] using hsdecomp)
                (by simp [intTail]) hintDigits hfracDigits (by simp) hlen
                hthreshold hmany
            have hmanyExponentTarget : manyExponent.val =
                -(fracs.length : Int) + remaining.length := by
              rw [hmanyExponent, hfracLen]
              norm_num
            subst d
            have hresult := finish_value
              (num.imp.dec2flt.decimal.Decimal.mk manyExponent
                manyMantissa false true)
              (intBytes ++ fracBytes) (ints ++ fracs)
              (-(fracs.length : Int)) hsigMap (by
                intro digit hdigit
                rcases List.mem_append.mp hdigit with hdigit | hdigit
                · exact hints digit hdigit
                · exact hfrac digit hdigit)
              (Or.inr ⟨rfl, consumed, remaining, hpartition,
                hmanyMantissa, hmanyExponentTarget⟩)
            simpa [DecimalGoalVocabularyDefault, natStep,
              List.foldl_append] using hresult
        · simp [hpositive] at hparse
          have hsigTailLen : sigTail.length <= 19 := by
            rw [hadjustVal, hnMoreVal, hcount, htotalVal, hnDigitsEq,
              hnAfterEq] at hpositive
            omega
          have hsigTailDigits : forall b, List.Mem b sigTail ->
              48 <= b.val /\ b.val <= 57 := by
            intro b hb
            apply hsigDigits b
            rw [hsSig]
            exact List.mem_append_right sigZeros hb
          have hzero := zero_fold sigZeros hsigZeros
          have hfoldLtTail : sigTail.foldl digitStep 0 <
              10 ^ sigTail.length := by
            simpa using fold_upper sigTail 0 hsigTailDigits
          have hfoldLt : (intBytes ++ fracBytes).foldl digitStep 0 <
              10 ^ 19 := by
            rw [hsSig, List.foldl_append, hzero]
            exact hfoldLtTail.trans_le
              (Nat.pow_le_pow_right (by norm_num) hsigTailLen)
          have hfullBound : (intBytes ++ fracBytes).foldl digitStep 0 <=
              U64.max := by
            have hpowMax : 10 ^ 19 <= U64.max := by
              norm_num [U64.max_eq]
            exact (Nat.le_of_lt hfoldLt).trans hpowMax
          obtain ⟨hmantissa, hmantissa1⟩ := hexactScans hfullBound
          subst d
          left
          refine ⟨rfl, ?_⟩
          norm_num
          rw [hmantissa1, hsigFoldEq, hfracExponentTarget,
            List.foldl_append]
          simp [natStep]
    | some e =>
      let upper : Bool := e.1
      let expSign : Option Bool := e.2.1
      let expDigits : List Nat := e.2.2
      change expDigits ≠ [] /\
        (forall digit, List.Mem digit expDigits -> digit < 10) at hexpo
      rcases hexpo with ⟨hexpNe, hexpDigits⟩
      simp [upper, expSign, expDigits] at hbytes
      obtain ⟨intBytes, afterInt, hsval, hintMap, hafterMap⟩ :=
        List.map_eq_append_iff.mp hbytes
      obtain ⟨point, afterPoint, hafterVal, hpointVal, hafterPointMap⟩ :=
        List.map_eq_cons_iff.mp hafterMap
      have hpoint : point = 46#u8 := by
        apply UScalar.eq_of_val_eq
        simpa using hpointVal
      subst point
      obtain ⟨fracBytes, afterFrac, hafterPointVal, hfracMap,
          hafterFracMap⟩ := List.map_eq_append_iff.mp hafterPointMap
      obtain ⟨marker, suffixBytes, hafterFracVal, hmarkerVal, hsuffixMap⟩ :=
        List.map_eq_cons_iff.mp hafterFracMap
      have hmarker : marker = if upper then 69#u8 else 101#u8 := by
        by_cases hu : upper = true
        · rw [if_pos hu]
          apply UScalar.eq_of_val_eq
          simpa [hu, upper] using hmarkerVal
        · rw [if_neg hu]
          apply UScalar.eq_of_val_eq
          simpa [hu, upper] using hmarkerVal
      subst marker
      have hsdecomp : s.val = intBytes ++ 46#u8 ::
          (fracBytes ++ (if upper then 69#u8 else 101#u8) :: suffixBytes) := by
        rw [hsval, hafterVal, hafterPointVal, hafterFracVal]
      have hintDigits := byte_digits intBytes ints hintMap hints
      have hfracDigits := byte_digits fracBytes fracs hfracMap hfrac
      have hmarkerTailProp :
          ((if upper then 69#u8 else 101#u8) :: suffixBytes).length <=
            Usize.max := by
        have hp := s.property
        rw [hsdecomp] at hp
        simp only [List.length_append, List.length_cons] at hp ⊢
        omega
      let markerTail : Slice Std.U8 :=
        ⟨(if upper then 69#u8 else 101#u8) :: suffixBytes,
          hmarkerTailProp⟩
      have hmarkerTailNotDigit : forall b rest,
          markerTail.val = b :: rest ->
          Not (48 <= b.val /\ b.val <= 57) := by
        intro b rest hb
        simp [markerTail] at hb
        rcases hb with ⟨rfl, _⟩
        by_cases hu : upper = true
        · simp [hu]
        · have hu' : upper = false := Bool.eq_false_of_not_eq_true hu
          simp [hu']
      have hintTailProp :
          (46#u8 :: (fracBytes ++ markerTail.val)).length <= Usize.max := by
        have hp := s.property
        rw [hsdecomp] at hp
        simp [markerTail] at hp ⊢
        omega
      let intTail : Slice Std.U8 :=
        ⟨46#u8 :: (fracBytes ++ markerTail.val), hintTailProp⟩
      have hstart : s.val = intBytes ++ 46#u8 ::
          (fracBytes ++ markerTail.val) := by
        simpa [markerTail] using hsdecomp
      have hintTailNotDigit : forall b rest, intTail.val = b :: rest ->
          Not (48 <= b.val /\ b.val <= 57) := by
        intro b rest hb
        simp [intTail] at hb
        rcases hb with ⟨rfl, _⟩
        norm_num
      obtain ⟨mantissa, intRest, hscanInt, hintRest⟩ :=
        NumberHelperDigitScanSourceLength s 0#u64 intBytes intTail.val
          hstart hintDigits hintTailNotDigit hlen
      have hintRestEq : intRest = intTail :=
        (Slice.eq_iff _ _).2 (by simpa using hintRest)
      subst intRest
      obtain ⟨nDigits, hoffInt, hnDigitsVal⟩ :=
        NumberHelperOffsetSourceLength s intTail hlen (by
          rw [hstart]
          simp [intTail])
      have hnDigitsEq : nDigits.val = intBytes.length := by
        rw [hnDigitsVal, hstart]
        simp [intTail]
      have hfracSliceProp : (fracBytes ++ markerTail.val).length <=
          Usize.max := by
        have hp := intTail.property
        simp [intTail] at hp ⊢
        omega
      let fracSlice : Slice Std.U8 :=
        ⟨fracBytes ++ markerTail.val, hfracSliceProp⟩
      have hsplitPoint : core.slice.Slice.split_first intTail =
          ok (some (46#u8, fracSlice)) := by
        simp [core.slice.Slice.split_first, ModelSliceSplitFirst,
          intTail, fracSlice]
      obtain ⟨mantissa1, fracRest, hscanFrac, hfracRest⟩ :=
        NumberHelperDigitScanSourceLength fracSlice mantissa fracBytes
          markerTail.val (by simp [fracSlice]) hfracDigits
            hmarkerTailNotDigit (by
              simp [fracSlice]
              rw [hstart] at hlen
              simp only [List.length_append, List.length_cons] at hlen
              omega)
      have hfracRestEq : fracRest = markerTail :=
        (Slice.eq_iff _ _).2 (by simpa using hfracRest)
      subst fracRest
      obtain ⟨nAfter, hoffFrac, hnAfterVal⟩ :=
        NumberHelperOffsetSourceLength fracSlice markerTail (by
          simp [fracSlice]
          rw [hstart] at hlen
          simp only [List.length_append, List.length_cons] at hlen
          omega) (by simp [fracSlice])
      have hnAfterEq : nAfter.val = fracBytes.length := by
        rw [hnAfterVal]
        simp [fracSlice]
      have hnAfterNotMin : nAfter.val ≠ IScalar.min .Isize := by
        rw [hnAfterEq, IScalar.min]
        simp [IScalarTy.numBits, Dec2Flt.configured_x86_64_numBits]
      obtain ⟨negAfter, hnegAfter, hnegAfterVal⟩ :=
        Aeneas.Std.WP.spec_imp_exists (HNeg.hNeg.step nAfter hnAfterNotMin)
      have hnegCastBounds : IScalar.min .I64 <= negAfter.val /\
          negAfter.val <= IScalar.max .I64 := by
        have hp := hlen
        rw [hstart] at hp
        simp only [List.length_append, List.length_cons] at hp
        rw [hnegAfterVal, hnAfterEq,
          IScalar.min_IScalarTy_I64_eq, I64.min_eq,
          IScalar.max_IScalarTy_I64_eq, I64.max_eq]
        constructor <;> omega
      obtain ⟨fracExponent, hfracExponent, hfracExponentVal⟩ :=
        Aeneas.Std.WP.spec_imp_exists
          (IScalar.cast_inBounds_spec .I64 negAfter hnegCastBounds)
      have hfracExponentEq : fracExponent.val = -(fracBytes.length : Int) := by
        rw [hfracExponentVal, hnegAfterVal, hnAfterEq]
      have htotalBounds : IScalar.min .Isize <= nDigits.val + nAfter.val /\
          nDigits.val + nAfter.val <= IScalar.max .Isize := by
        rw [hnDigitsEq, hnAfterEq]
        simp [IScalar.min, IScalar.max, IScalarTy.numBits,
          Dec2Flt.configured_x86_64_numBits]
        rw [hstart] at hlen
        simp only [List.length_append, List.length_cons] at hlen
        constructor <;> omega
      obtain ⟨totalDigits, htotal, htotalVal⟩ :=
        Aeneas.Std.WP.spec_imp_exists
          (IScalar.add_spec htotalBounds.1 htotalBounds.2)
      have hintLen : intBytes.length = ints.length := by
        have hp := congrArg List.length hintMap
        simpa using hp
      have hfracLen : fracBytes.length = fracs.length := by
        have hp := congrArg List.length hfracMap
        simpa using hp
      have htotalPos : 0 < totalDigits.val := by
        rw [htotalVal, hnDigitsEq, hnAfterEq]
        rcases hsome with hneInt | hneFrac
        · have hp := List.length_pos_of_ne_nil hneInt
          omega
        · have hp := List.length_pos_of_ne_nil hneFrac
          omega
      have hsuffixProp : suffixBytes.length <= Usize.max := by
        have hp := markerTail.property
        simp [markerTail] at hp
        omega
      let suffix : Slice Std.U8 := ⟨suffixBytes, hsuffixProp⟩
      have hsplitMarker : core.slice.Slice.split_first markerTail =
          ok (some (if upper then 69#u8 else 101#u8, suffix)) := by
        simp [core.slice.Slice.split_first, ModelSliceSplitFirst,
          markerTail, suffix]
      obtain ⟨expBytes, hsuffixDecomp, hexpMap⟩ :=
        NumberHelperSplitExponentSuffix expSign suffixBytes expDigits hsuffixMap
      have hexpByteDigits := byte_digits expBytes expDigits hexpMap hexpDigits
      have hexpDigitMap : expBytes.map (fun b : Std.U8 => b.val - 48) =
          expDigits := unrender_digits expBytes expDigits hexpMap hexpDigits
      have hexpByteNeProp : expBytes ≠ [] := by
        intro hempty
        rw [hempty] at hexpDigitMap
        simp at hexpDigitMap
        exact hexpNe hexpDigitMap
      have hexpByteNe : expBytes != [] := by
        simpa only [bne_iff_ne] using hexpByteNeProp
      have hsignByteMap :
          (match expSign with
          | none => ([] : List Std.U8)
          | some negative => [if negative then 45#u8 else 43#u8]).map
              (fun b : Std.U8 => b.val) =
            (match expSign with
            | none => []
            | some negative => [if negative then 45 else 43]) := by
        cases expSign with
        | none => rfl
        | some negative => cases negative <;> rfl
      have hsuffixDecomp' : suffix.val =
          (match expSign with
          | none => []
          | some negative => [if negative then 45#u8 else 43#u8]) ++
            expBytes := by
        change suffixBytes = _
        apply u8_list_eq_of_val_map
        dsimp [expSign, expDigits] at hsignByteMap ⊢
        rw [hsuffixMap, List.map_append, hsignByteMap, hexpMap]
        rfl
      obtain ⟨parsedExp, scientificRest, hscientific, hscientificRest,
          hparsedExp⟩ := NumberHelperScientificExact suffix expSign expBytes
        hexpByteNe hexpByteDigits hsuffixDecomp'
      have hparsedExpValue : parsedExp.val =
          if expSign = some true then
            -((expDigits.foldl
              (fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int)
          else ((expDigits.foldl
            (fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int) := by
        rw [hparsedExp, guarded_fold_map, hexpDigitMap]
      have hparsedExpTarget : parsedExp.val =
          (match expSign with
          | some true => -((expDigits.foldl
              (fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int)
          | _ => ((expDigits.foldl
              (fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int)) := by
        rw [hparsedExpValue]
        exact signed_if_eq_match expSign _
      obtain ⟨fullOffset, hoffFull, hfullOffsetVal⟩ :=
        NumberHelperOffsetSourceLength s scientificRest hlen (by
          simp [hscientificRest])
      have hfullCast : lift (IScalar.hcast .Usize fullOffset) =
          ok (Slice.len s) := by
        have hbound : 0 <= fullOffset.val /\
            fullOffset.val <= UScalar.max .Usize := by
          rw [hfullOffsetVal, hscientificRest]
          simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
          omega
        obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
          (IScalar.hcast_inBounds_spec .Usize fullOffset hbound)
        rw [hz]
        congr 2
        apply UScalar.eq_of_val_eq
        rw [hfullOffsetVal, hscientificRest] at hzval
        simpa [Slice.len_val] using hzval
      have hnotempty : Not (s.val = []) := by simpa using hne
      unfold num.imp.dec2flt.parse.parse_number at hparse
      simp [hnotempty] at hparse
      unfold num.imp.dec2flt.parse.parse_partial_number at hparse
      simp [hnotempty, hscanInt, hoffInt, hsplitPoint, hscanFrac,
        hoffFrac, hnegAfter, hfracExponent] at hparse
      norm_num at hparse
      simp only [UScalar.ofNat, UScalar.ofNatCore] at hparse
      cases hupper : upper <;>
        simp [hupper, htotal, htotalPos, hsplitMarker, hscientific,
          hoffFull, hfullCast, UScalar.ofNatCore,
          core.option.Option.Insts.CoreOpsTry_traitTry.branch,
          ModelOptionBranch, ModelOptionFromResidual] at hparse
      all_goals
        cases hsum : fracExponent + parsedExp with
        | fail err => simp [hsum] at hparse
        | div => simp [hsum] at hparse
        | ok combinedExponent =>
          simp [hsum] at hparse
          have hcombinedVal : combinedExponent.val =
              fracExponent.val + parsedExp.val := by
            have h := IScalar.add_equiv fracExponent parsedExp
            rw [hsum] at h
            exact h.2.1
          have hdigitInt : intBytes.map (fun b : Std.U8 => b.val - 48) =
              ints := unrender_digits intBytes ints hintMap hints
          have hdigitFrac : fracBytes.map (fun b : Std.U8 => b.val - 48) =
              fracs := unrender_digits fracBytes fracs hfracMap hfrac
          have hsigMap : (intBytes ++ fracBytes).map
              (fun b : Std.U8 => b.val - 48) = ints ++ fracs := by
            simp [hdigitInt, hdigitFrac]
          have hsigDigits : forall b, List.Mem b (intBytes ++ fracBytes) ->
              48 <= b.val /\ b.val <= 57 := by
            intro b hb
            rcases List.mem_append.mp hb with hb | hb
            · exact hintDigits b hb
            · exact hfracDigits b hb
          have hsigFoldEq : (intBytes ++ fracBytes).foldl digitStep 0 =
              (ints ++ fracs).foldl natStep 0 := by
            rw [fold_map, hsigMap]
          have hcombinedExponentTarget : combinedExponent.val =
              parsedExp.val - (fracs.length : Int) := by
            rw [hcombinedVal, hfracExponentEq, hfracLen]
            omega
          have hexactScans : (intBytes ++ fracBytes).foldl digitStep 0 <=
              U64.max ->
              mantissa.val = intBytes.foldl digitStep 0 /\
              mantissa1.val = (intBytes ++ fracBytes).foldl digitStep 0 := by
            as_aux_lemma =>
            intro hfullBound
            have hprefixLe : intBytes.foldl digitStep 0 <=
                (intBytes ++ fracBytes).foldl digitStep 0 := by
              rw [List.foldl_append]
              exact fold_ge_start fracBytes _
            have hintBound : intBytes.foldl digitStep 0 <= U64.max :=
              hprefixLe.trans hfullBound
            obtain ⟨exactInt, exactIntRest, hexactInt, hexactIntRest,
                hexactIntValue⟩ := NumberHelperDigitScanExact s 0#u64 intBytes
              intTail.val hstart hintDigits hintTailNotDigit hlen
                (by simpa [digitStep] using hintBound)
            have hmantissa : mantissa.val =
                intBytes.foldl digitStep 0 := by
              rw [hscanInt] at hexactInt
              simp at hexactInt
              rcases hexactInt with ⟨rfl, rfl⟩
              simpa [digitStep] using hexactIntValue
            have hfracBound : fracBytes.foldl digitStep mantissa.val <=
                U64.max := by
              rw [hmantissa, ← List.foldl_append]
              exact hfullBound
            obtain ⟨exactFrac, exactFracRest, hexactFrac, hexactFracRest,
                hexactFracValue⟩ := NumberHelperDigitScanExact fracSlice
              mantissa fracBytes markerTail.val (by simp [fracSlice])
                hfracDigits hmarkerTailNotDigit (by
                  simp [fracSlice]
                  rw [hstart] at hlen
                  simp only [List.length_append, List.length_cons] at hlen
                  omega) (by simpa [digitStep] using hfracBound)
            have hmantissa1 : mantissa1.val =
                (intBytes ++ fracBytes).foldl digitStep 0 := by
              rw [hscanFrac] at hexactFrac
              simp at hexactFrac
              rcases hexactFrac with ⟨rfl, rfl⟩
              rw [List.foldl_append, ← hmantissa]
              simpa [digitStep] using hexactFracValue
            exact ⟨hmantissa, hmantissa1⟩
          by_cases hsmall : totalDigits.val <= 19
          · simp [hsmall] at hparse
            have hsigLen : (intBytes ++ fracBytes).length <= 19 := by
              rw [List.length_append]
              omega
            have hfoldLt : (intBytes ++ fracBytes).foldl digitStep 0 <
                10 ^ (intBytes ++ fracBytes).length := by
              simpa using fold_upper (intBytes ++ fracBytes) 0 hsigDigits
            have hfullBound : (intBytes ++ fracBytes).foldl digitStep 0 <=
                U64.max := by
              have hp := hfoldLt.trans_le
                (Nat.pow_le_pow_right (by norm_num) hsigLen)
              have hpowMax : 10 ^ 19 <= U64.max := by
                norm_num [U64.max_eq]
              exact (Nat.le_of_lt hp).trans hpowMax
            obtain ⟨hmantissa, hmantissa1⟩ := hexactScans hfullBound
            subst d
            left
            refine ⟨rfl, ?_⟩
            norm_num
            rw [hmantissa1, hsigFoldEq, hcombinedExponentTarget,
              List.foldl_append]
            simp [natStep, hparsedExpTarget, expSign, expDigits]
            all_goals exact Or.inl rfl
          · have hlarge : 19 < totalDigits.val := by omega
            have hsubBounds : IScalar.min .Isize <= totalDigits.val - 19 /\
                totalDigits.val - 19 <= IScalar.max .Isize := by
              have hb := IScalar.hBounds totalDigits
              simp [IScalar.min, IScalar.max, IScalarTy.numBits,
                Dec2Flt.configured_x86_64_numBits] at hb ⊢
              omega
            obtain ⟨nMore, hnMore, hnMoreVal⟩ := Aeneas.Std.WP.spec_imp_exists
              (IScalar.sub_spec (x := totalDigits) (y := 19#isize)
                (by norm_num; omega) (by norm_num; omega))
            norm_num at hnMoreVal
            simp [hsmall, hnMore] at hparse
            obtain ⟨rawZeros, rawTail, sigZeros, sigTail, hsRaw,
                hrawZeros, hrawTail, hsSig, hsigZeros, hsigTailSharp,
                hcount⟩ := split_significand_zeros intBytes fracBytes
              markerTail.val hintDigits hfracDigits (by
                right
                refine ⟨if upper then 69#u8 else 101#u8, suffixBytes,
                  by simp [markerTail], ?_, ?_⟩
                · simp [hupper]
                · simp [hupper])
            have hsAdjust : s.val = rawZeros ++ rawTail := by
              rw [hstart]
              simpa using hsRaw
            have hsigLenEq : intBytes.length + fracBytes.length =
                sigZeros.length + sigTail.length := by
              have hp := congrArg List.length hsSig
              simpa using hp
            have hnMoreNonneg : 0 <= nMore.val := by
              rw [hnMoreVal]
              omega
            have hnMoreLe : nMore.val <= s.val.length := by
              rw [hnMoreVal, htotalVal, hnDigitsEq, hnAfterEq, hstart]
              simp only [List.length_append, List.length_cons]
              omega
            have hadjustLower : IScalar.min .Isize <=
                nMore.val - (rawZeros.count 48#u8 : Int) := by
              rw [hnMoreVal, hcount, htotalVal, hnDigitsEq, hnAfterEq]
              have hzlen : sigZeros.length <=
                  (intBytes ++ fracBytes).length := by
                rw [hsSig]
                simp
              simp [IScalar.min, IScalarTy.numBits,
                Dec2Flt.configured_x86_64_numBits]
              omega
            obtain ⟨adjusted, hadjust, hadjustVal⟩ :=
              NumberHelperAdjustManyExact s nMore rawZeros rawTail hsAdjust
                hrawZeros hrawTail hlen hnMoreNonneg hnMoreLe hadjustLower
            rw [hadjust] at hparse
            by_cases hpositive : 0 < adjusted.val
            · simp [hpositive] at hparse
              cases hmany : num.imp.dec2flt.parse.parse_many_digits s intTail
                  parsedExp with
              | fail err => simp [hmany] at hparse
              | div => simp [hmany] at hparse
              | ok result =>
                rcases result with ⟨manyMantissa, manyExponent⟩
                simp [hmany] at hparse
                have hsigTailLen : 19 < sigTail.length := by
                  rw [hadjustVal, hnMoreVal, hcount, htotalVal, hnDigitsEq,
                    hnAfterEq] at hpositive
                  omega
                have hsigTailCons : exists first tailRest,
                    sigTail = first :: tailRest /\ first ≠ 48#u8 := by
                  rcases hsigTailSharp with hnil | hcons
                  · rw [hnil] at hsigTailLen
                    simp at hsigTailLen
                  · exact hcons
                rcases hsigTailCons with
                  ⟨first, tailRest, htailEq, hfirstNe⟩
                have hfirstDigit := hsigDigits first (by
                  rw [hsSig, htailEq]
                  exact List.mem_append_right sigZeros List.mem_cons_self)
                have hthreshold : 1000000000000000000 <=
                    (intBytes ++ fracBytes).foldl digitStep 0 := by
                  have hzero := zero_fold sigZeros hsigZeros
                  have hlower := fold_lower tailRest (first.val - 48)
                  rw [hsSig, List.foldl_append, hzero, htailEq,
                    List.foldl_cons]
                  change 1000000000000000000 <=
                    tailRest.foldl digitStep (digitStep 0 first)
                  have hfirstPos : 1 <= first.val - 48 := by
                    have hneVal : first.val ≠ 48 := by
                      intro h
                      apply hfirstNe
                      apply UScalar.eq_of_val_eq
                      simpa using h
                    omega
                  have hpowLower : 1000000000000000000 <=
                      10 ^ tailRest.length := by
                    have hlenRest : 18 <= tailRest.length := by
                      rw [htailEq] at hsigTailLen
                      simp only [List.length_cons] at hsigTailLen
                      omega
                    have hp := Nat.pow_le_pow_right
                      (by norm_num : 0 < 10) hlenRest
                    norm_num at hp ⊢
                    exact hp
                  have hstep : 10 ^ tailRest.length <=
                      (first.val - 48) * 10 ^ tailRest.length := by
                    simpa using Nat.mul_le_mul_right (10 ^ tailRest.length)
                      hfirstPos
                  exact hpowLower.trans (hstep.trans (by
                    simpa [digitStep] using hlower))
                obtain ⟨consumed, remaining, hpartition, hmanyMantissa,
                    hmanyExponent⟩ := NumberHelperFractionalManyExact s
                  intTail parsedExp manyExponent manyMantissa intBytes
                    fracBytes markerTail.val hstart (by simp [intTail])
                    hintDigits hfracDigits hmarkerTailNotDigit hlen
                    hthreshold hmany
                have hmanyExponentTarget : manyExponent.val =
                    parsedExp.val - (fracs.length : Int) +
                      remaining.length := by
                  rw [hmanyExponent, hfracLen]
                subst d
                have hresult := finish_value
                  (num.imp.dec2flt.decimal.Decimal.mk manyExponent
                    manyMantissa false true)
                  (intBytes ++ fracBytes) (ints ++ fracs)
                  (parsedExp.val - (fracs.length : Int)) hsigMap (by
                    intro digit hdigit
                    rcases List.mem_append.mp hdigit with hdigit | hdigit
                    · exact hints digit hdigit
                    · exact hfrac digit hdigit)
                  (Or.inr ⟨rfl, consumed, remaining, hpartition,
                    hmanyMantissa, hmanyExponentTarget⟩)
                simpa [DecimalGoalVocabularyDefault, natStep,
                  List.foldl_append, hparsedExpTarget, expSign, expDigits]
                    using hresult
            · simp [hpositive] at hparse
              have hsigTailLen : sigTail.length <= 19 := by
                rw [hadjustVal, hnMoreVal, hcount, htotalVal, hnDigitsEq,
                  hnAfterEq] at hpositive
                omega
              have hsigTailDigits : forall b, List.Mem b sigTail ->
                  48 <= b.val /\ b.val <= 57 := by
                intro b hb
                apply hsigDigits b
                rw [hsSig]
                exact List.mem_append_right sigZeros hb
              have hzero := zero_fold sigZeros hsigZeros
              have hfoldLtTail : sigTail.foldl digitStep 0 <
                  10 ^ sigTail.length := by
                simpa using fold_upper sigTail 0 hsigTailDigits
              have hfoldLt : (intBytes ++ fracBytes).foldl digitStep 0 <
                  10 ^ 19 := by
                rw [hsSig, List.foldl_append, hzero]
                exact hfoldLtTail.trans_le
                  (Nat.pow_le_pow_right (by norm_num) hsigTailLen)
              have hfullBound :
                  (intBytes ++ fracBytes).foldl digitStep 0 <= U64.max := by
                have hpowMax : 10 ^ 19 <= U64.max := by
                  norm_num [U64.max_eq]
                exact (Nat.le_of_lt hfoldLt).trans hpowMax
              obtain ⟨hmantissa, hmantissa1⟩ := hexactScans hfullBound
              subst d
              left
              refine ⟨rfl, ?_⟩
              norm_num
              rw [hmantissa1, hsigFoldEq, hcombinedExponentTarget,
                List.foldl_append]
              simp [natStep, hparsedExpTarget, expSign, expDigits]
              all_goals exact Or.inl rfl

end dec2flt_model

Proof structure

Follow the declared dependencies to read the supporting statements and proofs.

Explore this dependency tree

Inspect related source (71)
More program dependencies (36)
Standard-library dependencies (32)

Related source and models come from the extraction records and declared dependencies.

Proof assumptions and review

Lean checks the formal proof. Trellis also reviews how the statement corresponds to the intended requirement.

Transitive assumptions

This list combines the assumptions recorded for this declaration and its dependencies. It may include assumptions used by auxiliary declarations in those modules.

Helper theorems included
All 65 entries
Technical checking records
Local closure summary
{
  "node": "NumberHelperAccumulatedValue",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "0d058b5420bf1d17e8ba8efb8581bab09071e82838e6357a36002016ae6ed899",
  "active_statement_hash": "28314528aea932a6d5b9409aa3d7e4af58d4aee38e436cc9622e1be0d889d9f0",
  "kernel_axioms": [
    "Classical.choice",
    "Dec2Flt.configured_x86_64_numBits",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "ab64d13f256386ee0e494a5abcc6a5db49512cf3d90bbdfcabd6327793a31f95",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-139",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DecimalGoalVocabularyDefault": "94cb4c406f8efb78",
    "ModelSliceSplitFirst": "f617ee05dd2925a9",
    "NumberHelperAdjustManyExact": "8999fa99d4681219",
    "NumberHelperDecimalPrefixInterval": "5c32858414034b55",
    "NumberHelperDigitScanExact": "6bcf20c61d10dea3",
    "NumberHelperDigitScanSourceLength": "8892b939bba0ecf9",
    "NumberHelperFractionalManyExact": "4f108f0f2477fa14",
    "NumberHelperIntegralManyExact": "4b76d387097e136b",
    "NumberHelperOffsetSourceLength": "de0168dfeba3b802",
    "NumberHelperScientificExact": "85d7c23c40290390",
    "NumberHelperSplitExponentSuffix": "36f92cf2e9d9f766",
    "num_imp_dec2flt_parse_parse_partial_number": "854af4cc12136a58"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "0717fd246d7ea78a",
    "DecimalGoalVocabularyDefault": "512f8d0aea894250",
    "DecimalLexeme": "303e59678842cea4",
    "F64": "ec4e25fbaf4e11d4",
    "ModelOptionBranch": "c55e273482c8c0a1",
    "ModelOptionFromResidual": "6d48ecfbc617744f",
    "NumberHelperSplitExponentSuffix": "3a789d080d66f335",
    "Preamble": "7754ffaf671693bf",
    "SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from": "7e7284dc9bc88830",
    "SourceValidByteSlice": "3dc42716a6378d26",
    "num_imp_dec2flt_common_BiasedFp": "31d81cf1cf22709f",
    "num_imp_dec2flt_decimal_Decimal": "c43614ff2149ecf2",
    "num_imp_dec2flt_parse_adjust_many_digit_count": "4e59e3776b6cfdaa",
    "num_imp_dec2flt_parse_parse_many_digits": "50c9ef13b3ed7fe8",
    "num_imp_dec2flt_parse_parse_number": "f73f8bc11faa6db3",
    "num_imp_dec2flt_parse_parse_partial_number": "5712e484f99eb7aa",
    "num_imp_dec2flt_parse_parse_scientific": "447f722d5841d2c5",
    "num_imp_dec2flt_parse_try_parse_digits": "238b4a73cd46fc56"
  }
}
Prose assessment
{
  "label": "Recorded Sound: VerifierPass",
  "assessment_status": "VerifierPass",
  "fingerprint_relation": "matches current fingerprint",
  "assessment_fingerprint": "sound-v2:25911d09519d5e4a5c06d02dda402a63783a5a7c12af3dc02e5856891ff73e3b",
  "current_fingerprint": "sound-v2:25911d09519d5e4a5c06d02dda402a63783a5a7c12af3dc02e5856891ff73e3b",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}