NumberHelperPartialNumberSafeLength

Lean checked

Statement

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

Lemma · Safe partial-number parsing of an invalid unsigned input

Let s be a source-valid, nonempty byte slice of length at most 9223372036854120459. If its complete byte sequence is not the rendering of any valid numeric lexeme having no leading sign, then the extracted parse_partial_number returns normally. Moreover, whenever its return is Some of a decimal record and consumed length, that length is not the full input length.

Lean statement

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

import Tablet.NumberHelperDigitScanSourceLength
import Tablet.NumberHelperOffsetSourceLength
import Tablet.NumberHelperAdjustManySourceLength
import Tablet.NumberHelperIntegralManyDigitsSourceLength
import Tablet.NumberHelperFractionalManyDigitsSourceLength
import Tablet.NumberHelperScientificPrefixSafeLength
import Tablet.NumberHelperScientificClassificationSourceLength
import Tablet.NumberHelperScientificExponentBounds
import Tablet.DecimalGoalVocabularyDefault
import Tablet.SourceValidByteSlice
import Tablet.ModelSliceSplitFirst
import Tablet.ModelOptionBranch
import Tablet.ModelOptionFromResidual
import Tablet.num_imp_dec2flt_parse_parse_partial_number

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

namespace dec2flt_model

-- [TABLET NODE: NumberHelperPartialNumberSafeLength]
theorem NumberHelperPartialNumberSafeLength :
    forall s : Slice Std.U8,
      SourceValidByteSlice s -> s.val != [] ->
      s.val.length <= 9223372036854120459 ->
      (Not (exists x : DecimalLexeme,
        x.leadingSign = none /\
        DecimalGoalVocabularyDefault.validNumeric x /\
        DecimalGoalVocabularyDefault.bytes s =
          DecimalGoalVocabularyDefault.renderNumeric x)) ->
      exists o,
        num.imp.dec2flt.parse.parse_partial_number s = ok o /\
        forall (d : num.imp.dec2flt.decimal.Decimal) (r : Std.Usize),
          o = some (d, r) -> Not (r = Slice.len s) := by
Proof

Natural-language proof

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

Explanatory prose status

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

Proof

Write M=2^{63}-1=9223372036854775807, B=9223372036854120459=M-655348, and L=|s|. By Assumptions, usize and isize are 64-bit. Thus L\leq B<M; every input length and guarded index below fits usize, and every cast of a length to nonnegative isize is exact. By SourceValidByteSlice, the separate source-validity premise is compatible with this stronger bound. The last premise, using the definitions in DecimalGoalVocabularyDefault, says precisely that the whole input is not a valid unsigned numeric rendering.
First consider the two loops in num imp dec2flt parse try parse digits. The eight-byte loop reads only after its remaining-length guard proves that the first eight bytes exist. The implementation in SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice read u64 therefore copies an in-bounds prefix and returns its little-endian word; a continuing iteration drops exactly those eight bytes. Each continuation strictly reduces the remaining length, so the loop terminates.
The test in num imp dec2flt common is 8digits has no false positive. Indeed, write the bytes of its word as b_0,\ldots,b_7. Its three constants consist bytewise of 0x46, 0x30, and 0x80. Let d_i be the borrow entering byte i of subtraction by 0x30, initially zero. If the test is true, the high bit of every result byte is zero. Inductively, b_i<48 would give a subtraction result in [208,255], a contradiction; hence there is no outgoing borrow and 48\leq b_i\leq175. Let c_i be the carry entering byte i of addition by 0x46, again initially zero. Under the preceding bound, b_i\geq58 would give a result in [128,245], a contradiction. Thus there is no outgoing carry and 48\leq b_i\leq57. These two inductions cover all eight bytes, including cross-byte carries and borrows.
Consequently every call of num imp dec2flt parse parse 8digits receives a word whose bytes are decimal digits. Its checked subtraction by eight copies of 0x30 has no borrow and produces a word v'<2^{60}. The checked multiplication by ten is below 10\cdot2^{60}<2^{64}. The checked shift by eight is defined and below 2^{52}, so the following checked addition is below 10\cdot2^{60}+2^{52}<2^{64}. Its shifts by 16 and 32 are also defined; intervening masked products and their addition are wrapping. The word after the final right shift is at most 2^{32}-1, so its checked cast to u32, and the widening back to u64, are exact.
The eight-byte accumulator operations are wrapping. In the scalar loop, the index test justifies every byte access, subtraction and accumulator arithmetic are wrapping, the byte-to-u64 cast is exact, and the checked count increment remains at most the slice length. The final suffix therefore starts at an in-bounds count. This establishes normal termination of a digit scan on arbitrary bytes, not just on digit-only slices, and also shows that its returned slice is a suffix of its argument consisting of the unconsumed bytes.
Unfold num imp dec2flt parse parse partial number. Its opening nonempty assertion holds. Every call of SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice offset from compares the original slice, or the slice after a point, with a suffix just constructed. Both length casts lie in [0,L], and their checked difference is the corresponding consumed length. Let I and F be the numbers of integer and fractional digits scanned and put D=I+F. We have 0\leq I,F,D\leq L. If a point was consumed, -F lies in the signed range and its cast to i64 is exact. The checked addition producing D is safe. If D=0, the function returns None normally.
Assume henceforth that D>0. With no following e or E, there is no explicit-exponent arithmetic. Otherwise unfold num imp dec2flt parse parse scientific. Removing an optional sign is guarded. An empty signed suffix, or a nondigit first byte, returns None normally. The option branch and residual operations modeled by ModelOptionBranch and ModelOptionFromResidual then make the partial parser return None normally.
If exponent digits are present, let q\geq1 be their consumed count. At each iteration the index is below the suffix length and its increment stays at most L. While the nonnegative accumulator a is below 65536, its checked update satisfies 10a+d\leq10\cdot65535+9=655359<2^{63}; afterward the guard leaves it unchanged. Final negation is therefore safe. This is also the loop invariant formalized by NumberHelperScientificExponentBounds: the returned explicit exponent E satisfies |E|\leq655359.
The first-pass exponent is -F+E. Its upper side is at most 655359. If E\geq0, its lower side is at least -F\geq-B>-2^{63}; if E<0 and F=0, it is at least -655359. Suppose E<0 and F>0. Were the suffix after the exponent empty, the already scanned bytes would consist of the integer digits, point, F fractional digits, exponent marker, minus sign, and q exponent digits. Since D>0, these components form a valid complete unsigned numeric lexeme under DecimalGoalVocabularyDefault, contrary to the hypothesis. Hence at least one unmatched byte remains, and counting the point, marker, minus, q digits, and that byte gives F\leq L-(q+4). For q\leq5, decimal accumulation gives |E|\leq10^q-1; for q\geq6, it gives |E|\leq655359. Therefore
F+|E|\leq \begin{cases} L-(q+4)+(10^q-1)\leq L+99990,&q\leq5,\\ L-(q+4)+655359\leq L+655349,&q\geq6. \end{cases}
The second expression is maximal at q=6, and L+655349\leq B+655349=M+1=2^{63}. Equality is permitted for the negative endpoint, so -F+E cannot overflow. All first-pass exponent additions, offsets, and casts are thus normal.
It remains to check the D>19 path. The checked subtraction starts num imp dec2flt parse adjust many digit count at n_0=D-19\geq1. Every access is index-guarded. Its constant subtraction is 48-1=47; saturating subtraction of 47 from a point gives zero and from a zero digit gives one, both exactly castable to isize. After i index-advancing iterations, let z_i be the number of visited zero digits. Induction over the point and zero branches gives
n_i=D-19-z_i,\qquad 0\leq z_i\leq i\leq L.
Hence n_i\geq1-L> -2^{63} and n_i\leq D-19\leq L<2^{63}, proving every checked signed subtraction safe; every index increment is at most L.
If the final n_i is positive, then z_i<D-19<D. The scan cannot have passed every significand digit, since doing so would require all of them to be zero and hence z_i\geq D. It stops at a nonzero digit within the original significand, with at least D-z_i\geq20 digit bytes remaining. If its final value is nonpositive, no retry occurs.
For a retry, num imp dec2flt parse MIN 19DIGIT INT is exactly 10^{18}. In num imp dec2flt parse try parse 19digits, a checked update occurs only below this threshold, and is at most 10(10^{18}-1)+9=10^{19}-1<2^{64}. All byte casts and splits are exact or guarded. If the first retry reaches the threshold, the offset from its suffix to the saved integer end is a nonnegative number at most L, so its casts are safe. If it remains below the threshold, it cannot have consumed nineteen of the at least twenty remaining digits: starting with a nonzero digit, the exact recurrence after nineteen digits is at least 10^{18}. Thus it must stop at the saved point. Skipping that point is in bounds, and the second retry consumes at most F fractional digits. Its offset R is in [0,F], so checked negation and conversion give a base in [-F,0].
Finally unfold num imp dec2flt parse parse many digits. In its nonnegative integer-offset branch without an explicit exponent, the base is at most L; a negative exponent only lowers it by at most 655359. With a positive q-digit exponent, at least nineteen digits, the marker, and the q exponent digits lie outside that remaining offset. The final sum is at most L-q-20+(10^q-1)\leq L+99974 for q\leq5, and at most L-q-20+655359\leq L+655333 for q\geq6; both are below 2^{63} at L\leq B. In the fractional branch the base is -R with R\leq F. Its upper side is at most 655359, and its lower side follows from the already proved F+|E|\leq2^{63}. Thus every retry addition is safe.
We have exhausted the assertions, guarded slices and indexes, checked offsets and casts, count arithmetic, negations, digit updates, and exponent additions in the partial parser, so it returns ok of some option. Suppose this option were Some with consumed length L. The scans then provide at least one significand digit; a point, if present, occurs in its single scanned position; and an exponent, if present, has its marker, optional sign, and at least one scanned digit. Translating each digit byte 48+d back to d<10 constructs a DecimalLexeme with leadingSign = None, satisfying DecimalGoalVocabularyDefault. Full consumption makes its rendered bytes exactly s. This contradicts the assumed absence of such a lexeme. Therefore every Some result has consumed length different from the full input length, as required.

