ParserNumberScanAccounting

Lean checked

Statement

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

Lemma · Branch-complete number-scan accounting

Let a nonempty source-valid byte slice s render a valid unsigned numeric lexeme x, and suppose parse_number(s) returns a record r. Concatenate the integer and fractional digit lists to obtain S, delete the maximal leading zero run to obtain S^+, and put
z=|S|-|S^+|,\qquad P=|x.\mathit{integerDigits}|-z, \qquad h=\min(|S^+|,19),
where the subtraction defining P is in the integers. Let E be the accumulated signed scientific exponent of x. Then
r.\mathit{exponent}=P-h+E,\qquad 0\le h\le19,\qquad -655359\le E\le655359.
In addition, if the returned record has many_digits=true, its mantissa is strictly positive. The definitions and equalities are exactly the nested lets and conjunctions in Lean.

Lean statement

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

import Tablet.DecimalGoalVocabularyDefault
import Tablet.NumberHelperAccumulatedValue
import Tablet.NumberHelperAdjustManyExact
import Tablet.NumberHelperDigitScanExact
import Tablet.NumberHelperFractionalManyExact
import Tablet.NumberHelperIntegralManyExact
import Tablet.NumberHelperManyRetryAccounting
import Tablet.NumberHelperScientificExact
import Tablet.SourceValidByteSlice
import Tablet.num_imp_dec2flt_decimal_Decimal
import Tablet.num_imp_dec2flt_parse_parse_number
import Tablet.num_imp_dec2flt_parse_parse_partial_number
import Tablet.num_imp_dec2flt_parse_parse_many_digits
import Tablet.num_imp_dec2flt_parse_parse_scientific
import Tablet.num_imp_dec2flt_parse_adjust_many_digit_count

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 400000

namespace dec2flt_model