Lean proof


  intro s hsource hne hlen hinvalid
  have hsourceLen : s.val.length <= 9223372036854775807 := by
    simp [SourceValidByteSlice] at hsource
    exact hsource
  have split_digits : forall bs : List Std.U8,
      exists digits tail,
        bs = digits ++ tail /\
        (forall b, List.Mem b digits -> 48 <= b.val /\ b.val <= 57) /\
        (forall b rest, tail = b :: rest ->
          Not (48 <= b.val /\ b.val <= 57)) := by
    intro bs
    induction bs with
    | nil => exact ⟨[], [], rfl, (by intro b hb; cases hb),
        (by intro b rest h; cases h)⟩
    | cons b bs ih =>
      by_cases hb : 48 <= b.val /\ b.val <= 57
      · obtain ⟨digits, tail, hbs, hdigits, htail⟩ := ih
        refine ⟨b :: digits, tail, ?_, ?_, htail⟩
        · simp [hbs]
        · intro c hc
          rcases List.mem_cons.mp hc with rfl | hc
          · exact hb
          · exact hdigits c hc
      · exact ⟨[], b :: bs, rfl, (by intro c hc; cases hc), by
          intro c rest h
          cases h
          exact hb⟩
  let scientific_sign : List Std.U8 -> Option Bool := fun bs =>
    match bs with
    | [] => none
    | b :: _ => if b = 45#u8 then some true
      else if b = 43#u8 then some false else none
  let scientific_body : List Std.U8 -> List Std.U8 := fun bs =>
    match bs with
    | [] => []
    | b :: rest => if b = 45#u8 \/ b = 43#u8 then rest else b :: rest
  have scientific_split : forall bs : List Std.U8,
      bs = (match scientific_sign bs with
        | none => []
        | some negative => [if negative then 45#u8 else 43#u8]) ++
          scientific_body bs := by
    intro bs
    cases bs with
    | nil => simp [scientific_sign, scientific_body]
    | cons b rest =>
      by_cases hm : b = 45#u8
      · subst b
        simp [scientific_sign, scientific_body]
      · by_cases hp : b = 43#u8
        · subst b
          simp [scientific_sign, scientific_body]
        · simp [scientific_sign, scientific_body, hm, hp]
  have scientific_unsigned : forall bs : List Std.U8,
      scientific_sign bs = none -> forall b rest,
        scientific_body bs = b :: rest -> b ≠ 45#u8 /\ b ≠ 43#u8 := by
    intro bs
    cases bs with
    | nil => simp [scientific_body]
    | cons b rest =>
      by_cases hm : b = 45#u8
      · subst b
        simp [scientific_sign]
      · by_cases hp : b = 43#u8
        · subst b
          simp [scientific_sign, hm]
        · simp only [scientific_sign, scientific_body, hm, hp, if_false,
            or_false]
          intro _ c cs h
          injection h with hbc _
          subst c
          exact ⟨hm, hp⟩
  have render_digits : forall bs : List Std.U8,
      (forall b, List.Mem b bs -> 48 <= b.val /\ b.val <= 57) ->
      List.map (fun b : Std.U8 => b.val) bs =
        List.map (fun d : Nat => 48 + d)
          (List.map (fun b : Std.U8 => b.val - 48) bs) := by
    intro bs hbs
    induction bs with
    | nil => rfl
    | cons b bs ih =>
      have hb := hbs b List.mem_cons_self
      have hrest : forall c, List.Mem c bs -> 48 <= c.val /\ c.val <= 57 := by
        intro c hc
        exact hbs c (List.mem_cons_of_mem b hc)
      simp [ih hrest]
      omega
  have complete_spelling : forall (integer : List Std.U8)
      (fraction : Option (List Std.U8))
      (expo : Option (Bool × Option Bool × List Std.U8)),
      (forall b, List.Mem b integer -> 48 <= b.val /\ b.val <= 57) ->
      (match fraction with
        | none => True
        | some ds => forall b, List.Mem b ds ->
            48 <= b.val /\ b.val <= 57) ->
      (integer != [] \/
        match fraction with | none => False | some ds => ds != []) ->
      (match expo with
        | none => True
        | some (_, _, ds) => ds != [] /\
            forall b, List.Mem b ds -> 48 <= b.val /\ b.val <= 57) ->
      s.val = integer ++
        (match fraction with | none => [] | some ds => 46#u8 :: ds) ++
        (match expo with
          | none => []
          | some (upper, sign, ds) =>
              (if upper then 69#u8 else 101#u8) ::
              (match sign with
                | none => []
                | some neg => [if neg then 45#u8 else 43#u8]) ++ ds) ->
      False := by
    intro integer fraction expo hint hfrac hsome hexpo hs
    apply hinvalid
    let x : DecimalLexeme := {
      leadingSign := none
      integerDigits := integer.map (fun b => b.val - 48)
      fractionDigits := fraction.map
        (fun ds => ds.map (fun b => b.val - 48))
      exponent := expo.map (fun e =>
        (e.1, e.2.1, e.2.2.map (fun b => b.val - 48)))
    }
    refine ⟨x, rfl, ?_, ?_⟩
    · simp [DecimalGoalVocabularyDefault, x]
      constructor
      · intro d hd
        have := hint d hd
        omega
      constructor
      · cases fraction with
        | none => simp
        | some fs =>
          simp only [Option.map_some]
          intro d hd
          obtain ⟨b, hb, rfl⟩ := List.mem_map.mp hd
          have := hfrac b hb
          omega
      constructor
      · cases fraction <;> simpa using hsome
      · cases expo with
        | none => simp
        | some e =>
          rcases e with ⟨upper, sign, es⟩
          simp at hexpo ⊢
          refine ⟨hexpo.1, ?_⟩
          intro d hd
          have := hexpo.2 d hd
          omega
    · simp [DecimalGoalVocabularyDefault, x]
      rw [hs]
      simp only [List.map_append, List.map_cons]
      have hintRender :
          List.map ((fun d : Nat => 48 + d) ∘
            fun b : Std.U8 => b.val - 48) integer =
          List.map (fun b : Std.U8 => b.val) integer := by
        simpa [List.map_map] using (render_digits integer hint).symm
      rw [hintRender]
      cases fraction with
      | none =>
        simp only [Option.map_none]
        simp at hfrac
        cases expo with
        | none => simp
        | some e =>
          rcases e with ⟨upper, sign, es⟩
          simp only [Option.map_some, List.map_map]
          simp at hexpo ⊢
          have hexpRender :
              List.map ((fun d : Nat => 48 + d) ∘
                fun b : Std.U8 => b.val - 48) es =
              List.map (fun b : Std.U8 => b.val) es := by
            simpa [List.map_map] using (render_digits es hexpo.2).symm
          rw [hexpRender]
          cases upper <;> cases sign with
          | none => norm_num
          | some neg => cases neg <;> norm_num
      | some fs =>
        simp only [Option.map_some, List.map_map]
        simp at hfrac
        have hfracRender :
            List.map ((fun d : Nat => 48 + d) ∘
              fun b : Std.U8 => b.val - 48) fs =
            List.map (fun b : Std.U8 => b.val) fs := by
          simpa [List.map_map] using (render_digits fs hfrac).symm
        rw [hfracRender]
        cases expo with
        | none => simp
        | some e =>
          rcases e with ⟨upper, sign, es⟩
          simp only [Option.map_some, List.map_map]
          simp at hexpo ⊢
          have hexpRender :
              List.map ((fun d : Nat => 48 + d) ∘
                fun b : Std.U8 => b.val - 48) es =
              List.map (fun b : Std.U8 => b.val) es := by
            simpa [List.map_map] using (render_digits es hexpo.2).symm
          rw [hexpRender]
          cases upper <;> cases sign with
          | none => norm_num
          | some neg => cases neg <;> norm_num
  obtain ⟨integer, intTailBytes, hsval, hintDigits, hintTail⟩ :=
    split_digits s.val
  obtain ⟨mantissa, intRest, hscanInt, hintRest⟩ :=
    NumberHelperDigitScanSourceLength s 0#u64 integer intTailBytes
      hsval hintDigits hintTail hsourceLen
  obtain ⟨nDigits, hoffInt, hnDigitsVal⟩ :=
    NumberHelperOffsetSourceLength s intRest hsourceLen (by
      rw [hintRest, hsval]
      simp)
  have hnDigitsEq : nDigits.val = integer.length := by
    rw [hnDigitsVal, hintRest, hsval]
    simp
  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 hnotempty : Not (s.val = []) := by simpa using hne
  cases htailEq : intTailBytes with
  | nil =>
    have hintegerNeProp : integer ≠ [] := by
      intro hi
      rw [hi, htailEq] at hsval
      simp at hsval
      exact hnotempty hsval
    have hintegerNe : integer != [] := by
      simpa only [bne_iff_ne] using hintegerNeProp
    exact False.elim (complete_spelling integer none none hintDigits (by
      simp) (by left; exact hintegerNe) (by simp) (by
        simpa [htailEq] using hsval))
  | cons c cs =>
    have hintRestVal : intRest.val = c :: cs := by simpa [htailEq] using hintRest
    have hcsProp : cs.length <= Usize.max := by
      have hp := intRest.property
      rw [hintRestVal] at hp
      simp only [List.length_cons] at hp
      omega
    let afterFirst : Slice Std.U8 := ⟨cs, hcsProp⟩
    have h46Target : (46#u8 : Std.U8) = 46#uscalar := by
      apply UScalar.eq_of_val_eq
      rfl
    have h101Target : (101#u8 : Std.U8) = 101#uscalar := by
      apply UScalar.eq_of_val_eq
      rfl
    have h69Target : (69#u8 : Std.U8) = 69#uscalar := by
      apply UScalar.eq_of_val_eq
      rfl
    have hsplitInt : core.slice.Slice.split_first intRest =
        ok (some (c, afterFirst)) := by
      have hirest : intRest = (⟨c :: cs, by simpa [hintRestVal] using
        intRest.property⟩ : Slice Std.U8) := (Slice.eq_iff _ _).2 hintRestVal
      rw [hirest]
      simp [core.slice.Slice.split_first, dec2flt_model.ModelSliceSplitFirst,
        afterFirst]
    by_cases hpoint : c = 46#u8
    · subst c
      obtain ⟨fraction, fracTail, hcs, hfracDigits, hfracTail⟩ :=
        split_digits cs
      have hafterVal : afterFirst.val = fraction ++ fracTail := by
        simp [afterFirst, hcs]
      have hafterLen : afterFirst.val.length <= 9223372036854775807 := by
        rw [hafterVal]
        rw [hsval, htailEq, hcs] at hlen
        simp at hlen
        rw [List.length_append]
        omega
      obtain ⟨mantissa1, fracRest, hscanFrac, hfracRest⟩ :=
        NumberHelperDigitScanSourceLength afterFirst mantissa fraction fracTail
          hafterVal hfracDigits hfracTail hafterLen
      obtain ⟨nAfter, hoffFrac, hnAfterVal⟩ :=
        NumberHelperOffsetSourceLength afterFirst fracRest hafterLen (by
          rw [hfracRest, hafterVal]
          simp)
      have hnAfterEq : nAfter.val = fraction.length := by
        rw [hnAfterVal, hfracRest, hafterVal]
        simp
      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
        rw [hnegAfterVal, hnAfterEq,
          IScalar.min_IScalarTy_I64_eq, I64.min_eq,
          IScalar.max_IScalarTy_I64_eq, I64.max_eq]
        have hl := hlen
        rw [hsval, htailEq, hcs] at hl
        simp at hl
        constructor <;> omega
      obtain ⟨fracExponent, hfracExponent, hfracExponentVal⟩ :=
        Aeneas.Std.WP.spec_imp_exists
          (IScalar.cast_inBounds_spec .I64 negAfter hnegCastBounds)
      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]
        have hl := hlen
        rw [hsval, htailEq, hcs] at hl
        simp at hl
        constructor <;> omega
      obtain ⟨totalDigits, htotal, htotalVal⟩ :=
        Aeneas.Std.WP.spec_imp_exists
          (IScalar.add_spec htotalBounds.1 htotalBounds.2)
      by_cases htotalZero : totalDigits = 0#isize
      · unfold num.imp.dec2flt.parse.parse_partial_number
        simp [hnotempty, hscanInt, hoffInt, hsplitInt, hscanFrac, hoffFrac,
          hnegAfter, hfracExponent, htotal, htotalZero]
        norm_num
        simp only [UScalar.ofNat, UScalar.ofNatCore]
        simp [htotal, htotalZero]
      · have htotalPos : 0 < totalDigits.val := by
          have hb := IScalar.hBounds totalDigits
          have hz : totalDigits.val ≠ 0 := by
            intro hv
            apply htotalZero
            apply IScalar.eq_of_val_eq
            simpa using hv
          rw [htotalVal, hnDigitsEq, hnAfterEq] at hz ⊢
          omega
        have hsome : integer != [] \/ fraction != [] := by
          simp only [bne_iff_ne]
          by_contra hnone
          push_neg at hnone
          rcases hnone with ⟨hi, hf⟩
          subst integer
          subst fraction
          rw [htotalVal, hnDigitsEq, hnAfterEq] at htotalPos
          norm_num at htotalPos
        cases htailCase : fracTail with
        | nil =>
          exact False.elim (complete_spelling integer (some fraction) none
            hintDigits (by simpa using hfracDigits) hsome (by simp) (by
              rw [hsval, htailEq, hcs, htailCase]
              simp [List.append_assoc]))
        | cons q qs =>
          have hqsProp : qs.length <= Usize.max := by
            have hp := fracRest.property
            rw [hfracRest, htailCase] at hp
            simp at hp ⊢
            omega
          let afterFrac : Slice Std.U8 := ⟨qs, hqsProp⟩
          have hsplitFrac : core.slice.Slice.split_first fracRest =
              ok (some (q, afterFrac)) := by
            have hr : fracRest = (⟨q :: qs, by
                rw [← htailCase, ← hfracRest]
                exact fracRest.property⟩ : Slice Std.U8) :=
              (Slice.eq_iff _ _).2 (by simpa [htailCase] using hfracRest)
            rw [hr]
            simp [core.slice.Slice.split_first,
              dec2flt_model.ModelSliceSplitFirst, afterFrac]
          by_cases hfracMarker : q = 101#u8 \/ q = 69#u8
          · obtain ⟨upper, hmarkerByte⟩ : exists upper : Bool,
                q = if upper then 69#u8 else 101#u8 := by
              rcases hfracMarker with hq | hq
              · exact ⟨false, by simpa using hq⟩
              · exact ⟨true, by simpa using hq⟩
            let sign := scientific_sign qs
            let expBody := scientific_body qs
            have hqsSign : qs =
                (match sign with
                | none => []
                | some negative => [if negative then 45#u8 else 43#u8]) ++
                  expBody := by
              exact scientific_split qs
            have hunsigned : sign = none -> forall b rest,
                expBody = b :: rest -> b ≠ 45#u8 /\ b ≠ 43#u8 := by
              exact scientific_unsigned qs
            obtain ⟨expDigits, expTail, hbody, hexpDigits, hexpTail⟩ :=
              split_digits expBody
            have hsci : afterFrac.val =
                (match sign with
                | none => []
                | some negative => [if negative then 45#u8 else 43#u8]) ++
                  expDigits ++ expTail := by
              change qs = _
              rw [hqsSign, hbody, List.append_assoc]
            obtain hnoexp | hexp :=
              NumberHelperScientificClassificationSourceLength afterFrac sign
                expDigits expTail hexpDigits hexpTail hsci (by
                  intro hd hs b rest ht
                  apply hunsigned hs b rest
                  rw [hbody, hd]
                  simpa using ht)
            · rcases hnoexp with ⟨_, rest, hscientific⟩
              unfold num.imp.dec2flt.parse.parse_partial_number
              simp [hnotempty, hscanInt, hoffInt, hsplitInt, hscanFrac,
                hoffFrac, hnegAfter, hfracExponent, htotal, htotalPos,
                hsplitFrac]
              norm_num
              simp only [UScalar.ofNat, UScalar.ofNatCore]
              cases upper <;>
                simp at hmarkerByte <;>
                subst q <;>
                simp [htotal, htotalPos, hsplitFrac, h101Target, h69Target,
                  hscientific,
                  core.option.Option.Insts.CoreOpsTry_traitTry.branch,
                  core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
                  dec2flt_model.ModelOptionBranch,
                  dec2flt_model.ModelOptionFromResidual]
            · rcases hexp with ⟨hexpNe, parsedExp, sciRest, hscientific,
                  hsciRest, hexplo, hexphi, hexpshort, hexpnonnegative⟩
              cases htailExp : expTail with
              | nil =>
                exact False.elim (complete_spelling integer (some fraction)
                  (some (upper, sign, expDigits)) hintDigits hfracDigits hsome
                  ⟨hexpNe, hexpDigits⟩ (by
                    rw [hsval, htailEq, hcs, htailCase, hmarkerByte,
                      hqsSign, hbody, htailExp]
                    simp [List.append_assoc]))
              | cons z zs =>
                obtain ⟨consumed, hoffConsumed, hconsumedVal⟩ :=
                  NumberHelperOffsetSourceLength s sciRest hsourceLen (by
                    rw [hsciRest, htailExp]
                    have hl := congrArg List.length hsval
                    rw [htailEq, hcs, htailCase, hqsSign, hbody, htailExp] at hl
                    simp at hl ⊢
                    omega)
                have hcastBounds : 0 <= consumed.val /\
                    consumed.val <= UScalar.max .Usize := by
                  rw [hconsumedVal]
                  have hrestLe : sciRest.val.length <= s.val.length := by
                    rw [hsciRest, htailExp]
                    have hl := congrArg List.length hsval
                    rw [htailEq, hcs, htailCase, hqsSign, hbody, htailExp] at hl
                    simp at hl ⊢
                    omega
                  simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
                  omega
                obtain ⟨len, hcastLen, hlenVal⟩ :=
                  Aeneas.Std.WP.spec_imp_exists
                    (IScalar.hcast_inBounds_spec .Usize consumed hcastBounds)
                have hlenNe : len ≠ Slice.len s := by
                  intro heq
                  have heqv : (len.val : Int) = s.val.length := by
                    have h := congrArg UScalar.val heq
                    simpa [Slice.len_val] using h
                  have hrestPos : 0 < sciRest.val.length := by
                    rw [hsciRest, htailExp]
                    simp
                  have hlenConsumed : (len.val : Int) = consumed.val := by
                    norm_num at hlenVal
                    exact hlenVal
                  rw [hconsumedVal] at hlenConsumed
                  omega
                have hsuffixLenEq : qs.length =
                    (match sign with
                    | none => []
                    | some negative => [if negative then 45#u8 else 43#u8]).length +
                      (expDigits.length + expTail.length) := by
                  have hl := congrArg List.length hqsSign
                  rw [hbody] at hl
                  simpa using hl
                have hcombinedBounds : IScalar.min .I64 <=
                      fracExponent.val + parsedExp.val /\
                    fracExponent.val + parsedExp.val <= IScalar.max .I64 := by
                  have hparts := hlen
                  rw [hsval, htailEq, hcs, htailCase] at hparts
                  simp only [List.length_append, List.length_cons] at hparts
                  rw [hfracExponentVal, hnegAfterVal, hnAfterEq,
                    IScalar.min_IScalarTy_I64_eq, I64.min_eq,
                    IScalar.max_IScalarTy_I64_eq, I64.max_eq]
                  constructor
                  · by_cases hshort : expDigits.length <= 5
                    · have hsharp := hexpshort hshort
                      omega
                    · have hq : 6 <= expDigits.length := by omega
                      by_cases hnegative : sign = some true
                      · simp [hnegative] at hsuffixLenEq
                        rw [htailExp] at hsuffixLenEq
                        simp at hsuffixLenEq
                        omega
                      · have hnonnegative := hexpnonnegative hnegative
                        omega
                  · omega
                obtain ⟨combinedExponent, hcombinedExponent,
                    hcombinedExponentVal⟩ := Aeneas.Std.WP.spec_imp_exists
                  (IScalar.add_spec hcombinedBounds.1 hcombinedBounds.2)
                unfold num.imp.dec2flt.parse.parse_partial_number
                simp [hnotempty, hscanInt, hoffInt, hsplitInt, hscanFrac,
                  hoffFrac, hnegAfter, hfracExponent, htotal, htotalPos,
                  hsplitFrac]
                norm_num
                simp only [UScalar.ofNat, UScalar.ofNatCore]
                cases upper <;>
                  simp at hmarkerByte <;>
                  subst q <;>
                  simp [htotal, htotalPos, hsplitFrac, h101Target, h69Target,
                    hscientific, hcombinedExponent, hoffConsumed, hcastLen,
                    core.option.Option.Insts.CoreOpsTry_traitTry.branch,
                    dec2flt_model.ModelOptionBranch,
                    dec2flt_model.ModelOptionFromResidual]
                all_goals
                  by_cases hsmall : totalDigits.val <= 19
                  · refine ⟨some ({
                        exponent := combinedExponent
                        mantissa := mantissa1
                        negative := false
                        many_digits := false
                      }, len), ?_, ?_⟩
                    · simp [hsmall]
                    · intro d r ho
                      simp only [Option.some.injEq, Prod.mk.injEq] at ho
                      rcases ho with ⟨_, rfl⟩
                      intro hv
                      apply hlenNe
                      apply UScalar.eq_of_val_eq
                      simpa [Slice.len_val] using hv
                  · simp [hsmall]
                    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 simpa using hsubBounds.1)
                          (by simpa using hsubBounds.2))
                    rw [hnMore]
                    simp
                    obtain ⟨adjusted, hadjusted⟩ :=
                      NumberHelperAdjustManySourceLength s nMore hsourceLen (by
                        norm_num at hnMoreVal
                        omega) (by
                        norm_num at hnMoreVal
                        rw [hnMoreVal, htotalVal, hnDigitsEq, hnAfterEq]
                        have hl := congrArg List.length hsval
                        rw [htailEq, hcs] at hl
                        simp at hl
                        omega)
                    rw [hadjusted]
                    by_cases hpositive : 0 < adjusted.val
                    · simp [hpositive]
                      obtain ⟨mantissa2, exponent2, hmany⟩ :=
                        NumberHelperFractionalManyDigitsSourceLength s intRest
                          parsedExp integer fraction fracTail (by
                            simpa [htailEq, hcs, List.append_assoc] using hsval)
                          (by simpa [htailEq, hcs] using hintRest) hintDigits
                          hfracDigits hfracTail hsourceLen (by
                            have hb := hcombinedBounds.1
                            rw [hfracExponentVal, hnegAfterVal, hnAfterEq] at hb
                            simpa [IScalar.min_IScalarTy_I64_eq, I64.min_eq]
                              using hb) (by
                            rw [IScalar.max_IScalarTy_I64_eq, I64.max_eq]
                            have hl := hlen
                            rw [hsval, htailEq, hcs] at hl
                            simp at hl
                            omega)
                      rw [hmany]
                      refine ⟨some ({
                          exponent := exponent2
                          mantissa := mantissa2
                          negative := false
                          many_digits := true
                        }, len), rfl, ?_⟩
                      intro d r ho
                      simp only [Option.some.injEq, Prod.mk.injEq] at ho
                      rcases ho with ⟨_, rfl⟩
                      intro hv
                      apply hlenNe
                      apply UScalar.eq_of_val_eq
                      simpa [Slice.len_val] using hv
                    · simp [hpositive]
                      intro hv
                      apply hlenNe
                      apply UScalar.eq_of_val_eq
                      simpa [Slice.len_val] using hv
          · have hq101 : q ≠ 101#u8 := by tauto
            have hq69 : q ≠ 69#u8 := by tauto
            obtain ⟨consumed, hoffConsumed, hconsumedVal⟩ :=
              NumberHelperOffsetSourceLength s fracRest hsourceLen (by
                have hsLenEq := congrArg List.length hsval
                rw [htailEq, hcs, htailCase] at hsLenEq
                rw [hfracRest, htailCase]
                simp at hsLenEq ⊢
                omega)
            have hrestLe : fracRest.val.length <= s.val.length := by
              have hsLenEq := congrArg List.length hsval
              rw [htailEq, hcs, htailCase] at hsLenEq
              rw [hfracRest, htailCase]
              simp at hsLenEq ⊢
              omega
            have hcastBounds : 0 <= consumed.val /\
                consumed.val <= UScalar.max .Usize := by
              rw [hconsumedVal]
              simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
              omega
            obtain ⟨len, hcastLen, hlenVal⟩ :=
              Aeneas.Std.WP.spec_imp_exists
                (IScalar.hcast_inBounds_spec .Usize consumed hcastBounds)
            have hlenEq : len.val = integer.length + 1 + fraction.length := by
              norm_num at hlenVal
              rw [hconsumedVal, hsval, htailEq, hcs, hfracRest, htailCase]
                at hlenVal
              simp at hlenVal
              omega
            have hlenNe : len ≠ Slice.len s := by
              intro heq
              have heqv := congrArg UScalar.val heq
              simp [Slice.len_val, hlenEq, hsval, htailEq, hcs, htailCase]
                at heqv
              omega
            unfold num.imp.dec2flt.parse.parse_partial_number
            simp [hnotempty, hscanInt, hoffInt, hsplitInt, hscanFrac,
              hoffFrac, hnegAfter, hfracExponent, htotal, htotalPos,
              hsplitFrac, hq101, hq69, hoffConsumed, hcastLen]
            norm_num
            simp only [UScalar.ofNat, UScalar.ofNatCore]
            simp [htotal, htotalPos, hsplitFrac, hq101, hq69,
              hoffConsumed, hcastLen]
            split <;> try contradiction
            split <;> try contradiction
            split
            · rename_i hsmall
              refine ⟨some ({
                  exponent := fracExponent
                  mantissa := mantissa1
                  negative := false
                  many_digits := false
                }, len), ?_, ?_⟩
              · rfl
              · intro d r ho
                simp only [Option.some.injEq, Prod.mk.injEq] at ho
                rcases ho with ⟨_, rfl⟩
                intro hv
                apply hlenNe
                apply UScalar.eq_of_val_eq
                simpa [Slice.len_val] using hv
            · rename_i hsmall
              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 simpa using hsubBounds.1)
                    (by simpa using hsubBounds.2))
              rw [hnMore]
              simp
              obtain ⟨adjusted, hadjusted⟩ :=
                NumberHelperAdjustManySourceLength s nMore hsourceLen (by
                  norm_num at hnMoreVal
                  omega) (by
                  norm_num at hnMoreVal
                  rw [hnMoreVal, htotalVal, hnDigitsEq, hnAfterEq]
                  omega)
              rw [hadjusted]
              by_cases hpositive : 0 < adjusted.val
              · simp [hpositive]
                obtain ⟨mantissa2, exponent2, hmany⟩ :=
                  NumberHelperFractionalManyDigitsSourceLength s intRest
                    0#i64 integer fraction (q :: qs) (by
                      simpa [htailEq, hcs, htailCase, List.append_assoc]
                        using hsval) (by
                      simpa [htailEq, hcs, htailCase] using hintRest) hintDigits
                    hfracDigits (by
                      intro b rest h
                      exact hfracTail b rest (by simpa [htailCase] using h))
                    hsourceLen (by
                      rw [IScalar.min_IScalarTy_I64_eq, I64.min_eq]
                      norm_num
                      have hl := hlen
                      rw [hsval, htailEq, hcs, htailCase] at hl
                      simp at hl
                      omega) (by
                      rw [IScalar.max_IScalarTy_I64_eq, I64.max_eq]
                      norm_num
                      rw [htotalVal, hnDigitsEq, hnAfterEq] at hsmall
                      omega)
                rw [hmany]
                refine ⟨some ({
                    exponent := exponent2
                    mantissa := mantissa2
                    negative := false
                    many_digits := true
                  }, len), rfl, ?_⟩
                intro d r ho
                simp only [Option.some.injEq, Prod.mk.injEq] at ho
                rcases ho with ⟨_, rfl⟩
                intro hv
                apply hlenNe
                apply UScalar.eq_of_val_eq
                simpa [Slice.len_val] using hv
              · simp [hpositive]
                intro hv
                apply hlenNe
                apply UScalar.eq_of_val_eq
                simpa [Slice.len_val] using hv
    · cases c
      rename_i cbv
      let c : Std.U8 := @UScalar.mk .U8 cbv
      have hcbv : cbv ≠ 46 := by
        intro heq
        subst cbv
        exact hpoint (by rfl)
      have hpointMatch :
          (match (@UScalar.mk .U8 cbv) with
          | 46#uscalar => do
              let (s3, mantissa2) ←
                num.imp.dec2flt.parse.try_parse_digits afterFirst mantissa
              let nAfter ←
                SliceU8.Insts.Dec2flt_modelNumImpDec2fltCommonByteSlice.offset_from
                  s3 afterFirst
              let negAfter ← -. nAfter
              let fracExponent ← lift (IScalar.cast .I64 negAfter)
              ok (s3, mantissa2, nAfter, fracExponent)
          | _ => ok (intRest, mantissa, 0#isize, 0#i64)) =
            ok (intRest, mantissa, 0#isize, 0#i64) := by
        split <;> try contradiction
        all_goals rfl
      by_cases hintegerEmpty : integer = []
      · have hnzero : nDigits = 0#isize := by
          apply IScalar.eq_of_val_eq
          rw [hnDigitsEq, hintegerEmpty]
          norm_num
        have haddZeroZero : (0#isize + 0#isize) = ok 0#isize := by
          simpa [hnzero] using haddZero
        unfold num.imp.dec2flt.parse.parse_partial_number
        simp [hnotempty, hscanInt, hoffInt, hsplitInt]
        split <;> try contradiction
        simp [haddZeroZero, hnzero]
      · have hnpos : 0 < nDigits.val := by
          rw [hnDigitsEq]
          have := List.length_pos_of_ne_nil hintegerEmpty
          omega
        by_cases hmarker : c = 101#u8 \/ c = 69#u8
        · obtain ⟨upper, hupper⟩ : exists upper : Bool,
              c = if upper then 69#u8 else 101#u8 := by
            rcases hmarker with hc | hc
            · exact ⟨false, by simpa using hc⟩
            · exact ⟨true, by simpa using hc⟩
          have hmarkerByte : (@UScalar.mk .U8 cbv) =
              if upper then 69#u8 else 101#u8 := by
            simpa [c] using hupper
          let sign := scientific_sign cs
          let expBody := scientific_body cs
          have hcsSign : cs =
              (match sign with
              | none => []
              | some negative => [if negative then 45#u8 else 43#u8]) ++
                expBody := by
            exact scientific_split cs
          have hunsigned : sign = none -> forall b rest,
              expBody = b :: rest -> b ≠ 45#u8 /\ b ≠ 43#u8 := by
            exact scientific_unsigned cs
          obtain ⟨expDigits, expTail, hbody, hexpDigits, hexpTail⟩ :=
            split_digits expBody
          have hsci : afterFirst.val =
              (match sign with
              | none => []
              | some negative => [if negative then 45#u8 else 43#u8]) ++
                expDigits ++ expTail := by
            change cs = _
            rw [hcsSign, hbody, List.append_assoc]
          obtain hnoexp | hexp :=
            NumberHelperScientificClassificationSourceLength afterFirst sign
              expDigits expTail hexpDigits hexpTail hsci (by
                intro hd hs b rest ht
                apply hunsigned hs b rest
                rw [hbody, hd]
                simpa using ht)
          · rcases hnoexp with ⟨_, rest, hscientific⟩
            unfold num.imp.dec2flt.parse.parse_partial_number
            simp [hnotempty, hscanInt, hoffInt, hsplitInt]
            split <;> try contradiction
            simp [haddZero, hnpos, hsplitInt]
            cases upper with
            | false =>
              have hb := congrArg UScalar.bv hmarkerByte
              simp at hb
              subst cbv
              simp [h101Target, h69Target, hscientific,
                core.option.Option.Insts.CoreOpsTry_traitTry.branch,
                core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
                dec2flt_model.ModelOptionBranch,
                dec2flt_model.ModelOptionFromResidual]
            | true =>
              have hb := congrArg UScalar.bv hmarkerByte
              simp at hb
              subst cbv
              simp [h101Target, h69Target, hscientific,
                core.option.Option.Insts.CoreOpsTry_traitTry.branch,
                core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
                dec2flt_model.ModelOptionBranch,
                dec2flt_model.ModelOptionFromResidual]
          · rcases hexp with ⟨hexpNe, parsedExp, sciRest, hscientific,
                hsciRest, hexplo, hexphi, hexpshort, hexpnonnegative⟩
            cases htailExp : expTail with
            | nil =>
              exact False.elim (complete_spelling integer none
                (some (upper, sign, expDigits)) hintDigits (by simp)
                (by left; simpa only [bne_iff_ne] using hintegerEmpty)
                ⟨hexpNe, hexpDigits⟩ (by
                  rw [hsval, htailEq, hmarkerByte, hcsSign, hbody, htailExp]
                  simp [List.append_assoc]))
            | cons z zs =>
              obtain ⟨consumed, hoffConsumed, hconsumedVal⟩ :=
                NumberHelperOffsetSourceLength s sciRest hsourceLen (by
                  rw [hsciRest, htailExp]
                  have hl := congrArg List.length hsval
                  rw [htailEq, hcsSign, hbody, htailExp] at hl
                  simp at hl ⊢
                  omega)
              have hcastBounds : 0 <= consumed.val /\
                  consumed.val <= UScalar.max .Usize := by
                rw [hconsumedVal]
                have hrestLe : sciRest.val.length <= s.val.length := by
                  rw [hsciRest, htailExp]
                  have hl := congrArg List.length hsval
                  rw [htailEq, hcsSign, hbody, htailExp] at hl
                  simp at hl ⊢
                  omega
                simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
                omega
              obtain ⟨len, hcastLen, hlenVal⟩ :=
                Aeneas.Std.WP.spec_imp_exists
                  (IScalar.hcast_inBounds_spec .Usize consumed hcastBounds)
              have hlenNe : len ≠ Slice.len s := by
                intro heq
                have heqv : (len.val : Int) = s.val.length := by
                  have h := congrArg UScalar.val heq
                  simpa [Slice.len_val] using h
                have hrestPos : 0 < sciRest.val.length := by
                  rw [hsciRest, htailExp]
                  simp
                have hlenConsumed : (len.val : Int) = consumed.val := by
                  norm_num at hlenVal
                  exact hlenVal
                rw [hconsumedVal] at hlenConsumed
                omega
              have haddBounds : IScalar.min .I64 <=
                    (0#i64).val + parsedExp.val /\
                  (0#i64).val + parsedExp.val <= IScalar.max .I64 := by
                rw [IScalar.min_IScalarTy_I64_eq, I64.min_eq,
                  IScalar.max_IScalarTy_I64_eq, I64.max_eq]
                norm_num
                omega
              obtain ⟨combined, haddExp, hcombinedVal⟩ :=
                Aeneas.Std.WP.spec_imp_exists
                  (IScalar.add_spec haddBounds.1 haddBounds.2)
              have hcombined : combined = parsedExp := by
                apply IScalar.eq_of_val_eq
                norm_num at hcombinedVal
                exact hcombinedVal
              subst combined
              unfold num.imp.dec2flt.parse.parse_partial_number
              simp [hnotempty, hscanInt, hoffInt, hsplitInt]
              split <;> try contradiction
              simp [haddZero, hnpos, hsplitInt]
              cases upper <;>
                have hb := congrArg UScalar.bv hmarkerByte <;>
                simp at hb <;>
                subst cbv <;>
                simp [h101Target, h69Target, hscientific, haddExp,
                  hoffConsumed, hcastLen,
                  core.option.Option.Insts.CoreOpsTry_traitTry.branch,
                  dec2flt_model.ModelOptionBranch,
                  dec2flt_model.ModelOptionFromResidual]
              all_goals
                by_cases hsmall : nDigits.val <= 19
                · refine ⟨some ({
                      exponent := parsedExp
                      mantissa := mantissa
                      negative := false
                      many_digits := false
                    }, len), ?_, ?_⟩
                  · simp [hsmall]
                  · intro d r ho
                    simp only [Option.some.injEq, Prod.mk.injEq] at ho
                    rcases ho with ⟨_, rfl⟩
                    intro hv
                    apply hlenNe
                    apply UScalar.eq_of_val_eq
                    simpa [Slice.len_val] using hv
                · simp [hsmall]
                  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 simpa using hsubBounds.1)
                        (by simpa using hsubBounds.2))
                  rw [hnMore]
                  simp
                  obtain ⟨adjusted, hadjusted⟩ :=
                    NumberHelperAdjustManySourceLength s nMore hsourceLen (by
                      norm_num at hnMoreVal
                      omega) (by
                      norm_num at hnMoreVal
                      rw [hnMoreVal, hnDigitsEq]
                      omega)
                  rw [hadjusted]
                  by_cases hpositive : 0 < adjusted.val
                  · simp [hpositive]
                    obtain ⟨mantissa2, exponent2, hmany⟩ :=
                      NumberHelperIntegralManyDigitsSourceLength s intRest
                        parsedExp nMore adjusted integer intTailBytes hsval
                        hintRest hintDigits hintTail (by
                          intro b rest h
                          rw [htailEq] at h
                          injection h with hbc _
                          subst b
                          exact hpoint) hsourceLen (by
                          norm_num at hnMoreVal
                          rw [hnMoreVal, hnDigitsEq]) hadjusted hpositive (by
                          rw [IScalar.max_IScalarTy_I64_eq, I64.max_eq]
                          have hl := hlen
                          rw [hsval] at hl
                          simp at hl
                          omega)
                    rw [hmany]
                    refine ⟨some ({
                        exponent := exponent2
                        mantissa := mantissa2
                        negative := false
                        many_digits := true
                      }, len), rfl, ?_⟩
                    intro d r ho
                    simp only [Option.some.injEq, Prod.mk.injEq] at ho
                    rcases ho with ⟨_, rfl⟩
                    intro hv
                    apply hlenNe
                    apply UScalar.eq_of_val_eq
                    simpa [Slice.len_val] using hv
                  · simp [hpositive]
                    intro hv
                    apply hlenNe
                    apply UScalar.eq_of_val_eq
                    simpa [Slice.len_val] using hv
        · have hc101 : c ≠ 101#u8 := by tauto
          have hc69 : c ≠ 69#u8 := by tauto
          have hcbv101 : cbv ≠ (101 : BitVec 8) := by
            intro heq
            apply hc101
            exact congrArg (fun v : BitVec 8 => (@UScalar.mk .U8 v)) heq
          have hcbv69 : cbv ≠ (69 : BitVec 8) := by
            intro heq
            apply hc69
            exact congrArg (fun v : BitVec 8 => (@UScalar.mk .U8 v)) heq
          obtain ⟨consumed, hoffConsumed, hconsumedVal⟩ :=
            NumberHelperOffsetSourceLength s intRest hsourceLen (by
              rw [hintRest, hsval]
              simp)
          have hcastBounds : 0 <= consumed.val /\
              consumed.val <= UScalar.max .Usize := by
            rw [hconsumedVal]
            simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
            omega
          obtain ⟨len, hcastLen, hlenVal⟩ :=
            Aeneas.Std.WP.spec_imp_exists
              (IScalar.hcast_inBounds_spec .Usize consumed hcastBounds)
          have hlenEq : len.val = integer.length := by
            norm_num at hlenVal
            rw [hconsumedVal, hintRest, hsval] at hlenVal
            simp at hlenVal
            omega
          have hlenNe : len ≠ Slice.len s := by
            intro heq
            have heqv := congrArg UScalar.val heq
            simp [Slice.len_val, hlenEq, hsval, htailEq] at heqv
          unfold num.imp.dec2flt.parse.parse_partial_number
          simp [hnotempty, hscanInt, hoffInt, hsplitInt]
          split <;> try contradiction
          simp [haddZero, hnpos, hsplitInt, h101Target, h69Target, hc101,
            hc69, hcbv101, hcbv69, hoffConsumed, hcastLen]
          split <;> try contradiction
          split <;> try contradiction
          by_cases hsmall : nDigits.val <= 19
          · refine ⟨some ({
                exponent := 0#i64
                mantissa := mantissa
                negative := false
                many_digits := false
              }, len), ?_, ?_⟩
            · simp [hsmall]
            · intro d r ho
              simp only [Option.some.injEq, Prod.mk.injEq] at ho
              rcases ho with ⟨_, rfl⟩
              intro hv
              apply hlenNe
              apply UScalar.eq_of_val_eq
              simpa [Slice.len_val] using hv
          · simp [hsmall]
            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 simpa using hsubBounds.1)
                  (by simpa using hsubBounds.2))
            rw [hnMore]
            simp
            obtain ⟨adjusted, hadjusted⟩ :=
              NumberHelperAdjustManySourceLength s nMore hsourceLen (by
                norm_num at hnMoreVal
                omega) (by
                norm_num at hnMoreVal
                rw [hnMoreVal, hnDigitsEq, hsval]
                simp
                omega)
            rw [hadjusted]
            by_cases hpositive : 0 < adjusted.val
            · simp [hpositive]
              obtain ⟨mantissa2, exponent2, hmany⟩ :=
                NumberHelperIntegralManyDigitsSourceLength s intRest 0#i64
                  nMore adjusted integer (c :: cs) (by
                    rw [htailEq] at hsval
                    simpa [c] using hsval) (by
                    rw [htailEq] at hintRest
                    simpa [c] using hintRest) hintDigits (by
                    intro b rest h
                    apply hintTail b rest
                    rw [htailEq]
                    simpa [c] using h) (by
                    intro b rest h
                    injection h with hbc _
                    subst b
                    simpa [c] using hpoint) hsourceLen (by
                    norm_num at hnMoreVal
                    rw [hnMoreVal, hnDigitsEq]) hadjusted hpositive (by
                    rw [IScalar.max_IScalarTy_I64_eq, I64.max_eq]
                    norm_num
                    have hl := hlen
                    rw [hsval] at hl
                    simp at hl
                    omega)
              rw [hmany]
              refine ⟨some ({
                  exponent := exponent2
                  mantissa := mantissa2
                  negative := false
                  many_digits := true
                }, len), rfl, ?_⟩
              intro d r ho
              simp only [Option.some.injEq, Prod.mk.injEq] at ho
              rcases ho with ⟨_, rfl⟩
              intro hv
              apply hlenNe
              apply UScalar.eq_of_val_eq
              simpa [Slice.len_val] using hv
            · simp [hpositive]
              intro hv
              apply hlenNe
              apply UScalar.eq_of_val_eq
              simpa [Slice.len_val] using hv


end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.NumberHelperDigitScanSourceLength
import Tablet.NumberHelperOffsetSourceLength
import Tablet.NumberHelperAdjustManySourceLength
import Tablet.NumberHelperIntegralManyDigitsSourceLength
import Tablet.NumberHelperFractionalManyDigitsSourceLength
import Tablet.NumberHelperScientificPrefixSafeLength
import Tablet.NumberHelperScientificClassificationSourceLength
import Tablet.NumberHelperScientificExponentBounds
import Tablet.DecimalGoalVocabularyDefault
import Tablet.SourceValidByteSlice
import Tablet.ModelSliceSplitFirst
import Tablet.ModelOptionBranch
import Tablet.ModelOptionFromResidual
import Tablet.num_imp_dec2flt_parse_parse_partial_number

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

namespace dec2flt_model

-- [TABLET NODE: NumberHelperPartialNumberSafeLength]
theorem NumberHelperPartialNumberSafeLength :
    forall s : Slice Std.U8,
      SourceValidByteSlice s -> s.val != [] ->
      s.val.length <= 9223372036854120459 ->
      (Not (exists x : DecimalLexeme,
        x.leadingSign = none /\
        DecimalGoalVocabularyDefault.validNumeric x /\
        DecimalGoalVocabularyDefault.bytes s =
          DecimalGoalVocabularyDefault.renderNumeric x)) ->
      exists o,
        num.imp.dec2flt.parse.parse_partial_number s = ok o /\
        forall (d : num.imp.dec2flt.decimal.Decimal) (r : Std.Usize),
          o = some (d, r) -> Not (r = Slice.len s) := by
-- BODY
  intro s hsource hne hlen hinvalid
  have hsourceLen : s.val.length <= 9223372036854775807 := by
    simp [SourceValidByteSlice] at hsource
    exact hsource
  have split_digits : forall bs : List Std.U8,
      exists digits tail,
        bs = digits ++ tail /\
        (forall b, List.Mem b digits -> 48 <= b.val /\ b.val <= 57) /\
        (forall b rest, tail = b :: rest ->
          Not (48 <= b.val /\ b.val <= 57)) := by
    intro bs
    induction bs with
    | nil => exact ⟨[], [], rfl, (by intro b hb; cases hb),
        (by intro b rest h; cases h)⟩
    | cons b bs ih =>
      by_cases hb : 48 <= b.val /\ b.val <= 57
      · obtain ⟨digits, tail, hbs, hdigits, htail⟩ := ih
        refine ⟨b :: digits, tail, ?_, ?_, htail⟩
        · simp [hbs]
        · intro c hc
          rcases List.mem_cons.mp hc with rfl | hc
          · exact hb
          · exact hdigits c hc
      · exact ⟨[], b :: bs, rfl, (by intro c hc; cases hc), by
          intro c rest h
          cases h
          exact hb⟩
  let scientific_sign : List Std.U8 -> Option Bool := fun bs =>
    match bs with
    | [] => none
    | b :: _ => if b = 45#u8 then some true
      else if b = 43#u8 then some false else none
  let scientific_body : List Std.U8 -> List Std.U8 := fun bs =>
    match bs with
    | [] => []
    | b :: rest => if b = 45#u8 \/ b = 43#u8 then rest else b :: rest
  have scientific_split : forall bs : List Std.U8,
      bs = (match scientific_sign bs with
        | none => []
        | some negative => [if negative then 45#u8 else 43#u8]) ++
          scientific_body bs := by
    intro bs
    cases bs with
    | nil => simp [scientific_sign, scientific_body]
    | cons b rest =>
      by_cases hm : b = 45#u8
      · subst b
        simp [scientific_sign, scientific_body]
      · by_cases hp : b = 43#u8
        · subst b
          simp [scientific_sign, scientific_body]
        · simp [scientific_sign, scientific_body, hm, hp]
  have scientific_unsigned : forall bs : List Std.U8,
      scientific_sign bs = none -> forall b rest,
        scientific_body bs = b :: rest -> b ≠ 45#u8 /\ b ≠ 43#u8 := by
    intro bs
    cases bs with
    | nil => simp [scientific_body]
    | cons b rest =>
      by_cases hm : b = 45#u8
      · subst b
        simp [scientific_sign]
      · by_cases hp : b = 43#u8
        · subst b
          simp [scientific_sign, hm]
        · simp only [scientific_sign, scientific_body, hm, hp, if_false,
            or_false]
          intro _ c cs h
          injection h with hbc _
          subst c
          exact ⟨hm, hp⟩
  have render_digits : forall bs : List Std.U8,
      (forall b, List.Mem b bs -> 48 <= b.val /\ b.val <= 57) ->
      List.map (fun b : Std.U8 => b.val) bs =
        List.map (fun d : Nat => 48 + d)
          (List.map (fun b : Std.U8 => b.val - 48) bs) := by
    intro bs hbs
    induction bs with
    | nil => rfl
    | cons b bs ih =>
      have hb := hbs b List.mem_cons_self
      have hrest : forall c, List.Mem c bs -> 48 <= c.val /\ c.val <= 57 := by
        intro c hc
        exact hbs c (List.mem_cons_of_mem b hc)
      simp [ih hrest]
      omega
  have complete_spelling : forall (integer : List Std.U8)
      (fraction : Option (List Std.U8))
      (expo : Option (Bool × Option Bool × List Std.U8)),
      (forall b, List.Mem b integer -> 48 <= b.val /\ b.val <= 57) ->
      (match fraction with
        | none => True
        | some ds => forall b, List.Mem b ds ->
            48 <= b.val /\ b.val <= 57) ->
      (integer != [] \/
        match fraction with | none => False | some ds => ds != []) ->
      (match expo with
        | none => True
        | some (_, _, ds) => ds != [] /\
            forall b, List.Mem b ds -> 48 <= b.val /\ b.val <= 57) ->
      s.val = integer ++
        (match fraction with | none => [] | some ds => 46#u8 :: ds) ++
        (match expo with
          | none => []
          | some (upper, sign, ds) =>
              (if upper then 69#u8 else 101#u8) ::
              (match sign with
                | none => []
                | some neg => [if neg then 45#u8 else 43#u8]) ++ ds) ->
      False := by
    intro integer fraction expo hint hfrac hsome hexpo hs
    apply hinvalid
    let x : DecimalLexeme := {
      leadingSign := none
      integerDigits := integer.map (fun b => b.val - 48)
      fractionDigits := fraction.map
        (fun ds => ds.map (fun b => b.val - 48))
      exponent := expo.map (fun e =>
        (e.1, e.2.1, e.2.2.map (fun b => b.val - 48)))
    }
    refine ⟨x, rfl, ?_, ?_⟩
    · simp [DecimalGoalVocabularyDefault, x]
      constructor
      · intro d hd
        have := hint d hd
        omega
      constructor
      · cases fraction with
        | none => simp
        | some fs =>
          simp only [Option.map_some]
          intro d hd
          obtain ⟨b, hb, rfl⟩ := List.mem_map.mp hd
          have := hfrac b hb
          omega
      constructor
      · cases fraction <;> simpa using hsome
      · cases expo with
        | none => simp
        | some e =>
          rcases e with ⟨upper, sign, es⟩
          simp at hexpo ⊢
          refine ⟨hexpo.1, ?_⟩
          intro d hd
          have := hexpo.2 d hd
          omega
    · simp [DecimalGoalVocabularyDefault, x]
      rw [hs]
      simp only [List.map_append, List.map_cons]
      have hintRender :
          List.map ((fun d : Nat => 48 + d) ∘
            fun b : Std.U8 => b.val - 48) integer =
          List.map (fun b : Std.U8 => b.val) integer := by
        simpa [List.map_map] using (render_digits integer hint).symm
      rw [hintRender]
      cases fraction with
      | none =>
        simp only [Option.map_none]
        simp at hfrac
        cases expo with
        | none => simp
        | some e =>
          rcases e with ⟨upper, sign, es⟩
          simp only [Option.map_some, List.map_map]
          simp at hexpo ⊢
          have hexpRender :
              List.map ((fun d : Nat => 48 + d) ∘
                fun b : Std.U8 => b.val - 48) es =
              List.map (fun b : Std.U8 => b.val) es := by
            simpa [List.map_map] using (render_digits es hexpo.2).symm
          rw [hexpRender]
          cases upper <;> cases sign with
          | none => norm_num
          | some neg => cases neg <;> norm_num
      | some fs =>
        simp only [Option.map_some, List.map_map]
        simp at hfrac
        have hfracRender :
            List.map ((fun d : Nat => 48 + d) ∘
              fun b : Std.U8 => b.val - 48) fs =
            List.map (fun b : Std.U8 => b.val) fs := by
          simpa [List.map_map] using (render_digits fs hfrac).symm
        rw [hfracRender]
        cases expo with
        | none => simp
        | some e =>
          rcases e with ⟨upper, sign, es⟩
          simp only [Option.map_some, List.map_map]
          simp at hexpo ⊢
          have hexpRender :
              List.map ((fun d : Nat => 48 + d) ∘
                fun b : Std.U8 => b.val - 48) es =
              List.map (fun b : Std.U8 => b.val) es := by
            simpa [List.map_map] using (render_digits es hexpo.2).symm
          rw [hexpRender]
          cases upper <;> cases sign with
          | none => norm_num
          | some neg => cases neg <;> norm_num
  obtain ⟨integer, intTailBytes, hsval, hintDigits, hintTail⟩ :=
    split_digits s.val
  obtain ⟨mantissa, intRest, hscanInt, hintRest⟩ :=
    NumberHelperDigitScanSourceLength s 0#u64 integer intTailBytes
      hsval hintDigits hintTail hsourceLen
  obtain ⟨nDigits, hoffInt, hnDigitsVal⟩ :=
    NumberHelperOffsetSourceLength s intRest hsourceLen (by
      rw [hintRest, hsval]
      simp)
  have hnDigitsEq : nDigits.val = integer.length := by
    rw [hnDigitsVal, hintRest, hsval]
    simp
  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 hnotempty : Not (s.val = []) := by simpa using hne
  cases htailEq : intTailBytes with
  | nil =>
    have hintegerNeProp : integer ≠ [] := by
      intro hi
      rw [hi, htailEq] at hsval
      simp at hsval
      exact hnotempty hsval
    have hintegerNe : integer != [] := by
      simpa only [bne_iff_ne] using hintegerNeProp
    exact False.elim (complete_spelling integer none none hintDigits (by
      simp) (by left; exact hintegerNe) (by simp) (by
        simpa [htailEq] using hsval))
  | cons c cs =>
    have hintRestVal : intRest.val = c :: cs := by simpa [htailEq] using hintRest
    have hcsProp : cs.length <= Usize.max := by
      have hp := intRest.property
      rw [hintRestVal] at hp
      simp only [List.length_cons] at hp
      omega
    let afterFirst : Slice Std.U8 := ⟨cs, hcsProp⟩
    have h46Target : (46#u8 : Std.U8) = 46#uscalar := by
      apply UScalar.eq_of_val_eq
      rfl
    have h101Target : (101#u8 : Std.U8) = 101#uscalar := by
      apply UScalar.eq_of_val_eq
      rfl
    have h69Target : (69#u8 : Std.U8) = 69#uscalar := by
      apply UScalar.eq_of_val_eq
      rfl
    have hsplitInt : core.slice.Slice.split_first intRest =
        ok (some (c, afterFirst)) := by
      have hirest : intRest = (⟨c :: cs, by simpa [hintRestVal] using
        intRest.property⟩ : Slice Std.U8) := (Slice.eq_iff _ _).2 hintRestVal
      rw [hirest]
      simp [core.slice.Slice.split_first, dec2flt_model.ModelSliceSplitFirst,
        afterFirst]
    by_cases hpoint : c = 46#u8
    · subst c
      obtain ⟨fraction, fracTail, hcs, hfracDigits, hfracTail⟩ :=
        split_digits cs
      have hafterVal : afterFirst.val = fraction ++ fracTail := by
        simp [afterFirst, hcs]
      have hafterLen : afterFirst.val.length <= 9223372036854775807 := by
        rw [hafterVal]
        rw [hsval, htailEq, hcs] at hlen
        simp at hlen
        rw [List.length_append]
        omega
      obtain ⟨mantissa1, fracRest, hscanFrac, hfracRest⟩ :=
        NumberHelperDigitScanSourceLength afterFirst mantissa fraction fracTail
          hafterVal hfracDigits hfracTail hafterLen
      obtain ⟨nAfter, hoffFrac, hnAfterVal⟩ :=
        NumberHelperOffsetSourceLength afterFirst fracRest hafterLen (by
          rw [hfracRest, hafterVal]
          simp)
      have hnAfterEq : nAfter.val = fraction.length := by
        rw [hnAfterVal, hfracRest, hafterVal]
        simp
      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
        rw [hnegAfterVal, hnAfterEq,
          IScalar.min_IScalarTy_I64_eq, I64.min_eq,
          IScalar.max_IScalarTy_I64_eq, I64.max_eq]
        have hl := hlen
        rw [hsval, htailEq, hcs] at hl
        simp at hl
        constructor <;> omega
      obtain ⟨fracExponent, hfracExponent, hfracExponentVal⟩ :=
        Aeneas.Std.WP.spec_imp_exists
          (IScalar.cast_inBounds_spec .I64 negAfter hnegCastBounds)
      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]
        have hl := hlen
        rw [hsval, htailEq, hcs] at hl
        simp at hl
        constructor <;> omega
      obtain ⟨totalDigits, htotal, htotalVal⟩ :=
        Aeneas.Std.WP.spec_imp_exists
          (IScalar.add_spec htotalBounds.1 htotalBounds.2)
      by_cases htotalZero : totalDigits = 0#isize
      · unfold num.imp.dec2flt.parse.parse_partial_number
        simp [hnotempty, hscanInt, hoffInt, hsplitInt, hscanFrac, hoffFrac,
          hnegAfter, hfracExponent, htotal, htotalZero]
        norm_num
        simp only [UScalar.ofNat, UScalar.ofNatCore]
        simp [htotal, htotalZero]
      · have htotalPos : 0 < totalDigits.val := by
          have hb := IScalar.hBounds totalDigits
          have hz : totalDigits.val ≠ 0 := by
            intro hv
            apply htotalZero
            apply IScalar.eq_of_val_eq
            simpa using hv
          rw [htotalVal, hnDigitsEq, hnAfterEq] at hz ⊢
          omega
        have hsome : integer != [] \/ fraction != [] := by
          simp only [bne_iff_ne]
          by_contra hnone
          push_neg at hnone
          rcases hnone with ⟨hi, hf⟩
          subst integer
          subst fraction
          rw [htotalVal, hnDigitsEq, hnAfterEq] at htotalPos
          norm_num at htotalPos
        cases htailCase : fracTail with
        | nil =>
          exact False.elim (complete_spelling integer (some fraction) none
            hintDigits (by simpa using hfracDigits) hsome (by simp) (by
              rw [hsval, htailEq, hcs, htailCase]
              simp [List.append_assoc]))
        | cons q qs =>
          have hqsProp : qs.length <= Usize.max := by
            have hp := fracRest.property
            rw [hfracRest, htailCase] at hp
            simp at hp ⊢
            omega
          let afterFrac : Slice Std.U8 := ⟨qs, hqsProp⟩
          have hsplitFrac : core.slice.Slice.split_first fracRest =
              ok (some (q, afterFrac)) := by
            have hr : fracRest = (⟨q :: qs, by
                rw [← htailCase, ← hfracRest]
                exact fracRest.property⟩ : Slice Std.U8) :=
              (Slice.eq_iff _ _).2 (by simpa [htailCase] using hfracRest)
            rw [hr]
            simp [core.slice.Slice.split_first,
              dec2flt_model.ModelSliceSplitFirst, afterFrac]
          by_cases hfracMarker : q = 101#u8 \/ q = 69#u8
          · obtain ⟨upper, hmarkerByte⟩ : exists upper : Bool,
                q = if upper then 69#u8 else 101#u8 := by
              rcases hfracMarker with hq | hq
              · exact ⟨false, by simpa using hq⟩
              · exact ⟨true, by simpa using hq⟩
            let sign := scientific_sign qs
            let expBody := scientific_body qs
            have hqsSign : qs =
                (match sign with
                | none => []
                | some negative => [if negative then 45#u8 else 43#u8]) ++
                  expBody := by
              exact scientific_split qs
            have hunsigned : sign = none -> forall b rest,
                expBody = b :: rest -> b ≠ 45#u8 /\ b ≠ 43#u8 := by
              exact scientific_unsigned qs
            obtain ⟨expDigits, expTail, hbody, hexpDigits, hexpTail⟩ :=
              split_digits expBody
            have hsci : afterFrac.val =
                (match sign with
                | none => []
                | some negative => [if negative then 45#u8 else 43#u8]) ++
                  expDigits ++ expTail := by
              change qs = _
              rw [hqsSign, hbody, List.append_assoc]
            obtain hnoexp | hexp :=
              NumberHelperScientificClassificationSourceLength afterFrac sign
                expDigits expTail hexpDigits hexpTail hsci (by
                  intro hd hs b rest ht
                  apply hunsigned hs b rest
                  rw [hbody, hd]
                  simpa using ht)
            · rcases hnoexp with ⟨_, rest, hscientific⟩
              unfold num.imp.dec2flt.parse.parse_partial_number
              simp [hnotempty, hscanInt, hoffInt, hsplitInt, hscanFrac,
                hoffFrac, hnegAfter, hfracExponent, htotal, htotalPos,
                hsplitFrac]
              norm_num
              simp only [UScalar.ofNat, UScalar.ofNatCore]
              cases upper <;>
                simp at hmarkerByte <;>
                subst q <;>
                simp [htotal, htotalPos, hsplitFrac, h101Target, h69Target,
                  hscientific,
                  core.option.Option.Insts.CoreOpsTry_traitTry.branch,
                  core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
                  dec2flt_model.ModelOptionBranch,
                  dec2flt_model.ModelOptionFromResidual]
            · rcases hexp with ⟨hexpNe, parsedExp, sciRest, hscientific,
                  hsciRest, hexplo, hexphi, hexpshort, hexpnonnegative⟩
              cases htailExp : expTail with
              | nil =>
                exact False.elim (complete_spelling integer (some fraction)
                  (some (upper, sign, expDigits)) hintDigits hfracDigits hsome
                  ⟨hexpNe, hexpDigits⟩ (by
                    rw [hsval, htailEq, hcs, htailCase, hmarkerByte,
                      hqsSign, hbody, htailExp]
                    simp [List.append_assoc]))
              | cons z zs =>
                obtain ⟨consumed, hoffConsumed, hconsumedVal⟩ :=
                  NumberHelperOffsetSourceLength s sciRest hsourceLen (by
                    rw [hsciRest, htailExp]
                    have hl := congrArg List.length hsval
                    rw [htailEq, hcs, htailCase, hqsSign, hbody, htailExp] at hl
                    simp at hl ⊢
                    omega)
                have hcastBounds : 0 <= consumed.val /\
                    consumed.val <= UScalar.max .Usize := by
                  rw [hconsumedVal]
                  have hrestLe : sciRest.val.length <= s.val.length := by
                    rw [hsciRest, htailExp]
                    have hl := congrArg List.length hsval
                    rw [htailEq, hcs, htailCase, hqsSign, hbody, htailExp] at hl
                    simp at hl ⊢
                    omega
                  simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
                  omega
                obtain ⟨len, hcastLen, hlenVal⟩ :=
                  Aeneas.Std.WP.spec_imp_exists
                    (IScalar.hcast_inBounds_spec .Usize consumed hcastBounds)
                have hlenNe : len ≠ Slice.len s := by
                  intro heq
                  have heqv : (len.val : Int) = s.val.length := by
                    have h := congrArg UScalar.val heq
                    simpa [Slice.len_val] using h
                  have hrestPos : 0 < sciRest.val.length := by
                    rw [hsciRest, htailExp]
                    simp
                  have hlenConsumed : (len.val : Int) = consumed.val := by
                    norm_num at hlenVal
                    exact hlenVal
                  rw [hconsumedVal] at hlenConsumed
                  omega
                have hsuffixLenEq : qs.length =
                    (match sign with
                    | none => []
                    | some negative => [if negative then 45#u8 else 43#u8]).length +
                      (expDigits.length + expTail.length) := by
                  have hl := congrArg List.length hqsSign
                  rw [hbody] at hl
                  simpa using hl
                have hcombinedBounds : IScalar.min .I64 <=
                      fracExponent.val + parsedExp.val /\
                    fracExponent.val + parsedExp.val <= IScalar.max .I64 := by
                  have hparts := hlen
                  rw [hsval, htailEq, hcs, htailCase] at hparts
                  simp only [List.length_append, List.length_cons] at hparts
                  rw [hfracExponentVal, hnegAfterVal, hnAfterEq,
                    IScalar.min_IScalarTy_I64_eq, I64.min_eq,
                    IScalar.max_IScalarTy_I64_eq, I64.max_eq]
                  constructor
                  · by_cases hshort : expDigits.length <= 5
                    · have hsharp := hexpshort hshort
                      omega
                    · have hq : 6 <= expDigits.length := by omega
                      by_cases hnegative : sign = some true
                      · simp [hnegative] at hsuffixLenEq
                        rw [htailExp] at hsuffixLenEq
                        simp at hsuffixLenEq
                        omega
                      · have hnonnegative := hexpnonnegative hnegative
                        omega
                  · omega
                obtain ⟨combinedExponent, hcombinedExponent,
                    hcombinedExponentVal⟩ := Aeneas.Std.WP.spec_imp_exists
                  (IScalar.add_spec hcombinedBounds.1 hcombinedBounds.2)
                unfold num.imp.dec2flt.parse.parse_partial_number
                simp [hnotempty, hscanInt, hoffInt, hsplitInt, hscanFrac,
                  hoffFrac, hnegAfter, hfracExponent, htotal, htotalPos,
                  hsplitFrac]
                norm_num
                simp only [UScalar.ofNat, UScalar.ofNatCore]
                cases upper <;>
                  simp at hmarkerByte <;>
                  subst q <;>
                  simp [htotal, htotalPos, hsplitFrac, h101Target, h69Target,
                    hscientific, hcombinedExponent, hoffConsumed, hcastLen,
                    core.option.Option.Insts.CoreOpsTry_traitTry.branch,
                    dec2flt_model.ModelOptionBranch,
                    dec2flt_model.ModelOptionFromResidual]
                all_goals
                  by_cases hsmall : totalDigits.val <= 19
                  · refine ⟨some ({
                        exponent := combinedExponent
                        mantissa := mantissa1
                        negative := false
                        many_digits := false
                      }, len), ?_, ?_⟩
                    · simp [hsmall]
                    · intro d r ho
                      simp only [Option.some.injEq, Prod.mk.injEq] at ho
                      rcases ho with ⟨_, rfl⟩
                      intro hv
                      apply hlenNe
                      apply UScalar.eq_of_val_eq
                      simpa [Slice.len_val] using hv
                  · simp [hsmall]
                    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 simpa using hsubBounds.1)
                          (by simpa using hsubBounds.2))
                    rw [hnMore]
                    simp
                    obtain ⟨adjusted, hadjusted⟩ :=
                      NumberHelperAdjustManySourceLength s nMore hsourceLen (by
                        norm_num at hnMoreVal
                        omega) (by
                        norm_num at hnMoreVal
                        rw [hnMoreVal, htotalVal, hnDigitsEq, hnAfterEq]
                        have hl := congrArg List.length hsval
                        rw [htailEq, hcs] at hl
                        simp at hl
                        omega)
                    rw [hadjusted]
                    by_cases hpositive : 0 < adjusted.val
                    · simp [hpositive]
                      obtain ⟨mantissa2, exponent2, hmany⟩ :=
                        NumberHelperFractionalManyDigitsSourceLength s intRest
                          parsedExp integer fraction fracTail (by
                            simpa [htailEq, hcs, List.append_assoc] using hsval)
                          (by simpa [htailEq, hcs] using hintRest) hintDigits
                          hfracDigits hfracTail hsourceLen (by
                            have hb := hcombinedBounds.1
                            rw [hfracExponentVal, hnegAfterVal, hnAfterEq] at hb
                            simpa [IScalar.min_IScalarTy_I64_eq, I64.min_eq]
                              using hb) (by
                            rw [IScalar.max_IScalarTy_I64_eq, I64.max_eq]
                            have hl := hlen
                            rw [hsval, htailEq, hcs] at hl
                            simp at hl
                            omega)
                      rw [hmany]
                      refine ⟨some ({
                          exponent := exponent2
                          mantissa := mantissa2
                          negative := false
                          many_digits := true
                        }, len), rfl, ?_⟩
                      intro d r ho
                      simp only [Option.some.injEq, Prod.mk.injEq] at ho
                      rcases ho with ⟨_, rfl⟩
                      intro hv
                      apply hlenNe
                      apply UScalar.eq_of_val_eq
                      simpa [Slice.len_val] using hv
                    · simp [hpositive]
                      intro hv
                      apply hlenNe
                      apply UScalar.eq_of_val_eq
                      simpa [Slice.len_val] using hv
          · have hq101 : q ≠ 101#u8 := by tauto
            have hq69 : q ≠ 69#u8 := by tauto
            obtain ⟨consumed, hoffConsumed, hconsumedVal⟩ :=
              NumberHelperOffsetSourceLength s fracRest hsourceLen (by
                have hsLenEq := congrArg List.length hsval
                rw [htailEq, hcs, htailCase] at hsLenEq
                rw [hfracRest, htailCase]
                simp at hsLenEq ⊢
                omega)
            have hrestLe : fracRest.val.length <= s.val.length := by
              have hsLenEq := congrArg List.length hsval
              rw [htailEq, hcs, htailCase] at hsLenEq
              rw [hfracRest, htailCase]
              simp at hsLenEq ⊢
              omega
            have hcastBounds : 0 <= consumed.val /\
                consumed.val <= UScalar.max .Usize := by
              rw [hconsumedVal]
              simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
              omega
            obtain ⟨len, hcastLen, hlenVal⟩ :=
              Aeneas.Std.WP.spec_imp_exists
                (IScalar.hcast_inBounds_spec .Usize consumed hcastBounds)
            have hlenEq : len.val = integer.length + 1 + fraction.length := by
              norm_num at hlenVal
              rw [hconsumedVal, hsval, htailEq, hcs, hfracRest, htailCase]
                at hlenVal
              simp at hlenVal
              omega
            have hlenNe : len ≠ Slice.len s := by
              intro heq
              have heqv := congrArg UScalar.val heq
              simp [Slice.len_val, hlenEq, hsval, htailEq, hcs, htailCase]
                at heqv
              omega
            unfold num.imp.dec2flt.parse.parse_partial_number
            simp [hnotempty, hscanInt, hoffInt, hsplitInt, hscanFrac,
              hoffFrac, hnegAfter, hfracExponent, htotal, htotalPos,
              hsplitFrac, hq101, hq69, hoffConsumed, hcastLen]
            norm_num
            simp only [UScalar.ofNat, UScalar.ofNatCore]
            simp [htotal, htotalPos, hsplitFrac, hq101, hq69,
              hoffConsumed, hcastLen]
            split <;> try contradiction
            split <;> try contradiction
            split
            · rename_i hsmall
              refine ⟨some ({
                  exponent := fracExponent
                  mantissa := mantissa1
                  negative := false
                  many_digits := false
                }, len), ?_, ?_⟩
              · rfl
              · intro d r ho
                simp only [Option.some.injEq, Prod.mk.injEq] at ho
                rcases ho with ⟨_, rfl⟩
                intro hv
                apply hlenNe
                apply UScalar.eq_of_val_eq
                simpa [Slice.len_val] using hv
            · rename_i hsmall
              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 simpa using hsubBounds.1)
                    (by simpa using hsubBounds.2))
              rw [hnMore]
              simp
              obtain ⟨adjusted, hadjusted⟩ :=
                NumberHelperAdjustManySourceLength s nMore hsourceLen (by
                  norm_num at hnMoreVal
                  omega) (by
                  norm_num at hnMoreVal
                  rw [hnMoreVal, htotalVal, hnDigitsEq, hnAfterEq]
                  omega)
              rw [hadjusted]
              by_cases hpositive : 0 < adjusted.val
              · simp [hpositive]
                obtain ⟨mantissa2, exponent2, hmany⟩ :=
                  NumberHelperFractionalManyDigitsSourceLength s intRest
                    0#i64 integer fraction (q :: qs) (by
                      simpa [htailEq, hcs, htailCase, List.append_assoc]
                        using hsval) (by
                      simpa [htailEq, hcs, htailCase] using hintRest) hintDigits
                    hfracDigits (by
                      intro b rest h
                      exact hfracTail b rest (by simpa [htailCase] using h))
                    hsourceLen (by
                      rw [IScalar.min_IScalarTy_I64_eq, I64.min_eq]
                      norm_num
                      have hl := hlen
                      rw [hsval, htailEq, hcs, htailCase] at hl
                      simp at hl
                      omega) (by
                      rw [IScalar.max_IScalarTy_I64_eq, I64.max_eq]
                      norm_num
                      rw [htotalVal, hnDigitsEq, hnAfterEq] at hsmall
                      omega)
                rw [hmany]
                refine ⟨some ({
                    exponent := exponent2
                    mantissa := mantissa2
                    negative := false
                    many_digits := true
                  }, len), rfl, ?_⟩
                intro d r ho
                simp only [Option.some.injEq, Prod.mk.injEq] at ho
                rcases ho with ⟨_, rfl⟩
                intro hv
                apply hlenNe
                apply UScalar.eq_of_val_eq
                simpa [Slice.len_val] using hv
              · simp [hpositive]
                intro hv
                apply hlenNe
                apply UScalar.eq_of_val_eq
                simpa [Slice.len_val] using hv
    · cases c
      rename_i cbv
      let c : Std.U8 := @UScalar.mk .U8 cbv
      have hcbv : cbv ≠ 46 := by
        intro heq
        subst cbv
        exact hpoint (by rfl)
      have hpointMatch :
          (match (@UScalar.mk .U8 cbv) with
          | 46#uscalar => do
              let (s3, mantissa2) ←
                num.imp.dec2flt.parse.try_parse_digits afterFirst mantissa
              let nAfter ←
                SliceU8.Insts.Dec2flt_modelNumImpDec2fltCommonByteSlice.offset_from
                  s3 afterFirst
              let negAfter ← -. nAfter
              let fracExponent ← lift (IScalar.cast .I64 negAfter)
              ok (s3, mantissa2, nAfter, fracExponent)
          | _ => ok (intRest, mantissa, 0#isize, 0#i64)) =
            ok (intRest, mantissa, 0#isize, 0#i64) := by
        split <;> try contradiction
        all_goals rfl
      by_cases hintegerEmpty : integer = []
      · have hnzero : nDigits = 0#isize := by
          apply IScalar.eq_of_val_eq
          rw [hnDigitsEq, hintegerEmpty]
          norm_num
        have haddZeroZero : (0#isize + 0#isize) = ok 0#isize := by
          simpa [hnzero] using haddZero
        unfold num.imp.dec2flt.parse.parse_partial_number
        simp [hnotempty, hscanInt, hoffInt, hsplitInt]
        split <;> try contradiction
        simp [haddZeroZero, hnzero]
      · have hnpos : 0 < nDigits.val := by
          rw [hnDigitsEq]
          have := List.length_pos_of_ne_nil hintegerEmpty
          omega
        by_cases hmarker : c = 101#u8 \/ c = 69#u8
        · obtain ⟨upper, hupper⟩ : exists upper : Bool,
              c = if upper then 69#u8 else 101#u8 := by
            rcases hmarker with hc | hc
            · exact ⟨false, by simpa using hc⟩
            · exact ⟨true, by simpa using hc⟩
          have hmarkerByte : (@UScalar.mk .U8 cbv) =
              if upper then 69#u8 else 101#u8 := by
            simpa [c] using hupper
          let sign := scientific_sign cs
          let expBody := scientific_body cs
          have hcsSign : cs =
              (match sign with
              | none => []
              | some negative => [if negative then 45#u8 else 43#u8]) ++
                expBody := by
            exact scientific_split cs
          have hunsigned : sign = none -> forall b rest,
              expBody = b :: rest -> b ≠ 45#u8 /\ b ≠ 43#u8 := by
            exact scientific_unsigned cs
          obtain ⟨expDigits, expTail, hbody, hexpDigits, hexpTail⟩ :=
            split_digits expBody
          have hsci : afterFirst.val =
              (match sign with
              | none => []
              | some negative => [if negative then 45#u8 else 43#u8]) ++
                expDigits ++ expTail := by
            change cs = _
            rw [hcsSign, hbody, List.append_assoc]
          obtain hnoexp | hexp :=
            NumberHelperScientificClassificationSourceLength afterFirst sign
              expDigits expTail hexpDigits hexpTail hsci (by
                intro hd hs b rest ht
                apply hunsigned hs b rest
                rw [hbody, hd]
                simpa using ht)
          · rcases hnoexp with ⟨_, rest, hscientific⟩
            unfold num.imp.dec2flt.parse.parse_partial_number
            simp [hnotempty, hscanInt, hoffInt, hsplitInt]
            split <;> try contradiction
            simp [haddZero, hnpos, hsplitInt]
            cases upper with
            | false =>
              have hb := congrArg UScalar.bv hmarkerByte
              simp at hb
              subst cbv
              simp [h101Target, h69Target, hscientific,
                core.option.Option.Insts.CoreOpsTry_traitTry.branch,
                core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
                dec2flt_model.ModelOptionBranch,
                dec2flt_model.ModelOptionFromResidual]
            | true =>
              have hb := congrArg UScalar.bv hmarkerByte
              simp at hb
              subst cbv
              simp [h101Target, h69Target, hscientific,
                core.option.Option.Insts.CoreOpsTry_traitTry.branch,
                core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
                dec2flt_model.ModelOptionBranch,
                dec2flt_model.ModelOptionFromResidual]
          · rcases hexp with ⟨hexpNe, parsedExp, sciRest, hscientific,
                hsciRest, hexplo, hexphi, hexpshort, hexpnonnegative⟩
            cases htailExp : expTail with
            | nil =>
              exact False.elim (complete_spelling integer none
                (some (upper, sign, expDigits)) hintDigits (by simp)
                (by left; simpa only [bne_iff_ne] using hintegerEmpty)
                ⟨hexpNe, hexpDigits⟩ (by
                  rw [hsval, htailEq, hmarkerByte, hcsSign, hbody, htailExp]
                  simp [List.append_assoc]))
            | cons z zs =>
              obtain ⟨consumed, hoffConsumed, hconsumedVal⟩ :=
                NumberHelperOffsetSourceLength s sciRest hsourceLen (by
                  rw [hsciRest, htailExp]
                  have hl := congrArg List.length hsval
                  rw [htailEq, hcsSign, hbody, htailExp] at hl
                  simp at hl ⊢
                  omega)
              have hcastBounds : 0 <= consumed.val /\
                  consumed.val <= UScalar.max .Usize := by
                rw [hconsumedVal]
                have hrestLe : sciRest.val.length <= s.val.length := by
                  rw [hsciRest, htailExp]
                  have hl := congrArg List.length hsval
                  rw [htailEq, hcsSign, hbody, htailExp] at hl
                  simp at hl ⊢
                  omega
                simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
                omega
              obtain ⟨len, hcastLen, hlenVal⟩ :=
                Aeneas.Std.WP.spec_imp_exists
                  (IScalar.hcast_inBounds_spec .Usize consumed hcastBounds)
              have hlenNe : len ≠ Slice.len s := by
                intro heq
                have heqv : (len.val : Int) = s.val.length := by
                  have h := congrArg UScalar.val heq
                  simpa [Slice.len_val] using h
                have hrestPos : 0 < sciRest.val.length := by
                  rw [hsciRest, htailExp]
                  simp
                have hlenConsumed : (len.val : Int) = consumed.val := by
                  norm_num at hlenVal
                  exact hlenVal
                rw [hconsumedVal] at hlenConsumed
                omega
              have haddBounds : IScalar.min .I64 <=
                    (0#i64).val + parsedExp.val /\
                  (0#i64).val + parsedExp.val <= IScalar.max .I64 := by
                rw [IScalar.min_IScalarTy_I64_eq, I64.min_eq,
                  IScalar.max_IScalarTy_I64_eq, I64.max_eq]
                norm_num
                omega
              obtain ⟨combined, haddExp, hcombinedVal⟩ :=
                Aeneas.Std.WP.spec_imp_exists
                  (IScalar.add_spec haddBounds.1 haddBounds.2)
              have hcombined : combined = parsedExp := by
                apply IScalar.eq_of_val_eq
                norm_num at hcombinedVal
                exact hcombinedVal
              subst combined
              unfold num.imp.dec2flt.parse.parse_partial_number
              simp [hnotempty, hscanInt, hoffInt, hsplitInt]
              split <;> try contradiction
              simp [haddZero, hnpos, hsplitInt]
              cases upper <;>
                have hb := congrArg UScalar.bv hmarkerByte <;>
                simp at hb <;>
                subst cbv <;>
                simp [h101Target, h69Target, hscientific, haddExp,
                  hoffConsumed, hcastLen,
                  core.option.Option.Insts.CoreOpsTry_traitTry.branch,
                  dec2flt_model.ModelOptionBranch,
                  dec2flt_model.ModelOptionFromResidual]
              all_goals
                by_cases hsmall : nDigits.val <= 19
                · refine ⟨some ({
                      exponent := parsedExp
                      mantissa := mantissa
                      negative := false
                      many_digits := false
                    }, len), ?_, ?_⟩
                  · simp [hsmall]
                  · intro d r ho
                    simp only [Option.some.injEq, Prod.mk.injEq] at ho
                    rcases ho with ⟨_, rfl⟩
                    intro hv
                    apply hlenNe
                    apply UScalar.eq_of_val_eq
                    simpa [Slice.len_val] using hv
                · simp [hsmall]
                  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 simpa using hsubBounds.1)
                        (by simpa using hsubBounds.2))
                  rw [hnMore]
                  simp
                  obtain ⟨adjusted, hadjusted⟩ :=
                    NumberHelperAdjustManySourceLength s nMore hsourceLen (by
                      norm_num at hnMoreVal
                      omega) (by
                      norm_num at hnMoreVal
                      rw [hnMoreVal, hnDigitsEq]
                      omega)
                  rw [hadjusted]
                  by_cases hpositive : 0 < adjusted.val
                  · simp [hpositive]
                    obtain ⟨mantissa2, exponent2, hmany⟩ :=
                      NumberHelperIntegralManyDigitsSourceLength s intRest
                        parsedExp nMore adjusted integer intTailBytes hsval
                        hintRest hintDigits hintTail (by
                          intro b rest h
                          rw [htailEq] at h
                          injection h with hbc _
                          subst b
                          exact hpoint) hsourceLen (by
                          norm_num at hnMoreVal
                          rw [hnMoreVal, hnDigitsEq]) hadjusted hpositive (by
                          rw [IScalar.max_IScalarTy_I64_eq, I64.max_eq]
                          have hl := hlen
                          rw [hsval] at hl
                          simp at hl
                          omega)
                    rw [hmany]
                    refine ⟨some ({
                        exponent := exponent2
                        mantissa := mantissa2
                        negative := false
                        many_digits := true
                      }, len), rfl, ?_⟩
                    intro d r ho
                    simp only [Option.some.injEq, Prod.mk.injEq] at ho
                    rcases ho with ⟨_, rfl⟩
                    intro hv
                    apply hlenNe
                    apply UScalar.eq_of_val_eq
                    simpa [Slice.len_val] using hv
                  · simp [hpositive]
                    intro hv
                    apply hlenNe
                    apply UScalar.eq_of_val_eq
                    simpa [Slice.len_val] using hv
        · have hc101 : c ≠ 101#u8 := by tauto
          have hc69 : c ≠ 69#u8 := by tauto
          have hcbv101 : cbv ≠ (101 : BitVec 8) := by
            intro heq
            apply hc101
            exact congrArg (fun v : BitVec 8 => (@UScalar.mk .U8 v)) heq
          have hcbv69 : cbv ≠ (69 : BitVec 8) := by
            intro heq
            apply hc69
            exact congrArg (fun v : BitVec 8 => (@UScalar.mk .U8 v)) heq
          obtain ⟨consumed, hoffConsumed, hconsumedVal⟩ :=
            NumberHelperOffsetSourceLength s intRest hsourceLen (by
              rw [hintRest, hsval]
              simp)
          have hcastBounds : 0 <= consumed.val /\
              consumed.val <= UScalar.max .Usize := by
            rw [hconsumedVal]
            simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
            omega
          obtain ⟨len, hcastLen, hlenVal⟩ :=
            Aeneas.Std.WP.spec_imp_exists
              (IScalar.hcast_inBounds_spec .Usize consumed hcastBounds)
          have hlenEq : len.val = integer.length := by
            norm_num at hlenVal
            rw [hconsumedVal, hintRest, hsval] at hlenVal
            simp at hlenVal
            omega
          have hlenNe : len ≠ Slice.len s := by
            intro heq
            have heqv := congrArg UScalar.val heq
            simp [Slice.len_val, hlenEq, hsval, htailEq] at heqv
          unfold num.imp.dec2flt.parse.parse_partial_number
          simp [hnotempty, hscanInt, hoffInt, hsplitInt]
          split <;> try contradiction
          simp [haddZero, hnpos, hsplitInt, h101Target, h69Target, hc101,
            hc69, hcbv101, hcbv69, hoffConsumed, hcastLen]
          split <;> try contradiction
          split <;> try contradiction
          by_cases hsmall : nDigits.val <= 19
          · refine ⟨some ({
                exponent := 0#i64
                mantissa := mantissa
                negative := false
                many_digits := false
              }, len), ?_, ?_⟩
            · simp [hsmall]
            · intro d r ho
              simp only [Option.some.injEq, Prod.mk.injEq] at ho
              rcases ho with ⟨_, rfl⟩
              intro hv
              apply hlenNe
              apply UScalar.eq_of_val_eq
              simpa [Slice.len_val] using hv
          · simp [hsmall]
            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 simpa using hsubBounds.1)
                  (by simpa using hsubBounds.2))
            rw [hnMore]
            simp
            obtain ⟨adjusted, hadjusted⟩ :=
              NumberHelperAdjustManySourceLength s nMore hsourceLen (by
                norm_num at hnMoreVal
                omega) (by
                norm_num at hnMoreVal
                rw [hnMoreVal, hnDigitsEq, hsval]
                simp
                omega)
            rw [hadjusted]
            by_cases hpositive : 0 < adjusted.val
            · simp [hpositive]
              obtain ⟨mantissa2, exponent2, hmany⟩ :=
                NumberHelperIntegralManyDigitsSourceLength s intRest 0#i64
                  nMore adjusted integer (c :: cs) (by
                    rw [htailEq] at hsval
                    simpa [c] using hsval) (by
                    rw [htailEq] at hintRest
                    simpa [c] using hintRest) hintDigits (by
                    intro b rest h
                    apply hintTail b rest
                    rw [htailEq]
                    simpa [c] using h) (by
                    intro b rest h
                    injection h with hbc _
                    subst b
                    simpa [c] using hpoint) hsourceLen (by
                    norm_num at hnMoreVal
                    rw [hnMoreVal, hnDigitsEq]) hadjusted hpositive (by
                    rw [IScalar.max_IScalarTy_I64_eq, I64.max_eq]
                    norm_num
                    have hl := hlen
                    rw [hsval] at hl
                    simp at hl
                    omega)
              rw [hmany]
              refine ⟨some ({
                  exponent := exponent2
                  mantissa := mantissa2
                  negative := false
                  many_digits := true
                }, len), rfl, ?_⟩
              intro d r ho
              simp only [Option.some.injEq, Prod.mk.injEq] at ho
              rcases ho with ⟨_, rfl⟩
              intro hv
              apply hlenNe
              apply UScalar.eq_of_val_eq
              simpa [Slice.len_val] using hv
            · simp [hpositive]
              intro hv
              apply hlenNe
              apply UScalar.eq_of_val_eq
              simpa [Slice.len_val] using hv


end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (68)
More program dependencies (35)
Standard-library dependencies (30)

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 62 entries
Technical checking records
Local closure summary
{
  "node": "NumberHelperPartialNumberSafeLength",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "fdcd06c8d54adc2b3871ff3d26f474e45db26f2ac610f1d05ff77d2dd4899aaf",
  "active_statement_hash": "1dac06f386f4425bcc0ffdab42c712fde5cab559cf4c9f8d17194ee727c97bcb",
  "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-116",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DecimalGoalVocabularyDefault": "94cb4c406f8efb78",
    "ModelSliceSplitFirst": "f617ee05dd2925a9",
    "NumberHelperAdjustManySourceLength": "43aa71b5b9fb578d",
    "NumberHelperDigitScanSourceLength": "8892b939bba0ecf9",
    "NumberHelperFractionalManyDigitsSourceLength": "d9edc04302c7e34a",
    "NumberHelperIntegralManyDigitsSourceLength": "65c9aa63b230b4f0",
    "NumberHelperOffsetSourceLength": "de0168dfeba3b802",
    "NumberHelperScientificClassificationSourceLength": "8f49a3f3533503f0",
    "num_imp_dec2flt_parse_parse_partial_number": "854af4cc12136a58"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "c08dd4b4aea4abb4",
    "DecimalGoalVocabularyDefault": "4634372c8f7a7f44",
    "DecimalLexeme": "c43614ff2149ecf2",
    "F64": "ec4e25fbaf4e11d4",
    "ModelOptionBranch": "c55e273482c8c0a1",
    "ModelOptionFromResidual": "6d48ecfbc617744f",
    "Preamble": "4adf4172ae751d7d",
    "SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from": "7e7284dc9bc88830",
    "SourceValidByteSlice": "3dc42716a6378d26",
    "num_imp_dec2flt_common_BiasedFp": "5c88d5d7976c5e8f",
    "num_imp_dec2flt_decimal_Decimal": "4c41a56bf44cb31e",
    "num_imp_dec2flt_parse_adjust_many_digit_count": "4e59e3776b6cfdaa",
    "num_imp_dec2flt_parse_parse_many_digits": "50c9ef13b3ed7fe8",
    "num_imp_dec2flt_parse_parse_partial_number": "5712e484f99eb7aa",
    "num_imp_dec2flt_parse_parse_scientific": "447f722d5841d2c5",
    "num_imp_dec2flt_parse_try_parse_digits": "238b4a73cd46fc56"
  }
}
Prose assessment
{
  "label": "Recorded Sound: VerifierPass",
  "assessment_status": "VerifierPass",
  "fingerprint_relation": "matches current fingerprint",
  "assessment_fingerprint": "sound-v2:e5062f53eacca1ac92c53cf211454dd7ce06dbe3b3b879ea88a62b948b08c087",
  "current_fingerprint": "sound-v2:e5062f53eacca1ac92c53cf211454dd7ce06dbe3b3b879ea88a62b948b08c087",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}