-- [TABLET NODE: ParserNumberScanAccounting]
theorem ParserNumberScanAccounting :
    forall (s : Slice Std.U8) (x : DecimalLexeme)
      (r : num.imp.dec2flt.decimal.Decimal),
      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 r) ->
      let significand := x.integerDigits ++
        match x.fractionDigits with | none => [] | some ds => ds
      let significant := significand.dropWhile (fun d => d == 0)
      let leadingZeros := significand.length - significant.length
      let P : Int := (x.integerDigits.length : Int) - leadingZeros
      let h : Int := (min significant.length 19 : Nat)
      let E : Int :=
        DecimalGoalVocabularyDefault.accumulatedExplicitExponent x
      r.exponent.val = P - h + E /\
        0 <= h /\ h <= 19 /\ -655359 <= E /\ E <= 655359 /\
        (r.many_digits = true -> 0 < r.mantissa.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.

Earlier prose review

An earlier review questioned the prose argument. Lean subsequently checked the formal proof. Review of the statement’s intended meaning is a separate judgment.

Proof

Write I and F for the integer and fractional digit lists, taking F=[] when the fractional field is absent. Validity in DecimalGoalVocabularyDefault says every member of I,F is below ten, at least one of them is nonempty, and any scientific-exponent digit list is nonempty and decimal. The render equality therefore decomposes the slice into the ASCII bytes for I, an optional point followed by the bytes for F, and an optional exponent marker, sign, and exponent digits. The unsigned-sign hypothesis excludes a leading sign byte.
Put D=|I|+|F|=|S|. Apply NumberHelperDigitScanSourceLength to the integral digit-byte run. Its stopping-tail clause says that the returned slice is exactly the suffix beginning at the point, exponent marker, or end of input; no claim about the wrapping accumulator is needed. If the point is present, apply the same lemma to the fractional run to obtain exactly the suffix beginning at the exponent marker or end. The point and exponent marker are nondigits, so the lemma's stopping hypotheses hold. By NumberHelperOffsetSourceLength, the corresponding extracted offsets have values |I| and |F|. The source-validity bound SourceValidByteSlice gives every required slice length at most 2^{63}-1, so these offsets and their casts are represented. Unfolding the ordinary branches of num imp dec2flt parse parse partial number now shows that the pre-scientific record exponent is 0 when F=[] and -|F| when a fraction is present: the latter is the checked negation of the nonnegative offset, followed by its exact cast to I64. Thus in both layouts that exponent is -|F|.
We next audit the many-digit decision. The extracted initial digit count is D. The branch D\le19 goes directly to the ordinary record, and already implies |S^+|\le19. Suppose therefore that D>19. Before calling the adjustment, the extracted subtraction produces n=D-19\ge0. In the rendered byte layout, let Q be the maximal prefix consisting only of zero bytes 48 and the optional point byte 46, and let T be the remaining tail. Maximality gives exactly the stopping alternative required by NumberHelperAdjustManyExact: T=[], or its first byte is neither 48 nor 46. The zero bytes in Q are precisely the z leading zeros of S, even when the run crosses the point, hence \operatorname{count}(Q,48)=z. Also 0\le n\le |s|. Finally
n-z\ge-z\ge-D\ge-|s|\ge-(2^{63}-1)>-2^{63},
which supplies the helper's Isize lower-bound premise. Its remaining length, initial-count, and upper-bound premises follow respectively from source validity, n\ge0, and n\le|s|. Therefore NumberHelperAdjustManyExact returns the exact corrected count
a=n-z=D-z-19=|S^+|-19. \tag{1}
Consequently the extracted positive test chooses the retry exactly when |S^+|>19; otherwise it chooses the ordinary record and |S^+|\le19.
Consider first an ordinary record. If S^+\ne[], its length is at most 19, so h=|S^+|. Since deletion of the maximal zero prefix gives
h=|S^+|=D-z=|I|+|F|-z,
the definition P=|I|-z yields the required, correctly oriented equality
P-h=(|I|-z)-(|I|+|F|-z)=-|F|. \tag{2}
This is exactly the ordinary pre-scientific exponent above. If every significand digit is zero, then instead S^+=[], h=0, and z=D=|I|+|F|; hence P=|I|-z=-|F| and again P-h=-|F|. This explicitly covers the all-zero integral, fractional, and point-crossing layouts without using a nonempty-tail argument.
Now suppose the retry is selected, so (1) gives |S^+|>19 and h=19. Apply NumberHelperManyRetryAccounting with the exact integral and fractional suffixes established above, the maximal decomposition S=ZS^+, and the successful extracted retry. Its two layout clauses state uniformly that the retry consumes exactly the first nineteen post-zero digit positions, even when they cross the optional point, and that the returned mantissa m and pre-scientific exponent q satisfy
10^{18}\le m<10^{19},\qquad q=e+|I|-z-19=e+P-h, \tag{3}
where e is the exponent passed to the retry. Thus this branch supplies both the exact exponent accounting and m>0, the latter proving the final mantissa implication whenever many_digits=true.
It remains to identify e and the final scientific addition. If there is no exponent suffix, the extracted branches pass e=0 to the retry and make no addition to an ordinary record; put E=0. Then (2) and (3) respectively give r.\mathit{exponent}=P-h+E, and the requested bounds on E are immediate.
If an exponent suffix is present, apply NumberHelperScientificExact. Its exact result is the signed fold specified in the statement, so it is precisely E. At an updating step the old accumulator satisfies a<65536, hence a\le65535, and its decimal digit r satisfies 0\le r\le9; therefore 10a+r\le10\cdot65535+9=655359. Once the accumulator is at least 65536 the fold leaves it unchanged. Induction over the nonempty exponent digit list therefore gives 0\le |E|\le655359, and the optional minus sign gives -655359\le E\le655359. In the retry branch the extracted call passes this E as the incoming e, so (3) is the conclusion directly. In the ordinary fractional branch the checked final I64 addition combines -|F| with E; in the integral branch it combines 0 with E. Case analysis on that checked operation in num imp dec2flt parse parse partial number rules out failure and divergence because the whole call is assumed to return r, and its successful case has integer value (P-h)+E by (2). Hence every present-suffix branch also has r.\mathit{exponent}=P-h+E. Finally h=\min(|S^+|,19) is a natural number between zero and 19, completing every conjunct.

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 drop_zeros : forall (all zeros tail : List Std.U8),
      (forall b, List.Mem b all -> 48 <= b.val /\ b.val <= 57) ->
      all = zeros ++ tail ->
      (forall b, List.Mem b zeros -> b = 48#u8) ->
      (tail = [] \/ exists b rest, tail = b :: rest /\ b ≠ 48#u8) ->
      List.dropWhile (fun d : Nat => d == 0)
          (all.map (fun b : Std.U8 => b.val - 48)) =
        tail.map (fun b : Std.U8 => b.val - 48) := by
    intro all zeros tail hdigits hall hzeros htail
    rw [hall, List.map_append]
    induction zeros generalizing all with
    | nil =>
      simp only [List.map_nil, List.nil_append]
      rcases htail with rfl | ⟨b, rest, rfl, hb⟩
      · rfl
      · have hbdigit := hdigits b (by
          rw [hall]
          exact List.mem_append_right [] List.mem_cons_self)
        have hbval : b.val - 48 ≠ 0 := by
          have hne : b.val ≠ 48 := by
            intro h
            apply hb
            exact UScalar.eq_of_val_eq h
          omega
        simp [hbval]
    | cons z zs ih =>
      have hz := hzeros z List.mem_cons_self
      have hzs : forall b, List.Mem b zs -> b = 48#u8 := by
        intro b hb
        exact hzeros b (List.mem_cons_of_mem z hb)
      simp only [List.map_cons]
      rw [hz]
      norm_num
      apply ih (all := zs ++ tail)
      · intro b hb
        apply hdigits b
        rw [hall]
        exact List.mem_append_right [z] hb
      · rfl
      · exact hzs
  have guarded_fold_bound : forall (ds : List Nat) (a : Nat),
      (forall d, List.Mem d ds -> d < 10) ->
      a <= 655359 ->
      ds.foldl (fun n d => if n < 65536 then 10 * n + d else n) a <=
        655359 := by
    intro ds
    induction ds with
    | nil => intro a hds ha; simpa using ha
    | cons d ds ih =>
      intro a hds ha
      have hd := hds d List.mem_cons_self
      have hrest : forall e, List.Mem e ds -> e < 10 := by
        intro e he
        exact hds e (List.mem_cons_of_mem d he)
      simp only [List.foldl_cons]
      split
      · apply ih _ hrest
        omega
      · exact ih _ hrest ha
  have explicit_bound : forall (sign : Option Bool) (ds : List Nat),
      (forall d, List.Mem d ds -> d < 10) ->
      let magnitude : Nat :=
        ds.foldl (fun (n d : Nat) =>
          if n < 65536 then 10 * n + d else n) 0
      let value : Int :=
        match sign with
        | some true => -(magnitude : Int)
        | _ => (magnitude : Int)
      (-655359 : Int) <= value /\ value <= 655359 := by
    intro sign ds hds
    have hbound := guarded_fold_bound ds 0 hds (by omega)
    cases sign with
    | none => simp; omega
    | some negative => cases negative <;> simp <;> omega
  have finish_accounting : forall
      (record : num.imp.dec2flt.decimal.Decimal)
      (bytes : List Std.U8) (digits : List Nat)
      (zeros significant : List Std.U8) (integerLength : Nat) (E : Int),
      (forall b, List.Mem b bytes -> 48 <= b.val /\ b.val <= 57) ->
      bytes.map (fun b : Std.U8 => b.val - 48) = digits ->
      bytes = zeros ++ significant ->
      (forall b, List.Mem b zeros -> b = 48#u8) ->
      (significant = [] \/ exists b rest,
        significant = b :: rest /\ b ≠ 48#u8) ->
      -655359 <= E -> E <= 655359 ->
      ((record.many_digits = false /\ significant.length <= 19 /\
          record.exponent.val =
            (integerLength : Int) - zeros.length - significant.length + E) \/
        (record.many_digits = true /\ 19 < significant.length /\
          record.exponent.val =
            (integerLength : Int) - zeros.length - 19 + E /\
          0 < record.mantissa.val)) ->
      record.exponent.val =
          (integerLength : Int) -
            ((digits.length -
              (List.dropWhile (fun d : Nat => d == 0) digits).length : Nat) :
                Int) -
            ((min (List.dropWhile (fun d : Nat => d == 0) digits).length 19 :
                Nat) : Int) + E /\
        -655359 <= E /\ E <= 655359 /\
        (record.many_digits = true -> 0 < record.mantissa.val) := by
    intro record bytes digits zeros significant integerLength E hdigits
      hmap hsplit hzeros hsignificant hElower hEupper hbranch
    have hdrop := drop_zeros bytes zeros significant hdigits hsplit hzeros
      hsignificant
    rw [hmap] at hdrop
    have hlength := congrArg List.length hsplit
    have hmapLength := congrArg List.length hmap
    simp only [List.length_append, List.length_map] at hlength hmapLength
    rcases hbranch with ⟨hmany, hsiglen, hexponent⟩ |
        ⟨hmany, hsiglen, hexponent, hpositive⟩
    · have hmin : min significant.length 19 = significant.length :=
        Nat.min_eq_left hsiglen
      constructor
      · rw [hexponent, hdrop, List.length_map, hmin]
        omega
      · exact ⟨hElower, hEupper, by simp [hmany]⟩
    · have hmin : min significant.length 19 = 19 :=
        Nat.min_eq_right (by omega)
      constructor
      · rw [hexponent, hdrop, List.length_map, hmin]
        omega
      · refine ⟨hElower, hEupper, ?_⟩
        intro htrue
        exact hpositive
  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
        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
        obtain ⟨zeros, significant, hzeroSplit, hzeros, hsignificant⟩ :=
          split_zeros s.val hsdigits
        have hsignificant' : significant = [] \/ exists b rest,
            significant = b :: rest /\ b ≠ 48#u8 := by
          rcases hsignificant with hnil | ⟨b, rest, heq, hb⟩
          · exact Or.inl hnil
          · exact Or.inr ⟨b, rest, heq,
              by simpa only [bne_iff_ne] using hb⟩
        have hbranch :
            ((num.imp.dec2flt.decimal.Decimal.mk 0#i64 mantissa false false).many_digits =
                false /\ significant.length <= 19 /\
              (0#i64).val = (ints.length : Int) - zeros.length -
                significant.length + 0) \/
            ((num.imp.dec2flt.decimal.Decimal.mk 0#i64 mantissa false false).many_digits =
                true /\ 19 < significant.length /\
              (0#i64).val = (ints.length : Int) - zeros.length - 19 + 0 /\
              0 < mantissa.val) := by
          left
          refine ⟨rfl, ?_, ?_⟩
          · have hsigLe : significant.length <= s.val.length := by
              rw [hzeroSplit]
              simp
            rw [hnDigitsEq] at hsmall
            omega
          · have hlength := congrArg List.length hzeroSplit
            simp only [List.length_append] at hlength
            norm_num
            omega
        have hfinal := finish_accounting
          (num.imp.dec2flt.decimal.Decimal.mk 0#i64 mantissa false false)
          s.val ints zeros significant ints.length 0 hsdigits hdigitMap
          hzeroSplit hzeros hsignificant' (by omega) (by omega) hbranch
        simpa using hfinal
      · 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
                simpa using Nat.mul_le_mul_right (10 ^ tailRest.length)
                  hfirstPos
              exact hpowLower.trans (hstep.trans (by
                simpa [digitStep] using hlower))
            obtain ⟨headPart, restPart, hsigPartition, hheadLength,
                hmanyValue, hmanyLower, hmanyUpper, hmanyExponent⟩ :=
              NumberHelperManyRetryAccounting.1 s rest 0#i64 manyExponent
                manyMantissa s.val [] zeros tail (by simp) hrest hsdigits
                (by simp) hlen hsZeros hzeros
                ⟨first, tailRest, htailEq, hfirstNe⟩ htailLen hmany
            subst d
            have hbranch :
                ((num.imp.dec2flt.decimal.Decimal.mk manyExponent manyMantissa
                    false true).many_digits = false /\ tail.length <= 19 /\
                  manyExponent.val = (ints.length : Int) - zeros.length -
                    tail.length + 0) \/
                ((num.imp.dec2flt.decimal.Decimal.mk manyExponent manyMantissa
                    false true).many_digits = true /\ 19 < tail.length /\
                  manyExponent.val = (ints.length : Int) - zeros.length - 19 + 0 /\
                  0 < manyMantissa.val) := by
              right
              refine ⟨rfl, htailLen, ?_, by omega⟩
              norm_num at hmanyExponent ⊢
              rw [hsLenEq] at hmanyExponent
              exact hmanyExponent
            have hfinal := finish_accounting
              (num.imp.dec2flt.decimal.Decimal.mk manyExponent manyMantissa
                false true)
              s.val ints zeros tail ints.length 0 hsdigits hdigitMap hsZeros
              hzeros (Or.inr ⟨first, tailRest, htailEq, hfirstNe⟩)
              (by omega) (by omega) hbranch
            simpa using hfinal
        · 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
          have hsignificant' : tail = [] \/ exists b rest,
              tail = b :: rest /\ b ≠ 48#u8 := by
            rcases htail with hnil | ⟨b, rest, heq, hb⟩
            · exact Or.inl hnil
            · exact Or.inr ⟨b, rest, heq,
                by simpa only [bne_iff_ne] using hb⟩
          have hbranch :
              ((num.imp.dec2flt.decimal.Decimal.mk 0#i64 mantissa false false).many_digits =
                  false /\ tail.length <= 19 /\
                (0#i64).val = (ints.length : Int) - zeros.length -
                  tail.length + 0) \/
              ((num.imp.dec2flt.decimal.Decimal.mk 0#i64 mantissa false false).many_digits =
                  true /\ 19 < tail.length /\
                (0#i64).val = (ints.length : Int) - zeros.length - 19 + 0 /\
                0 < mantissa.val) := by
            left
            refine ⟨rfl, htailLen, ?_⟩
            have hlength := congrArg List.length hsZeros
            simp only [List.length_append] at hlength
            norm_num
            rw [hsLenEq] at hlength
            omega
          have hfinal := finish_accounting
            (num.imp.dec2flt.decimal.Decimal.mk 0#i64 mantissa false false)
            s.val ints zeros tail ints.length 0 hsdigits hdigitMap hsZeros
            hzeros hsignificant' (by omega) (by omega) hbranch
          simpa using hfinal
    | 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 hparsedBounds : -655359 <= parsedExp.val /\
          parsedExp.val <= 655359 := by
        rw [hparsedExpTarget]
        exact explicit_bound expSign expDigits hexpDigits
      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 hintLen : intBytes.length = ints.length := by
          have := congrArg List.length hdigitMap
          simpa using this
        have hparsedBounds : -655359 <= parsedExp.val /\
            parsedExp.val <= 655359 := by
          rw [hparsedExpTarget]
          exact explicit_bound expSign expDigits hexpDigits
        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
          obtain ⟨zeros, significant, hzeroSplit, hzeros, hsignificant⟩ :=
            split_zeros intBytes hintDigits
          have hsignificant' : significant = [] \/ exists b rest,
              significant = b :: rest /\ b ≠ 48#u8 := by
            rcases hsignificant with hnil | ⟨b, rest, heq, hb⟩
            · exact Or.inl hnil
            · exact Or.inr ⟨b, rest, heq,
                by simpa only [bne_iff_ne] using hb⟩
          have hbranch :
              ((num.imp.dec2flt.decimal.Decimal.mk parsedExp mantissa
                  false false).many_digits = false /\
                significant.length <= 19 /\
                parsedExp.val = (ints.length : Int) - zeros.length -
                  significant.length + parsedExp.val) \/
              ((num.imp.dec2flt.decimal.Decimal.mk parsedExp mantissa
                  false false).many_digits = true /\
                19 < significant.length /\
                parsedExp.val = (ints.length : Int) - zeros.length - 19 +
                  parsedExp.val /\ 0 < mantissa.val) := by
            left
            refine ⟨rfl, ?_, ?_⟩
            · have hsigLe : significant.length <= intBytes.length := by
                rw [hzeroSplit]
                simp
              rw [hnDigitsEq] at hsmall
              omega
            · have hlength := congrArg List.length hzeroSplit
              simp only [List.length_append] at hlength
              omega
          have hfinal := finish_accounting
            (num.imp.dec2flt.decimal.Decimal.mk parsedExp mantissa false false)
            intBytes ints zeros significant ints.length parsedExp.val
            hintDigits hdigitMap hzeroSplit hzeros hsignificant'
            hparsedBounds.1 hparsedBounds.2 hbranch
          dsimp [expSign, expDigits] at hparsedExpTarget
          dsimp [expSign, expDigits]
          rw [hparsedExpTarget] at hfinal
          refine ⟨?_, ?_⟩
          · simpa using hparsedExpTarget.trans hfinal.1
          · simpa using hfinal.2
        · 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
                  simpa using Nat.mul_le_mul_right (10 ^ tailRest.length)
                    hfirstPos
                exact hpowLower.trans (hstep.trans (by
                  simpa [digitStep] using hlower))
              obtain ⟨headPart, restPart, hsigPartition, hheadLength,
                  hmanyValue, hmanyLower, hmanyUpper, hmanyExponent⟩ :=
                NumberHelperManyRetryAccounting.1 s intTail parsedExp
                  manyExponent manyMantissa intBytes intTail.val zeros sigTail
                  (by simpa [intTail] using hsdecomp) rfl hintDigits
                  hintTailNotDigit hlen hintZeros hzeros
                  ⟨first, tailRest, htailEq, hfirstNe⟩ hsigTailLen hmany
              subst d
              have hbranch :
                  ((num.imp.dec2flt.decimal.Decimal.mk manyExponent
                      manyMantissa false true).many_digits = false /\
                    sigTail.length <= 19 /\
                    manyExponent.val = (ints.length : Int) - zeros.length -
                      sigTail.length + parsedExp.val) \/
                  ((num.imp.dec2flt.decimal.Decimal.mk manyExponent
                      manyMantissa false true).many_digits = true /\
                    19 < sigTail.length /\
                    manyExponent.val = (ints.length : Int) - zeros.length -
                      19 + parsedExp.val /\ 0 < manyMantissa.val) := by
                right
                refine ⟨rfl, hsigTailLen, ?_, by omega⟩
                rw [hmanyExponent, hintLen]
                omega
              have hfinal := finish_accounting
                (num.imp.dec2flt.decimal.Decimal.mk manyExponent
                  manyMantissa false true)
                intBytes ints zeros sigTail ints.length parsedExp.val
                hintDigits hdigitMap hintZeros hzeros
                (Or.inr ⟨first, tailRest, htailEq, hfirstNe⟩)
                hparsedBounds.1 hparsedBounds.2 hbranch
              dsimp [expSign, expDigits] at hparsedExpTarget
              dsimp [expSign, expDigits]
              rw [hparsedExpTarget] at hfinal
              simpa using hfinal
          · 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
            have hsignificant' : sigTail = [] \/ exists b rest,
                sigTail = b :: rest /\ b ≠ 48#u8 := by
              rcases hsigTail with hnil | ⟨b, rest, heq, hb⟩
              · exact Or.inl hnil
              · exact Or.inr ⟨b, rest, heq,
                  by simpa only [bne_iff_ne] using hb⟩
            have hbranch :
                ((num.imp.dec2flt.decimal.Decimal.mk parsedExp mantissa
                    false false).many_digits = false /\
                  sigTail.length <= 19 /\
                  parsedExp.val = (ints.length : Int) - zeros.length -
                    sigTail.length + parsedExp.val) \/
                ((num.imp.dec2flt.decimal.Decimal.mk parsedExp mantissa
                    false false).many_digits = true /\
                  19 < sigTail.length /\
                  parsedExp.val = (ints.length : Int) - zeros.length - 19 +
                    parsedExp.val /\ 0 < mantissa.val) := by
              left
              refine ⟨rfl, hsigTailLen, ?_⟩
              have hlength := congrArg List.length hintZeros
              simp only [List.length_append] at hlength
              omega
            have hfinal := finish_accounting
              (num.imp.dec2flt.decimal.Decimal.mk parsedExp mantissa false false)
              intBytes ints zeros sigTail ints.length parsedExp.val hintDigits
              hdigitMap hintZeros hzeros hsignificant' hparsedBounds.1
              hparsedBounds.2 hbranch
            dsimp [expSign, expDigits] at hparsedExpTarget
            dsimp [expSign, expDigits]
            rw [hparsedExpTarget] at hfinal
            refine ⟨?_, ?_⟩
            · simpa using hparsedExpTarget.trans hfinal.1
            · simpa using hfinal.2
  | 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
        obtain ⟨zeros, significant, hzeroSplit, hzeros, hsignificant⟩ :=
          split_zeros (intBytes ++ fracBytes) hsigDigits
        have hsignificant' : significant = [] \/ exists b rest,
            significant = b :: rest /\ b ≠ 48#u8 := by
          rcases hsignificant with hnil | ⟨b, rest, heq, hb⟩
          · exact Or.inl hnil
          · exact Or.inr ⟨b, rest, heq,
              by simpa only [bne_iff_ne] using hb⟩
        have hbranch :
            ((num.imp.dec2flt.decimal.Decimal.mk fracExponent mantissa1
                false false).many_digits = false /\
              significant.length <= 19 /\
              fracExponent.val = (ints.length : Int) - zeros.length -
                significant.length + 0) \/
            ((num.imp.dec2flt.decimal.Decimal.mk fracExponent mantissa1
                false false).many_digits = true /\
              19 < significant.length /\
              fracExponent.val = (ints.length : Int) - zeros.length - 19 + 0 /\
              0 < mantissa1.val) := by
          left
          refine ⟨rfl, ?_, ?_⟩
          · have hsigLe : significant.length <=
                (intBytes ++ fracBytes).length := by
              rw [hzeroSplit]
              simp
            exact hsigLe.trans hsigLen
          · have hlength := congrArg List.length hzeroSplit
            simp only [List.length_append] at hlength
            rw [hfracExponentTarget]
            omega
        have hfinal := finish_accounting
          (num.imp.dec2flt.decimal.Decimal.mk fracExponent mantissa1 false false)
          (intBytes ++ fracBytes) (ints ++ fracs) zeros significant ints.length 0
          hsigDigits hsigMap hzeroSplit hzeros hsignificant' (by omega)
          (by omega) hbranch
        simpa using hfinal
      · 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 ⟨headPart, restPart, hsigPartition, hheadLength,
                hmanyMantissa, hmanyLower, hmanyUpper, hmanyExponent⟩ :=
              NumberHelperManyRetryAccounting.2 s intTail 0#i64 manyExponent
                manyMantissa intBytes fracBytes [] sigZeros sigTail
                (by simpa [List.append_assoc] using hsdecomp)
                (by simp [intTail]) hintDigits hfracDigits (by simp) hlen hsSig
                hsigZeros ⟨first, tailRest, htailEq, hfirstNe⟩ hsigTailLen hmany
            subst d
            have hbranch :
                ((num.imp.dec2flt.decimal.Decimal.mk manyExponent manyMantissa
                    false true).many_digits = false /\
                  sigTail.length <= 19 /\
                  manyExponent.val = (ints.length : Int) - sigZeros.length -
                    sigTail.length + 0) \/
                ((num.imp.dec2flt.decimal.Decimal.mk manyExponent manyMantissa
                    false true).many_digits = true /\
                  19 < sigTail.length /\
                  manyExponent.val = (ints.length : Int) - sigZeros.length -
                    19 + 0 /\ 0 < manyMantissa.val) := by
              right
              refine ⟨rfl, hsigTailLen, ?_, by omega⟩
              norm_num at hmanyExponent
              rw [hmanyExponent, hintLen]
              omega
            have hfinal := finish_accounting
              (num.imp.dec2flt.decimal.Decimal.mk manyExponent
                manyMantissa false true)
              (intBytes ++ fracBytes) (ints ++ fracs) sigZeros sigTail
              ints.length 0 hsigDigits hsigMap hsSig hsigZeros hsigTailSharp
              (by omega) (by omega) hbranch
            simpa using hfinal
        · 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
          have hbranch :
              ((num.imp.dec2flt.decimal.Decimal.mk fracExponent mantissa1
                  false false).many_digits = false /\
                sigTail.length <= 19 /\
                fracExponent.val = (ints.length : Int) - sigZeros.length -
                  sigTail.length + 0) \/
              ((num.imp.dec2flt.decimal.Decimal.mk fracExponent mantissa1
                  false false).many_digits = true /\
                19 < sigTail.length /\
                fracExponent.val = (ints.length : Int) - sigZeros.length - 19 + 0 /\
                0 < mantissa1.val) := by
            left
            refine ⟨rfl, hsigTailLen, ?_⟩
            rw [hfracExponentTarget]
            omega
          have hfinal := finish_accounting
            (num.imp.dec2flt.decimal.Decimal.mk fracExponent mantissa1 false false)
            (intBytes ++ fracBytes) (ints ++ fracs) sigZeros sigTail ints.length 0
            hsigDigits hsigMap hsSig hsigZeros hsigTailSharp (by omega)
            (by omega) hbranch
          simpa using hfinal
    | 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 _
      have hparsedBounds : -655359 <= parsedExp.val /\
          parsedExp.val <= 655359 := by
        rw [hparsedExpTarget]
        exact explicit_bound expSign expDigits hexpDigits
      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
            obtain ⟨zeros, significant, hzeroSplit, hzeros, hsignificant⟩ :=
              split_zeros (intBytes ++ fracBytes) hsigDigits
            have hsignificant' : significant = [] \/ exists b rest,
                significant = b :: rest /\ b ≠ 48#u8 := by
              rcases hsignificant with hnil | ⟨b, rest, heq, hb⟩
              · exact Or.inl hnil
              · exact Or.inr ⟨b, rest, heq,
                  by simpa only [bne_iff_ne] using hb⟩
            have hbranch :
                ((num.imp.dec2flt.decimal.Decimal.mk combinedExponent mantissa1
                    false false).many_digits = false /\
                  significant.length <= 19 /\
                  combinedExponent.val = (ints.length : Int) - zeros.length -
                    significant.length + parsedExp.val) \/
                ((num.imp.dec2flt.decimal.Decimal.mk combinedExponent mantissa1
                    false false).many_digits = true /\
                  19 < significant.length /\
                  combinedExponent.val = (ints.length : Int) - zeros.length - 19 +
                    parsedExp.val /\ 0 < mantissa1.val) := by
              left
              refine ⟨rfl, ?_, ?_⟩
              · have hsigLe : significant.length <=
                    (intBytes ++ fracBytes).length := by
                  rw [hzeroSplit]
                  simp
                exact hsigLe.trans hsigLen
              · have hlength := congrArg List.length hzeroSplit
                simp only [List.length_append] at hlength
                rw [hcombinedExponentTarget]
                omega
            have hfinal := finish_accounting
              (num.imp.dec2flt.decimal.Decimal.mk combinedExponent mantissa1
                false false)
              (intBytes ++ fracBytes) (ints ++ fracs) zeros significant
              ints.length parsedExp.val hsigDigits hsigMap hzeroSplit hzeros
              hsignificant' hparsedBounds.1 hparsedBounds.2 hbranch
            dsimp [expSign, expDigits] at hparsedExpTarget
            rw [hparsedExpTarget] at hfinal
            simpa [expSign, expDigits] using hfinal
          · 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 ⟨headPart, restPart, hsigPartition, hheadLength,
                    hmanyMantissa, hmanyLower, hmanyUpper, hmanyExponent⟩ :=
                  NumberHelperManyRetryAccounting.2 s intTail parsedExp
                    manyExponent manyMantissa intBytes fracBytes markerTail.val
                    sigZeros sigTail hstart (by simp [intTail]) hintDigits
                    hfracDigits hmarkerTailNotDigit hlen hsSig hsigZeros
                    ⟨first, tailRest, htailEq, hfirstNe⟩ hsigTailLen hmany
                subst d
                have hbranch :
                    ((num.imp.dec2flt.decimal.Decimal.mk manyExponent manyMantissa
                        false true).many_digits = false /\
                      sigTail.length <= 19 /\
                      manyExponent.val = (ints.length : Int) - sigZeros.length -
                        sigTail.length + parsedExp.val) \/
                    ((num.imp.dec2flt.decimal.Decimal.mk manyExponent manyMantissa
                        false true).many_digits = true /\
                      19 < sigTail.length /\
                      manyExponent.val = (ints.length : Int) - sigZeros.length -
                        19 + parsedExp.val /\ 0 < manyMantissa.val) := by
                  right
                  refine ⟨rfl, hsigTailLen, ?_, by omega⟩
                  rw [hmanyExponent, hintLen]
                  omega
                have hfinal := finish_accounting
                  (num.imp.dec2flt.decimal.Decimal.mk manyExponent
                    manyMantissa false true)
                  (intBytes ++ fracBytes) (ints ++ fracs) sigZeros sigTail
                  ints.length parsedExp.val hsigDigits hsigMap hsSig hsigZeros
                  hsigTailSharp hparsedBounds.1 hparsedBounds.2 hbranch
                dsimp [expSign, expDigits] at hparsedExpTarget
                rw [hparsedExpTarget] at hfinal
                simpa [expSign, expDigits] using hfinal
            · 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
              have hbranch :
                  ((num.imp.dec2flt.decimal.Decimal.mk combinedExponent mantissa1
                      false false).many_digits = false /\
                    sigTail.length <= 19 /\
                    combinedExponent.val = (ints.length : Int) - sigZeros.length -
                      sigTail.length + parsedExp.val) \/
                  ((num.imp.dec2flt.decimal.Decimal.mk combinedExponent mantissa1
                      false false).many_digits = true /\
                    19 < sigTail.length /\
                    combinedExponent.val = (ints.length : Int) - sigZeros.length -
                      19 + parsedExp.val /\ 0 < mantissa1.val) := by
                left
                refine ⟨rfl, hsigTailLen, ?_⟩
                rw [hcombinedExponentTarget]
                omega
              have hfinal := finish_accounting
                (num.imp.dec2flt.decimal.Decimal.mk combinedExponent mantissa1
                  false false)
                (intBytes ++ fracBytes) (ints ++ fracs) sigZeros sigTail
                ints.length parsedExp.val hsigDigits hsigMap hsSig hsigZeros
                hsigTailSharp hparsedBounds.1 hparsedBounds.2 hbranch
              dsimp [expSign, expDigits] at hparsedExpTarget
              rw [hparsedExpTarget] at hfinal
              simpa [expSign, expDigits] using hfinal

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalGoalVocabularyDefault
import Tablet.NumberHelperAccumulatedValue
import Tablet.NumberHelperAdjustManyExact
import Tablet.NumberHelperDigitScanExact
import Tablet.NumberHelperFractionalManyExact
import Tablet.NumberHelperIntegralManyExact
import Tablet.NumberHelperManyRetryAccounting
import Tablet.NumberHelperScientificExact
import Tablet.SourceValidByteSlice
import Tablet.num_imp_dec2flt_decimal_Decimal
import Tablet.num_imp_dec2flt_parse_parse_number
import Tablet.num_imp_dec2flt_parse_parse_partial_number
import Tablet.num_imp_dec2flt_parse_parse_many_digits
import Tablet.num_imp_dec2flt_parse_parse_scientific
import Tablet.num_imp_dec2flt_parse_adjust_many_digit_count

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 400000

namespace dec2flt_model

-- [TABLET NODE: ParserNumberScanAccounting]
theorem ParserNumberScanAccounting :
    forall (s : Slice Std.U8) (x : DecimalLexeme)
      (r : num.imp.dec2flt.decimal.Decimal),
      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 r) ->
      let significand := x.integerDigits ++
        match x.fractionDigits with | none => [] | some ds => ds
      let significant := significand.dropWhile (fun d => d == 0)
      let leadingZeros := significand.length - significant.length
      let P : Int := (x.integerDigits.length : Int) - leadingZeros
      let h : Int := (min significant.length 19 : Nat)
      let E : Int :=
        DecimalGoalVocabularyDefault.accumulatedExplicitExponent x
      r.exponent.val = P - h + E /\
        0 <= h /\ h <= 19 /\ -655359 <= E /\ E <= 655359 /\
        (r.many_digits = true -> 0 < r.mantissa.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 drop_zeros : forall (all zeros tail : List Std.U8),
      (forall b, List.Mem b all -> 48 <= b.val /\ b.val <= 57) ->
      all = zeros ++ tail ->
      (forall b, List.Mem b zeros -> b = 48#u8) ->
      (tail = [] \/ exists b rest, tail = b :: rest /\ b ≠ 48#u8) ->
      List.dropWhile (fun d : Nat => d == 0)
          (all.map (fun b : Std.U8 => b.val - 48)) =
        tail.map (fun b : Std.U8 => b.val - 48) := by
    intro all zeros tail hdigits hall hzeros htail
    rw [hall, List.map_append]
    induction zeros generalizing all with
    | nil =>
      simp only [List.map_nil, List.nil_append]
      rcases htail with rfl | ⟨b, rest, rfl, hb⟩
      · rfl
      · have hbdigit := hdigits b (by
          rw [hall]
          exact List.mem_append_right [] List.mem_cons_self)
        have hbval : b.val - 48 ≠ 0 := by
          have hne : b.val ≠ 48 := by
            intro h
            apply hb
            exact UScalar.eq_of_val_eq h
          omega
        simp [hbval]
    | cons z zs ih =>
      have hz := hzeros z List.mem_cons_self
      have hzs : forall b, List.Mem b zs -> b = 48#u8 := by
        intro b hb
        exact hzeros b (List.mem_cons_of_mem z hb)
      simp only [List.map_cons]
      rw [hz]
      norm_num
      apply ih (all := zs ++ tail)
      · intro b hb
        apply hdigits b
        rw [hall]
        exact List.mem_append_right [z] hb
      · rfl
      · exact hzs
  have guarded_fold_bound : forall (ds : List Nat) (a : Nat),
      (forall d, List.Mem d ds -> d < 10) ->
      a <= 655359 ->
      ds.foldl (fun n d => if n < 65536 then 10 * n + d else n) a <=
        655359 := by
    intro ds
    induction ds with
    | nil => intro a hds ha; simpa using ha
    | cons d ds ih =>
      intro a hds ha
      have hd := hds d List.mem_cons_self
      have hrest : forall e, List.Mem e ds -> e < 10 := by
        intro e he
        exact hds e (List.mem_cons_of_mem d he)
      simp only [List.foldl_cons]
      split
      · apply ih _ hrest
        omega
      · exact ih _ hrest ha
  have explicit_bound : forall (sign : Option Bool) (ds : List Nat),
      (forall d, List.Mem d ds -> d < 10) ->
      let magnitude : Nat :=
        ds.foldl (fun (n d : Nat) =>
          if n < 65536 then 10 * n + d else n) 0
      let value : Int :=
        match sign with
        | some true => -(magnitude : Int)
        | _ => (magnitude : Int)
      (-655359 : Int) <= value /\ value <= 655359 := by
    intro sign ds hds
    have hbound := guarded_fold_bound ds 0 hds (by omega)
    cases sign with
    | none => simp; omega
    | some negative => cases negative <;> simp <;> omega
  have finish_accounting : forall
      (record : num.imp.dec2flt.decimal.Decimal)
      (bytes : List Std.U8) (digits : List Nat)
      (zeros significant : List Std.U8) (integerLength : Nat) (E : Int),
      (forall b, List.Mem b bytes -> 48 <= b.val /\ b.val <= 57) ->
      bytes.map (fun b : Std.U8 => b.val - 48) = digits ->
      bytes = zeros ++ significant ->
      (forall b, List.Mem b zeros -> b = 48#u8) ->
      (significant = [] \/ exists b rest,
        significant = b :: rest /\ b ≠ 48#u8) ->
      -655359 <= E -> E <= 655359 ->
      ((record.many_digits = false /\ significant.length <= 19 /\
          record.exponent.val =
            (integerLength : Int) - zeros.length - significant.length + E) \/
        (record.many_digits = true /\ 19 < significant.length /\
          record.exponent.val =
            (integerLength : Int) - zeros.length - 19 + E /\
          0 < record.mantissa.val)) ->
      record.exponent.val =
          (integerLength : Int) -
            ((digits.length -
              (List.dropWhile (fun d : Nat => d == 0) digits).length : Nat) :
                Int) -
            ((min (List.dropWhile (fun d : Nat => d == 0) digits).length 19 :
                Nat) : Int) + E /\
        -655359 <= E /\ E <= 655359 /\
        (record.many_digits = true -> 0 < record.mantissa.val) := by
    intro record bytes digits zeros significant integerLength E hdigits
      hmap hsplit hzeros hsignificant hElower hEupper hbranch
    have hdrop := drop_zeros bytes zeros significant hdigits hsplit hzeros
      hsignificant
    rw [hmap] at hdrop
    have hlength := congrArg List.length hsplit
    have hmapLength := congrArg List.length hmap
    simp only [List.length_append, List.length_map] at hlength hmapLength
    rcases hbranch with ⟨hmany, hsiglen, hexponent⟩ |
        ⟨hmany, hsiglen, hexponent, hpositive⟩
    · have hmin : min significant.length 19 = significant.length :=
        Nat.min_eq_left hsiglen
      constructor
      · rw [hexponent, hdrop, List.length_map, hmin]
        omega
      · exact ⟨hElower, hEupper, by simp [hmany]⟩
    · have hmin : min significant.length 19 = 19 :=
        Nat.min_eq_right (by omega)
      constructor
      · rw [hexponent, hdrop, List.length_map, hmin]
        omega
      · refine ⟨hElower, hEupper, ?_⟩
        intro htrue
        exact hpositive
  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
        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
        obtain ⟨zeros, significant, hzeroSplit, hzeros, hsignificant⟩ :=
          split_zeros s.val hsdigits
        have hsignificant' : significant = [] \/ exists b rest,
            significant = b :: rest /\ b ≠ 48#u8 := by
          rcases hsignificant with hnil | ⟨b, rest, heq, hb⟩
          · exact Or.inl hnil
          · exact Or.inr ⟨b, rest, heq,
              by simpa only [bne_iff_ne] using hb⟩
        have hbranch :
            ((num.imp.dec2flt.decimal.Decimal.mk 0#i64 mantissa false false).many_digits =
                false /\ significant.length <= 19 /\
              (0#i64).val = (ints.length : Int) - zeros.length -
                significant.length + 0) \/
            ((num.imp.dec2flt.decimal.Decimal.mk 0#i64 mantissa false false).many_digits =
                true /\ 19 < significant.length /\
              (0#i64).val = (ints.length : Int) - zeros.length - 19 + 0 /\
              0 < mantissa.val) := by
          left
          refine ⟨rfl, ?_, ?_⟩
          · have hsigLe : significant.length <= s.val.length := by
              rw [hzeroSplit]
              simp
            rw [hnDigitsEq] at hsmall
            omega
          · have hlength := congrArg List.length hzeroSplit
            simp only [List.length_append] at hlength
            norm_num
            omega
        have hfinal := finish_accounting
          (num.imp.dec2flt.decimal.Decimal.mk 0#i64 mantissa false false)
          s.val ints zeros significant ints.length 0 hsdigits hdigitMap
          hzeroSplit hzeros hsignificant' (by omega) (by omega) hbranch
        simpa using hfinal
      · 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
                simpa using Nat.mul_le_mul_right (10 ^ tailRest.length)
                  hfirstPos
              exact hpowLower.trans (hstep.trans (by
                simpa [digitStep] using hlower))
            obtain ⟨headPart, restPart, hsigPartition, hheadLength,
                hmanyValue, hmanyLower, hmanyUpper, hmanyExponent⟩ :=
              NumberHelperManyRetryAccounting.1 s rest 0#i64 manyExponent
                manyMantissa s.val [] zeros tail (by simp) hrest hsdigits
                (by simp) hlen hsZeros hzeros
                ⟨first, tailRest, htailEq, hfirstNe⟩ htailLen hmany
            subst d
            have hbranch :
                ((num.imp.dec2flt.decimal.Decimal.mk manyExponent manyMantissa
                    false true).many_digits = false /\ tail.length <= 19 /\
                  manyExponent.val = (ints.length : Int) - zeros.length -
                    tail.length + 0) \/
                ((num.imp.dec2flt.decimal.Decimal.mk manyExponent manyMantissa
                    false true).many_digits = true /\ 19 < tail.length /\
                  manyExponent.val = (ints.length : Int) - zeros.length - 19 + 0 /\
                  0 < manyMantissa.val) := by
              right
              refine ⟨rfl, htailLen, ?_, by omega⟩
              norm_num at hmanyExponent ⊢
              rw [hsLenEq] at hmanyExponent
              exact hmanyExponent
            have hfinal := finish_accounting
              (num.imp.dec2flt.decimal.Decimal.mk manyExponent manyMantissa
                false true)
              s.val ints zeros tail ints.length 0 hsdigits hdigitMap hsZeros
              hzeros (Or.inr ⟨first, tailRest, htailEq, hfirstNe⟩)
              (by omega) (by omega) hbranch
            simpa using hfinal
        · 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
          have hsignificant' : tail = [] \/ exists b rest,
              tail = b :: rest /\ b ≠ 48#u8 := by
            rcases htail with hnil | ⟨b, rest, heq, hb⟩
            · exact Or.inl hnil
            · exact Or.inr ⟨b, rest, heq,
                by simpa only [bne_iff_ne] using hb⟩
          have hbranch :
              ((num.imp.dec2flt.decimal.Decimal.mk 0#i64 mantissa false false).many_digits =
                  false /\ tail.length <= 19 /\
                (0#i64).val = (ints.length : Int) - zeros.length -
                  tail.length + 0) \/
              ((num.imp.dec2flt.decimal.Decimal.mk 0#i64 mantissa false false).many_digits =
                  true /\ 19 < tail.length /\
                (0#i64).val = (ints.length : Int) - zeros.length - 19 + 0 /\
                0 < mantissa.val) := by
            left
            refine ⟨rfl, htailLen, ?_⟩
            have hlength := congrArg List.length hsZeros
            simp only [List.length_append] at hlength
            norm_num
            rw [hsLenEq] at hlength
            omega
          have hfinal := finish_accounting
            (num.imp.dec2flt.decimal.Decimal.mk 0#i64 mantissa false false)
            s.val ints zeros tail ints.length 0 hsdigits hdigitMap hsZeros
            hzeros hsignificant' (by omega) (by omega) hbranch
          simpa using hfinal
    | 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 hparsedBounds : -655359 <= parsedExp.val /\
          parsedExp.val <= 655359 := by
        rw [hparsedExpTarget]
        exact explicit_bound expSign expDigits hexpDigits
      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 hintLen : intBytes.length = ints.length := by
          have := congrArg List.length hdigitMap
          simpa using this
        have hparsedBounds : -655359 <= parsedExp.val /\
            parsedExp.val <= 655359 := by
          rw [hparsedExpTarget]
          exact explicit_bound expSign expDigits hexpDigits
        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
          obtain ⟨zeros, significant, hzeroSplit, hzeros, hsignificant⟩ :=
            split_zeros intBytes hintDigits
          have hsignificant' : significant = [] \/ exists b rest,
              significant = b :: rest /\ b ≠ 48#u8 := by
            rcases hsignificant with hnil | ⟨b, rest, heq, hb⟩
            · exact Or.inl hnil
            · exact Or.inr ⟨b, rest, heq,
                by simpa only [bne_iff_ne] using hb⟩
          have hbranch :
              ((num.imp.dec2flt.decimal.Decimal.mk parsedExp mantissa
                  false false).many_digits = false /\
                significant.length <= 19 /\
                parsedExp.val = (ints.length : Int) - zeros.length -
                  significant.length + parsedExp.val) \/
              ((num.imp.dec2flt.decimal.Decimal.mk parsedExp mantissa
                  false false).many_digits = true /\
                19 < significant.length /\
                parsedExp.val = (ints.length : Int) - zeros.length - 19 +
                  parsedExp.val /\ 0 < mantissa.val) := by
            left
            refine ⟨rfl, ?_, ?_⟩
            · have hsigLe : significant.length <= intBytes.length := by
                rw [hzeroSplit]
                simp
              rw [hnDigitsEq] at hsmall
              omega
            · have hlength := congrArg List.length hzeroSplit
              simp only [List.length_append] at hlength
              omega
          have hfinal := finish_accounting
            (num.imp.dec2flt.decimal.Decimal.mk parsedExp mantissa false false)
            intBytes ints zeros significant ints.length parsedExp.val
            hintDigits hdigitMap hzeroSplit hzeros hsignificant'
            hparsedBounds.1 hparsedBounds.2 hbranch
          dsimp [expSign, expDigits] at hparsedExpTarget
          dsimp [expSign, expDigits]
          rw [hparsedExpTarget] at hfinal
          refine ⟨?_, ?_⟩
          · simpa using hparsedExpTarget.trans hfinal.1
          · simpa using hfinal.2
        · 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
                  simpa using Nat.mul_le_mul_right (10 ^ tailRest.length)
                    hfirstPos
                exact hpowLower.trans (hstep.trans (by
                  simpa [digitStep] using hlower))
              obtain ⟨headPart, restPart, hsigPartition, hheadLength,
                  hmanyValue, hmanyLower, hmanyUpper, hmanyExponent⟩ :=
                NumberHelperManyRetryAccounting.1 s intTail parsedExp
                  manyExponent manyMantissa intBytes intTail.val zeros sigTail
                  (by simpa [intTail] using hsdecomp) rfl hintDigits
                  hintTailNotDigit hlen hintZeros hzeros
                  ⟨first, tailRest, htailEq, hfirstNe⟩ hsigTailLen hmany
              subst d
              have hbranch :
                  ((num.imp.dec2flt.decimal.Decimal.mk manyExponent
                      manyMantissa false true).many_digits = false /\
                    sigTail.length <= 19 /\
                    manyExponent.val = (ints.length : Int) - zeros.length -
                      sigTail.length + parsedExp.val) \/
                  ((num.imp.dec2flt.decimal.Decimal.mk manyExponent
                      manyMantissa false true).many_digits = true /\
                    19 < sigTail.length /\
                    manyExponent.val = (ints.length : Int) - zeros.length -
                      19 + parsedExp.val /\ 0 < manyMantissa.val) := by
                right
                refine ⟨rfl, hsigTailLen, ?_, by omega⟩
                rw [hmanyExponent, hintLen]
                omega
              have hfinal := finish_accounting
                (num.imp.dec2flt.decimal.Decimal.mk manyExponent
                  manyMantissa false true)
                intBytes ints zeros sigTail ints.length parsedExp.val
                hintDigits hdigitMap hintZeros hzeros
                (Or.inr ⟨first, tailRest, htailEq, hfirstNe⟩)
                hparsedBounds.1 hparsedBounds.2 hbranch
              dsimp [expSign, expDigits] at hparsedExpTarget
              dsimp [expSign, expDigits]
              rw [hparsedExpTarget] at hfinal
              simpa using hfinal
          · 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
            have hsignificant' : sigTail = [] \/ exists b rest,
                sigTail = b :: rest /\ b ≠ 48#u8 := by
              rcases hsigTail with hnil | ⟨b, rest, heq, hb⟩
              · exact Or.inl hnil
              · exact Or.inr ⟨b, rest, heq,
                  by simpa only [bne_iff_ne] using hb⟩
            have hbranch :
                ((num.imp.dec2flt.decimal.Decimal.mk parsedExp mantissa
                    false false).many_digits = false /\
                  sigTail.length <= 19 /\
                  parsedExp.val = (ints.length : Int) - zeros.length -
                    sigTail.length + parsedExp.val) \/
                ((num.imp.dec2flt.decimal.Decimal.mk parsedExp mantissa
                    false false).many_digits = true /\
                  19 < sigTail.length /\
                  parsedExp.val = (ints.length : Int) - zeros.length - 19 +
                    parsedExp.val /\ 0 < mantissa.val) := by
              left
              refine ⟨rfl, hsigTailLen, ?_⟩
              have hlength := congrArg List.length hintZeros
              simp only [List.length_append] at hlength
              omega
            have hfinal := finish_accounting
              (num.imp.dec2flt.decimal.Decimal.mk parsedExp mantissa false false)
              intBytes ints zeros sigTail ints.length parsedExp.val hintDigits
              hdigitMap hintZeros hzeros hsignificant' hparsedBounds.1
              hparsedBounds.2 hbranch
            dsimp [expSign, expDigits] at hparsedExpTarget
            dsimp [expSign, expDigits]
            rw [hparsedExpTarget] at hfinal
            refine ⟨?_, ?_⟩
            · simpa using hparsedExpTarget.trans hfinal.1
            · simpa using hfinal.2
  | 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
        obtain ⟨zeros, significant, hzeroSplit, hzeros, hsignificant⟩ :=
          split_zeros (intBytes ++ fracBytes) hsigDigits
        have hsignificant' : significant = [] \/ exists b rest,
            significant = b :: rest /\ b ≠ 48#u8 := by
          rcases hsignificant with hnil | ⟨b, rest, heq, hb⟩
          · exact Or.inl hnil
          · exact Or.inr ⟨b, rest, heq,
              by simpa only [bne_iff_ne] using hb⟩
        have hbranch :
            ((num.imp.dec2flt.decimal.Decimal.mk fracExponent mantissa1
                false false).many_digits = false /\
              significant.length <= 19 /\
              fracExponent.val = (ints.length : Int) - zeros.length -
                significant.length + 0) \/
            ((num.imp.dec2flt.decimal.Decimal.mk fracExponent mantissa1
                false false).many_digits = true /\
              19 < significant.length /\
              fracExponent.val = (ints.length : Int) - zeros.length - 19 + 0 /\
              0 < mantissa1.val) := by
          left
          refine ⟨rfl, ?_, ?_⟩
          · have hsigLe : significant.length <=
                (intBytes ++ fracBytes).length := by
              rw [hzeroSplit]
              simp
            exact hsigLe.trans hsigLen
          · have hlength := congrArg List.length hzeroSplit
            simp only [List.length_append] at hlength
            rw [hfracExponentTarget]
            omega
        have hfinal := finish_accounting
          (num.imp.dec2flt.decimal.Decimal.mk fracExponent mantissa1 false false)
          (intBytes ++ fracBytes) (ints ++ fracs) zeros significant ints.length 0
          hsigDigits hsigMap hzeroSplit hzeros hsignificant' (by omega)
          (by omega) hbranch
        simpa using hfinal
      · 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 ⟨headPart, restPart, hsigPartition, hheadLength,
                hmanyMantissa, hmanyLower, hmanyUpper, hmanyExponent⟩ :=
              NumberHelperManyRetryAccounting.2 s intTail 0#i64 manyExponent
                manyMantissa intBytes fracBytes [] sigZeros sigTail
                (by simpa [List.append_assoc] using hsdecomp)
                (by simp [intTail]) hintDigits hfracDigits (by simp) hlen hsSig
                hsigZeros ⟨first, tailRest, htailEq, hfirstNe⟩ hsigTailLen hmany
            subst d
            have hbranch :
                ((num.imp.dec2flt.decimal.Decimal.mk manyExponent manyMantissa
                    false true).many_digits = false /\
                  sigTail.length <= 19 /\
                  manyExponent.val = (ints.length : Int) - sigZeros.length -
                    sigTail.length + 0) \/
                ((num.imp.dec2flt.decimal.Decimal.mk manyExponent manyMantissa
                    false true).many_digits = true /\
                  19 < sigTail.length /\
                  manyExponent.val = (ints.length : Int) - sigZeros.length -
                    19 + 0 /\ 0 < manyMantissa.val) := by
              right
              refine ⟨rfl, hsigTailLen, ?_, by omega⟩
              norm_num at hmanyExponent
              rw [hmanyExponent, hintLen]
              omega
            have hfinal := finish_accounting
              (num.imp.dec2flt.decimal.Decimal.mk manyExponent
                manyMantissa false true)
              (intBytes ++ fracBytes) (ints ++ fracs) sigZeros sigTail
              ints.length 0 hsigDigits hsigMap hsSig hsigZeros hsigTailSharp
              (by omega) (by omega) hbranch
            simpa using hfinal
        · 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
          have hbranch :
              ((num.imp.dec2flt.decimal.Decimal.mk fracExponent mantissa1
                  false false).many_digits = false /\
                sigTail.length <= 19 /\
                fracExponent.val = (ints.length : Int) - sigZeros.length -
                  sigTail.length + 0) \/
              ((num.imp.dec2flt.decimal.Decimal.mk fracExponent mantissa1
                  false false).many_digits = true /\
                19 < sigTail.length /\
                fracExponent.val = (ints.length : Int) - sigZeros.length - 19 + 0 /\
                0 < mantissa1.val) := by
            left
            refine ⟨rfl, hsigTailLen, ?_⟩
            rw [hfracExponentTarget]
            omega
          have hfinal := finish_accounting
            (num.imp.dec2flt.decimal.Decimal.mk fracExponent mantissa1 false false)
            (intBytes ++ fracBytes) (ints ++ fracs) sigZeros sigTail ints.length 0
            hsigDigits hsigMap hsSig hsigZeros hsigTailSharp (by omega)
            (by omega) hbranch
          simpa using hfinal
    | 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 _
      have hparsedBounds : -655359 <= parsedExp.val /\
          parsedExp.val <= 655359 := by
        rw [hparsedExpTarget]
        exact explicit_bound expSign expDigits hexpDigits
      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
            obtain ⟨zeros, significant, hzeroSplit, hzeros, hsignificant⟩ :=
              split_zeros (intBytes ++ fracBytes) hsigDigits
            have hsignificant' : significant = [] \/ exists b rest,
                significant = b :: rest /\ b ≠ 48#u8 := by
              rcases hsignificant with hnil | ⟨b, rest, heq, hb⟩
              · exact Or.inl hnil
              · exact Or.inr ⟨b, rest, heq,
                  by simpa only [bne_iff_ne] using hb⟩
            have hbranch :
                ((num.imp.dec2flt.decimal.Decimal.mk combinedExponent mantissa1
                    false false).many_digits = false /\
                  significant.length <= 19 /\
                  combinedExponent.val = (ints.length : Int) - zeros.length -
                    significant.length + parsedExp.val) \/
                ((num.imp.dec2flt.decimal.Decimal.mk combinedExponent mantissa1
                    false false).many_digits = true /\
                  19 < significant.length /\
                  combinedExponent.val = (ints.length : Int) - zeros.length - 19 +
                    parsedExp.val /\ 0 < mantissa1.val) := by
              left
              refine ⟨rfl, ?_, ?_⟩
              · have hsigLe : significant.length <=
                    (intBytes ++ fracBytes).length := by
                  rw [hzeroSplit]
                  simp
                exact hsigLe.trans hsigLen
              · have hlength := congrArg List.length hzeroSplit
                simp only [List.length_append] at hlength
                rw [hcombinedExponentTarget]
                omega
            have hfinal := finish_accounting
              (num.imp.dec2flt.decimal.Decimal.mk combinedExponent mantissa1
                false false)
              (intBytes ++ fracBytes) (ints ++ fracs) zeros significant
              ints.length parsedExp.val hsigDigits hsigMap hzeroSplit hzeros
              hsignificant' hparsedBounds.1 hparsedBounds.2 hbranch
            dsimp [expSign, expDigits] at hparsedExpTarget
            rw [hparsedExpTarget] at hfinal
            simpa [expSign, expDigits] using hfinal
          · 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 ⟨headPart, restPart, hsigPartition, hheadLength,
                    hmanyMantissa, hmanyLower, hmanyUpper, hmanyExponent⟩ :=
                  NumberHelperManyRetryAccounting.2 s intTail parsedExp
                    manyExponent manyMantissa intBytes fracBytes markerTail.val
                    sigZeros sigTail hstart (by simp [intTail]) hintDigits
                    hfracDigits hmarkerTailNotDigit hlen hsSig hsigZeros
                    ⟨first, tailRest, htailEq, hfirstNe⟩ hsigTailLen hmany
                subst d
                have hbranch :
                    ((num.imp.dec2flt.decimal.Decimal.mk manyExponent manyMantissa
                        false true).many_digits = false /\
                      sigTail.length <= 19 /\
                      manyExponent.val = (ints.length : Int) - sigZeros.length -
                        sigTail.length + parsedExp.val) \/
                    ((num.imp.dec2flt.decimal.Decimal.mk manyExponent manyMantissa
                        false true).many_digits = true /\
                      19 < sigTail.length /\
                      manyExponent.val = (ints.length : Int) - sigZeros.length -
                        19 + parsedExp.val /\ 0 < manyMantissa.val) := by
                  right
                  refine ⟨rfl, hsigTailLen, ?_, by omega⟩
                  rw [hmanyExponent, hintLen]
                  omega
                have hfinal := finish_accounting
                  (num.imp.dec2flt.decimal.Decimal.mk manyExponent
                    manyMantissa false true)
                  (intBytes ++ fracBytes) (ints ++ fracs) sigZeros sigTail
                  ints.length parsedExp.val hsigDigits hsigMap hsSig hsigZeros
                  hsigTailSharp hparsedBounds.1 hparsedBounds.2 hbranch
                dsimp [expSign, expDigits] at hparsedExpTarget
                rw [hparsedExpTarget] at hfinal
                simpa [expSign, expDigits] using hfinal
            · 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
              have hbranch :
                  ((num.imp.dec2flt.decimal.Decimal.mk combinedExponent mantissa1
                      false false).many_digits = false /\
                    sigTail.length <= 19 /\
                    combinedExponent.val = (ints.length : Int) - sigZeros.length -
                      sigTail.length + parsedExp.val) \/
                  ((num.imp.dec2flt.decimal.Decimal.mk combinedExponent mantissa1
                      false false).many_digits = true /\
                    19 < sigTail.length /\
                    combinedExponent.val = (ints.length : Int) - sigZeros.length -
                      19 + parsedExp.val /\ 0 < mantissa1.val) := by
                left
                refine ⟨rfl, hsigTailLen, ?_⟩
                rw [hcombinedExponentTarget]
                omega
              have hfinal := finish_accounting
                (num.imp.dec2flt.decimal.Decimal.mk combinedExponent mantissa1
                  false false)
                (intBytes ++ fracBytes) (ints ++ fracs) sigZeros sigTail
                ints.length parsedExp.val hsigDigits hsigMap hsSig hsigZeros
                hsigTailSharp hparsedBounds.1 hparsedBounds.2 hbranch
              dsimp [expSign, expDigits] at hparsedExpTarget
              rw [hparsedExpTarget] at hfinal
              simpa [expSign, expDigits] using hfinal

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 67 entries
Technical checking records
Local closure summary
{
  "node": "ParserNumberScanAccounting",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "8b05e78cb6d5eb68e95464fc13711c6b8c31814178b365978a7ae01e360478d0",
  "active_statement_hash": "ec5f421814f5cb91d527fba56360b239935acd4b1c02faafedc3a93deea480b3",
  "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-166",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DecimalGoalVocabularyDefault": "94cb4c406f8efb78",
    "ModelSliceSplitFirst": "f617ee05dd2925a9",
    "NumberHelperAccumulatedValue": "4dbd872ba02a631e",
    "NumberHelperAdjustManyExact": "8999fa99d4681219",
    "NumberHelperDecimalPrefixInterval": "5c32858414034b55",
    "NumberHelperDigitScanExact": "6bcf20c61d10dea3",
    "NumberHelperDigitScanSourceLength": "8892b939bba0ecf9",
    "NumberHelperManyRetryAccounting": "85db50d7a412afc2",
    "NumberHelperOffsetSourceLength": "de0168dfeba3b802",
    "NumberHelperScientificExact": "85d7c23c40290390",
    "NumberHelperSplitExponentSuffix": "36f92cf2e9d9f766",
    "num_imp_dec2flt_parse_parse_partial_number": "854af4cc12136a58"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "0717fd246d7ea78a",
    "DecimalGoalVocabularyDefault": "512f8d0aea894250",
    "DecimalLexeme": "c43614ff2149ecf2",
    "F64": "ec4e25fbaf4e11d4",
    "ModelOptionBranch": "2b227898dbe15e59",
    "NumberHelperSplitExponentSuffix": "3a789d080d66f335",
    "Preamble": "4adf4172ae751d7d",
    "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": "b8693ec58f01c43c",
    "num_imp_dec2flt_parse_parse_partial_number": "0b89b3e203e9108d",
    "num_imp_dec2flt_parse_parse_scientific": "447f722d5841d2c5",
    "num_imp_dec2flt_parse_try_parse_digits": "238b4a73cd46fc56"
  }
}
Prose assessment
{
  "label": "Sound flag superseded by recorded Lean closure",
  "assessment_status": "ReviewerPinnedFail",
  "fingerprint_relation": "differs from current fingerprint",
  "assessment_fingerprint": "sound-v2:76de19bd1703e8033ca166bc5451dd840986432ef30247a61868cb1cbe2d6280",
  "current_fingerprint": "sound-v2:50f86fac577afb93011936f4715036688bd830eb85623ce87f5c108f913bd94f",
  "superseded_for_theorem_closure": true
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Fail",
  "substantiveness_status": "Pass"
}