P401_T1_UnsignedZeroRecord

Lean checked

Statement

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

Lemma · Unrestricted successful unsigned zero record

Let s be a SourceValidByteSlice and x a valid numeric lexeme with absent leading sign, whose complete rendering is the byte list of s, as defined by DecimalGoalVocabularyDefault. Suppose every integer and fractional digit of x is zero. If the extracted parse_number returns normally with Some record d, then d.\mathit{mantissa}=0, d.\mathit{many\_digits}=\texttt{false}, and d.\mathit{negative}=\texttt{false}. The only length restriction is the full source bound |s|\leq C=2^{63}-1; the explicit exponent is unrestricted, and no claim of normal return is made.

Lean statement

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

import Tablet.DecimalGoalVocabularyDefault
import Tablet.Assumptions
import Tablet.SourceValidByteSlice
import Tablet.NumberHelperDigitScanExact
import Tablet.P364_T1_NumberHelperOffsetSourceLength
import Tablet.P364_T1_NumberHelperAdjustCountExact
import Tablet.ModelSliceSplitFirst
import Tablet.ModelOptionBranch
import Tablet.ModelOptionFromResidual
import Tablet.num_imp_dec2flt_parse_parse_number
import Tablet.num_imp_dec2flt_parse_parse_partial_number

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P401_T1_UnsignedZeroRecord]
theorem P401_T1_UnsignedZeroRecord
    (s : Slice Std.U8) (x : DecimalLexeme)
    (d : num.imp.dec2flt.decimal.Decimal)
    (hsource : SourceValidByteSlice s)
    (hsign : x.leadingSign = none)
    (hvalid : DecimalGoalVocabularyDefault.validNumeric x)
    (hrender : DecimalGoalVocabularyDefault.renderNumeric x =
      DecimalGoalVocabularyDefault.bytes s)
    (hzero : ∀ digit ∈ (x.integerDigits ++
      match x.fractionDigits with | none => [] | some ds => ds), digit = 0)
    (hresult : num.imp.dec2flt.parse.parse_number s = ok (some d)) :
    d.mantissa.val = 0 ∧ d.many_digits = false ∧ d.negative = false := 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

Put I=|x.\mathit{integerDigits}|, let F be the fractional digit count (zero if the fraction is absent), and put D=I+F. Unfold DecimalGoalVocabularyDefault. Validity gives D\geq1. Absent leading sign and rendering give the byte decomposition s=UZ E, where U is I ASCII zero bytes, Z is empty if the fraction is absent and otherwise is a dot followed by F ASCII zero bytes, and E is empty or starts with the rendered exponent marker 101 or 69. Consequently D\leq |s|\leq C, and s is nonempty. These statements concern byte contents: equality of the lists of unsigned values determines equality of their U8 lists, because unsigned words are determined by their values.
Unfold num imp dec2flt parse parse number at the given successful equation. Inverting its Result bind yields a normal parse_partial_number return of Some (d,\ell) and its final length comparison must be true. No None, failure, or divergence of that bind could produce ok (Some d). Unfold num imp dec2flt parse parse partial number. The initial emptiness test is false and its assertion succeeds since D\geq1. Its first digit scan starts at zero. Apply NumberHelperDigitScanExact to U and suffix ZE. Every byte of U lies in [48,57], the first byte of ZE, if present, is a dot or exponent marker and hence is not a digit, and the source-length premise is |s|\leq C. The fold of zero bytes starting at zero is zero by induction, hence is at most 2^{64}-1. The lemma supplies a normal scan with mantissa zero and exactly suffix ZE. By NumberHelperOffsetSourceLength, the following offset returns integer value I: its whole slice is s, its suffix is ZE, and |ZE|\leq |s|\leq C. In particular its length casts are exact.
The split-first observation uses ModelSliceSplitFirst. If there is no fraction, the suffix is empty or starts with 101 or 69, never 46, and the dot branch is not taken: the stored mantissa remains zero, fractional count is zero, and initial exponent is zero. If there is a fraction, that observation returns the dot and its suffix VE, where V consists of F zero bytes. Apply NumberHelperDigitScanExact again with initial mantissa zero, digit block V, and tail E. Its length is at most |s|\leq C; the tail is empty or starts with a nondigit marker, and its full fold is zero. It returns mantissa zero and tail E. Apply NumberHelperOffsetSourceLength with whole slice VE and remaining slice E to obtain fractional count F. Checked signed negation of this count succeeds because 0\leq F\leq C, so it is not signed minimum; its value is -F in [-C,0]. The subsequent Isize-to-I64 cast is exact on the 64-bit target of Assumptions. Thus the initial exponent is -F. In both cases the next count addition succeeds with value I+F=D: 0\leq I,F and D\leq C put the sum in the signed range. The zero-count rejection branch is impossible since D\geq1.
The next split-first sees exactly E. If E is empty, the no-exponent branch is taken. Otherwise its first byte is 101 or 69, and the matching scientific branch is taken. In the latter case invert the reached parse_scientific Result bind in the given successful execution. It must return normally; its option branch must be Continue with some signed value v, because Break returns None by ModelOptionBranch and ModelOptionFromResidual. Invert the next checked exponent addition too: it must return normally with some I64 value q. We do not infer normality of this addition merely from numeric grammar or claim that -F+v is in range for all valid strings. If it is out of range, the premise of this lemma is false. The offset and consumed-length cast which precede record construction are likewise either the actual normal results forced by the premise, or the premise is impossible. Their values are not needed below. Thus, in every reached record-building branch, mantissa is still zero and the signed count still has value D; the presence and value of an explicit exponent do not alter either fact.
If D\leq19, each reached branch immediately constructs the record with that zero mantissa, negative=false, and many_digits=false. If D>19, the checked subtraction by 19 succeeds with value n=D-19, since 1\leq n\leq D\leq C. For the reached adjustment call, take the zero-and-dot prefix P=UZ and tail E in NumberHelperAdjustCountExact. Every byte of P is 48 or 46. The tail is empty or starts with 101 or 69, so it starts with neither 48 nor 46. Exactly D bytes of P are 48: both integer and fractional zero lists contribute their full lengths, and the optional dot contributes none. Therefore c_0(P)=D. All arithmetic premises of that lemma hold explicitly:
0\leq n=D-19\leq |s|,\qquad n-c_0(P)=D-19-D=-19\geq-2^{63}=\mathit{isize}_{\min}, \qquad |s|\leq C.
Hence the adjustment returns normally with integer value -19. Its comparison with zero is false; in particular the parse_many_digits retry is not reached even on a very long all-zero significand. Each reached branch again constructs the record with zero mantissa and both Boolean fields false. Comparing its normal Some result with the inverted given result identifies that record with d and proves all three conclusions.

Lean proof


  have hpartial : ∃ len : Std.Usize,
      num.imp.dec2flt.parse.parse_partial_number s = ok (some (d, len)) := by
    unfold num.imp.dec2flt.parse.parse_number at hresult
    cases hp : num.imp.dec2flt.parse.parse_partial_number s with
    | fail err => simp [hp] at hresult
    | div => simp [hp] at hresult
    | ok out =>
      cases out with
      | none => simp [hp] at hresult
      | some pair =>
        rcases pair with ⟨d', len⟩
        simp [hp] at hresult
        split at hresult
        · simp_all
        · simp at hresult
  rcases hpartial with ⟨len, hpartial⟩
  have bind_ok_inv : ∀ {α β : Type} (r : Result α)
      (f : α → Result β) y, Bind.bind r f = ok y →
      ∃ z, r = ok z ∧ f z = ok y := by
    intro α β r f y h
    cases r with
    | fail err => simp [Bind.bind, Aeneas.Std.bind] at h
    | div => simp [Bind.bind, Aeneas.Std.bind] at h
    | ok z => exact ⟨z, rfl, h⟩
  have hpartialExec := hpartial
  unfold num.imp.dec2flt.parse.parse_partial_number at hpartialExec
  obtain ⟨isEmpty, hempty, hafterEmpty⟩ := bind_ok_inv _ _ _ hpartialExec
  obtain ⟨_, hmassert, hafterAssert⟩ := bind_ok_inv _ _ _ hafterEmpty
  cases isEmpty <;> simp [massert] at hmassert
  obtain ⟨scanOut, hscan, hafterScan⟩ := bind_ok_inv _ _ _ hafterAssert
  have hvalid' := hvalid
  simp [DecimalGoalVocabularyDefault] at hvalid'
  rcases hvalid' with ⟨hint, hfrac, hnonempty, hexp⟩
  let fracDigits := match x.fractionDigits with | none => [] | some ds => ds
  have hzeroInt : ∀ digit, digit ∈ x.integerDigits → digit = 0 := by
    intro digit hd
    exact hzero digit (List.mem_append_left _ hd)
  have hzeroFrac : ∀ digit, digit ∈ fracDigits → digit = 0 := by
    intro digit hd
    cases hf : x.fractionDigits with
    | none => simp [fracDigits, hf] at hd
    | some ds =>
      simp [fracDigits, hf] at hd
      exact hzero digit (by simpa [fracDigits, hf] using List.mem_append_right x.integerDigits hd)
  have mapZero : ∀ ds : List Nat, (∀ n, n ∈ ds → n = 0) →
      ds.map (fun n => 48 + n) = ds.map (fun _ => 48) := by
    intro ds
    induction ds with
    | nil => intro; rfl
    | cons n ns ih =>
      intro hn
      have hn0 := hn n List.mem_cons_self
      simp only [List.map_cons, hn0]
      exact congrArg (List.cons 48) (ih (by intro m hm; exact hn m (List.mem_cons_of_mem _ hm)))
  have hrenderNat :
      (x.integerDigits.map (fun _ => 48) ++
        (match x.fractionDigits with
          | none => []
          | some _ => 46 :: fracDigits.map (fun _ => 48))) ++
        (match x.exponent with
          | none => []
          | some (upper, sign, ds) =>
              (if upper then 69 else 101) ::
                (match sign with | none => [] | some neg => [if neg then 45 else 43]) ++
                  ds.map (fun n => 48 + n)) = s.val.map (fun b => b.val) := by
    have hvals := hrender
    simp [DecimalGoalVocabularyDefault, hsign] at hvals
    rw [mapZero x.integerDigits hzeroInt] at hvals
    cases hf : x.fractionDigits with
    | none => simpa [fracDigits, hf, List.append_assoc] using hvals
    | some ds =>
      have hz := mapZero ds (by
        intro n hn
        exact hzero n (by simpa [hf] using List.mem_append_right x.integerDigits hn))
      simpa [fracDigits, hf, hz, List.append_assoc] using hvals
  let intNat := x.integerDigits.map (fun _ => 48)
  let fracNat := fracDigits.map (fun _ => 48)
  let dotNat := match x.fractionDigits with | none => [] | some _ => 46 :: fracNat
  let expNat := match x.exponent with
    | none => []
    | some (upper, sign, ds) =>
        (if upper then 69 else 101) ::
          (match sign with | none => [] | some neg => [if neg then 45 else 43]) ++
            ds.map (fun n => 48 + n)
  let renderedNat := intNat ++ dotNat ++ expNat
  have hrenderNat' : renderedNat = s.val.map (fun b => b.val) := by
    simpa [renderedNat, intNat, dotNat, expNat, fracNat, fracDigits,
      List.append_assoc] using hrenderNat
  have hrenderNonempty : renderedNat ≠ [] := by
    rcases hnonempty with hi | hf
    · cases hx : x.integerDigits with
      | nil => simp [hx] at hi
      | cons a ds => simp [renderedNat, intNat, hx]
    · cases hx : x.fractionDigits with
      | none => simp [hx] at hf
      | some ds =>
        cases hd : ds with
        | nil => simp [hx, hd] at hf
        | cons a ds' => simp [renderedNat, intNat, dotNat, fracNat, hx, hd]
  have hsourceNonempty : s.val ≠ [] := by
    intro hs
    apply hrenderNonempty
    simpa [hs] using hrenderNat'
  have hrenderSmall : ∀ n, n ∈ renderedNat → n < 256 := by
    intro n hn
    have hp : n ∈ intNat ++ dotNat ++ expNat := by
      simpa [renderedNat] using hn
    rcases List.mem_append.mp hp with hprefix | he
    · rcases List.mem_append.mp hprefix with hi | hd
      · rcases List.mem_map.mp hi with ⟨d, _, rfl⟩
        norm_num
      · cases hf : x.fractionDigits with
        | none => simp [dotNat, hf] at hd
        | some ds =>
          simp [dotNat, hf] at hd
          rcases hd with rfl | hd
          · norm_num
          · rcases List.mem_map.mp hd with ⟨d, _, rfl⟩
            norm_num
    · cases hx : x.exponent with
      | none => simp [expNat, hx] at he
      | some e =>
        rcases e with ⟨upper, sign, ds⟩
        simp [expNat, hx] at he
        rcases he with hhead | hs
        · rw [hhead]
          split <;> norm_num
        · rcases hs with hsign | hd
          · cases sign with
            | none => simp at hsign
            | some neg => cases neg <;> simp at hsign <;> omega
          · rcases hd with ⟨d, hdm, heq⟩
            have hexp' : ds ≠ [] ∧ ∀ d, d ∈ ds → d < 10 := by
              simpa [hx] using hexp
            have hdigit := hexp'.2 d hdm
            omega
  let byteOfNat := fun n : Nat =>
    @UScalar.ofNatCore .U8 (n % 256) (by exact Nat.mod_lt _ (by omega))
  have mapByteValues : ∀ ns : List Nat,
      (∀ n, n ∈ ns → n < 256) →
      List.map (fun b : Std.U8 => b.val) (ns.map byteOfNat) = ns := by
    intro ns
    induction ns with
    | nil => intro; rfl
    | cons n ns ih =>
      intro hn
      simp only [List.map_cons, List.map_map, Function.comp_apply]
      have hlt := hn n List.mem_cons_self
      have htail := ih (by intro m hm; exact hn m (List.mem_cons_of_mem _ hm))
      have hhead : (byteOfNat n).val = n := by
        simp [byteOfNat, UScalar.ofNatCore_val_eq, Nat.mod_eq_of_lt hlt]
      rw [hhead]
      simpa only [List.map_map] using congrArg (List.cons n) htail
  let intBytes := intNat.map byteOfNat
  let dotBytes := dotNat.map byteOfNat
  let expBytes := expNat.map byteOfNat
  have mapByteInj : Function.Injective (List.map (fun b : Std.U8 => b.val)) := by
    intro l1 l2 heq
    induction l1 generalizing l2 with
    | nil => cases l2 <;> simp at heq ⊢
    | cons a xs ih =>
      cases l2 with
      | nil => simp at heq
      | cons b bs =>
        simp only [List.map_cons] at heq
        injection heq with hhead htail
        have hab : a = b := UScalar.eq_of_val_eq hhead
        subst b
        exact congrArg (List.cons a) (ih htail)
  have hsourceBytes : s.val = intBytes ++ dotBytes ++ expBytes := by
    apply mapByteInj
    have hmap : s.val.map (fun b => b.val) =
        (renderedNat.map byteOfNat).map (fun b => b.val) := by
      rw [mapByteValues renderedNat hrenderSmall]
      exact hrenderNat'.symm
    simpa [intBytes, dotBytes, expBytes, renderedNat, List.map_append,
      List.append_assoc] using hmap
  let scanTail := dotBytes ++ expBytes
  have hscanPartition : s.val = intBytes ++ scanTail := by
    simpa [scanTail, List.append_assoc] using hsourceBytes
  have hscanDigits : ∀ b, b ∈ intBytes → 48 ≤ b.val ∧ b.val ≤ 57 := by
    intro b hb
    rcases List.mem_map.mp hb with ⟨n, hn, rfl⟩
    rcases List.mem_map.mp hn with ⟨d, _, rfl⟩
    simp [byteOfNat]
  have hscanTail : ∀ b rest, scanTail = b :: rest →
      ¬ (48 ≤ b.val ∧ b.val ≤ 57) := by
    intro b rest htail
    cases hf : x.fractionDigits with
    | some ds =>
      have : b = byteOfNat 46 := by
        simp [scanTail, dotBytes, dotNat, hf, List.map_append] at htail
        exact htail.1.symm
      rw [this]
      norm_num [byteOfNat]
    | none =>
      cases he : x.exponent with
      | none => simp [scanTail, dotBytes, dotNat, expBytes, expNat, hf, he] at htail
      | some e =>
        rcases e with ⟨upper, sign, ds⟩
        have : b = byteOfNat (if upper then 69 else 101) := by
          simp [scanTail, dotBytes, dotNat, expBytes, expNat, hf, he,
            List.map_append] at htail
          exact htail.1.symm
        rw [this]
        cases upper <;> norm_num [byteOfNat]
  have foldZero : ∀ ns : List Nat, (∀ n, n ∈ ns → n = 48) →
      (ns.map byteOfNat).foldl (fun a b => 10 * a + (b.val - 48)) 0 = 0 := by
    intro ns
    induction ns with
    | nil => intro; rfl
    | cons n ns ih =>
      intro hn
      have hn48 := hn n List.mem_cons_self
      simp only [List.map_cons, List.foldl_cons]
      have hb : (byteOfNat n).val = 48 := by rw [hn48]; norm_num [byteOfNat]
      simp [hb, ih (by intro m hm; exact hn m (List.mem_cons_of_mem _ hm))]
  have hscanFold : intBytes.foldl
      (fun a b => 10 * a + (b.val - 48)) 0 = 0 := by
    simpa [intBytes] using foldZero intNat (by
      intro n hn
      rcases List.mem_map.mp hn with ⟨v, _, rfl⟩
      rfl)
  let fracBytes := fracNat.map byteOfNat
  have hfracFold : fracBytes.foldl
      (fun a b => 10 * a + (b.val - 48)) 0 = 0 := by
    simpa [fracBytes] using foldZero fracNat (by
      intro n hn
      rcases List.mem_map.mp hn with ⟨v, _, rfl⟩
      rfl)
  have hfracBytesZero : ∀ b, b ∈ fracBytes → b.val = 48 := by
    intro b hb
    rcases List.mem_map.mp hb with ⟨n, hn, rfl⟩
    rcases List.mem_map.mp hn with ⟨v, _, rfl⟩
    simp [byteOfNat]
  have hfracLeDot : fracBytes.length ≤ dotBytes.length := by
    cases hf : x.fractionDigits with
    | none => simp [dotBytes, dotNat, fracBytes, fracNat, fracDigits, hf]
    | some ds =>
      simp [dotBytes, dotNat, fracBytes, fracNat, fracDigits, hf]
  have hfracSuffixLe : (fracBytes ++ expBytes).length ≤ s.val.length := by
    calc
      (fracBytes ++ expBytes).length = fracBytes.length + expBytes.length := by simp
      _ ≤ dotBytes.length + expBytes.length := Nat.add_le_add_right hfracLeDot _
      _ ≤ (intBytes ++ dotBytes ++ expBytes).length := by simp [List.length_append]
      _ = s.val.length := by rw [hsourceBytes]
  let fractionSlice : Slice Std.U8 := ⟨fracBytes ++ expBytes,
    le_trans hfracSuffixLe s.property⟩
  have hfracTailNotDigit : ∀ b rest, expBytes = b :: rest →
      ¬ (48 ≤ b.val ∧ b.val ≤ 57) := by
    intro b rest he
    cases hx : x.exponent with
    | none => simp [expBytes, expNat, hx] at he
    | some tuple =>
      rcases tuple with ⟨upper, sign, digits⟩
      have hhead : List.head? expBytes = some b := by rw [he]; rfl
      cases upper <;> simp [expBytes, expNat, hx, byteOfNat] at hhead
      all_goals rw [← hhead] <;> norm_num
  have hfracByteDigits : ∀ b, b ∈ fracBytes → 48 ≤ b.val ∧ b.val ≤ 57 := by
    intro b hb
    rw [hfracBytesZero b hb]
    norm_num
  have hfracFoldBound : fracBytes.foldl
      (fun a b => 10 * a + (b.val - 48)) (0#u64).val ≤ U64.max := by
    change fracBytes.foldl (fun a b => 10 * a + (b.val - 48)) 0 ≤ U64.max
    rw [hfracFold]
    exact Nat.zero_le _
  have hfracSource : SourceValidByteSlice fractionSlice := by
    change fractionSlice.val.length ≤ 9223372036854775807
    exact Nat.le_trans hfracSuffixLe hsource
  obtain ⟨fractionValue, fractionRest, hfractionScan, hfractionRest,
      hfractionValue⟩ := NumberHelperDigitScanExact fractionSlice 0#u64
    fracBytes expBytes (by simp [fractionSlice]) hfracByteDigits
    hfracTailNotDigit hfracSource hfracFoldBound
  have hfractionValueZero : fractionValue.val = 0 := by
    simpa [hfracFold] using hfractionValue
  have hfoldBound : intBytes.foldl
      (fun a b => 10 * a + (b.val - 48)) (0#u64).val ≤ U64.max := by
    simpa [hscanFold] using (Nat.zero_le U64.max)
  have hscanCert := NumberHelperDigitScanExact s 0#u64 intBytes scanTail
    hscanPartition hscanDigits hscanTail hsource hfoldBound
  rcases hscanCert with ⟨scanValue, scanRest, hcert, hrest, hscanValue⟩
  have hscanPair : scanOut = (scanRest, scanValue) := by
    rw [hcert] at hscan
    injection hscan with hpair
    exact hpair.symm
  subst scanOut
  have hscanValueZero : scanValue.val = 0 := by
    simpa [hscanFold] using hscanValue
  have hscanRestEq : scanRest.val = scanTail := hrest
  let tailSlice : Slice Std.U8 := ⟨scanTail, by
    rw [← hscanRestEq]
    exact scanRest.property⟩
  have hscanRestSlice : scanRest = tailSlice :=
    (Slice.eq_iff _ _).2 hscanRestEq
  obtain ⟨nDigits, hoffset, hafterOffset⟩ :=
    bind_ok_inv _ _ _ hafterScan
  have htailLe : scanRest.val.length ≤ s.val.length := by
    rw [hscanRestEq, hscanPartition]
    simp
  obtain ⟨off, hoff, hoffVal⟩ :=
    P364_T1_NumberHelperOffsetSourceLength s scanRest hsource htailLe
  have hoffEq : nDigits = off := by
    rw [hoff] at hoffset
    injection hoffset with h
    exact h.symm
  have hcountEq : nDigits.val = x.integerDigits.length := by
    have hintByteLen : intBytes.length = x.integerDigits.length := by
      simp [intBytes, intNat]
    have hlenPartitionNat : s.val.length = intBytes.length + scanTail.length := by
      rw [hscanPartition]
      simp
    have hlenPartition : (s.val.length : Int) =
        (intBytes.length : Int) + (scanTail.length : Int) := by
      exact_mod_cast hlenPartitionNat
    have hrestLen : (scanRest.val.length : Int) = (scanTail.length : Int) := by
      exact_mod_cast congrArg List.length hscanRestEq
    have hoffInt : off.val = (intBytes.length : Int) := by
      rw [hoffVal, hrestLen, hlenPartition]
      omega
    rw [hoffEq, hoffInt, hintByteLen]
  obtain ⟨dotOpt, hsplit, hafterSplit⟩ :=
    bind_ok_inv _ _ _ hafterOffset
  have hfracActual : ∀ ds, x.fractionDigits = some ds →
      dotOpt = some (46#u8, fractionSlice) := by
    intro ds hf
    have hdotBytes : dotBytes = 46#u8 :: fracBytes := by
      simp only [dotBytes, dotNat, hf, List.map_cons, fracBytes]
      have h46 : byteOfNat 46 = 46#u8 := by
        apply UScalar.eq_of_val_eq
        simp [byteOfNat, UScalar.ofNatCore_val_eq]
      rw [h46]
    have hshape : scanTail = 46#u8 :: (fracBytes ++ expBytes) := by
      simp [scanTail, hdotBytes]
    have hv : scanRest.val = 46#u8 :: (fracBytes ++ expBytes) := by
      rw [hscanRestEq, hshape]
    have hs : scanRest = ⟨46#u8 :: (fracBytes ++ expBytes), by
        rw [← hv]
        exact scanRest.property⟩ := (Slice.eq_iff _ _).2 hv
    rw [hs] at hsplit
    simp [core.slice.Slice.split_first, ModelSliceSplitFirst, fractionSlice] at hsplit
    exact hsplit.symm
  obtain ⟨afterSplit, hsplitContinuation, hafterSplitContinuation⟩ :=
    bind_ok_inv _ _ _ hafterSplit
  rcases afterSplit with ⟨s2, mantissa1, nAfterDot, baseExponent⟩
  have hscanValueEq : scanValue = 0#u64 := by
    apply UScalar.eq_of_val_eq
    exact hscanValueZero
  have hfracOutputs : ∀ ds, x.fractionDigits = some ds →
      s2 = fractionRest ∧ mantissa1 = fractionValue ∧
        nAfterDot.val = ds.length ∧ baseExponent.val = -(ds.length : Int) := by
    intro ds hf
    have hfracLenDs : fracBytes.length = ds.length := by
      simp [fracBytes, fracNat, fracDigits, hf, List.length_map]
    have hrestLe : fractionRest.val.length ≤ fractionSlice.val.length := by
      rw [hfractionRest]
      change expBytes.length ≤ (fracBytes ++ expBytes).length
      simp
    obtain ⟨fracCount, hoffFrac, hoffFracVal⟩ :=
      P364_T1_NumberHelperOffsetSourceLength fractionSlice fractionRest
        hfracSource hrestLe
    have hfracCountVal : fracCount.val = ds.length := by
      rw [hoffFracVal, hfractionRest]
      simp [fractionSlice, hfracLenDs]
    have hnotmin : fracCount.val ≠ IScalar.min .Isize := by
      rw [hfracCountVal, IScalar.min]
      norm_num [IScalarTy.numBits, Dec2Flt.P340_T1_selected_target_numBits]
      have hds : ds.length ≤ s.val.length := by
        rw [← hfracLenDs]
        exact Nat.le_trans (by simp) hfracSuffixLe
      have hsmax : s.val.length ≤ 9223372036854775807 := by
        simpa [SourceValidByteSlice] using hsource
      omega
    obtain ⟨fracNeg, hneg, hnegVal⟩ :=
      Aeneas.Std.WP.spec_imp_exists (HNeg.hNeg.step fracCount hnotmin)
    have hnegBounds : IScalar.min .I64 ≤ fracNeg.val ∧
        fracNeg.val ≤ IScalar.max .I64 := by
      rw [hnegVal, hfracCountVal,
        IScalar.min_IScalarTy_I64_eq, I64.min_eq,
        IScalar.max_IScalarTy_I64_eq, I64.max_eq]
      have hds : ds.length ≤ s.val.length := by
        rw [← hfracLenDs]
        exact Nat.le_trans (by simp) hfracSuffixLe
      have hsmax : s.val.length ≤ 9223372036854775807 := by
        simpa [SourceValidByteSlice] using hsource
      omega
    obtain ⟨base, hcast, hbaseVal⟩ :=
      Aeneas.Std.WP.spec_imp_exists (IScalar.cast_inBounds_spec .I64 fracNeg hnegBounds)
    rw [hfracActual ds hf] at hsplitContinuation
    dsimp at hsplitContinuation
    rw [hscanValueEq, hfractionScan] at hsplitContinuation
    simp only [bind_tc_ok] at hsplitContinuation
    simp [UScalar.ofNat, UScalar.ofNatCore] at hsplitContinuation
    rw [hoffFrac] at hsplitContinuation
    simp only [bind_tc_ok] at hsplitContinuation
    rw [hneg] at hsplitContinuation
    simp only [bind_tc_ok] at hsplitContinuation
    rw [hcast] at hsplitContinuation
    simp only [bind_tc_ok] at hsplitContinuation
    simp at hsplitContinuation
    rcases hsplitContinuation with ⟨h1, h2, h3, h4⟩
    exact ⟨h1.symm, h2.symm, by rw [← h3, hfracCountVal],
      by rw [← h4, hbaseVal, hnegVal, hfracCountVal]⟩
  have hnoFractionOutputs : x.fractionDigits = none →
      s2 = scanRest ∧ mantissa1 = scanValue ∧
        nAfterDot = 0#isize ∧ baseExponent = 0#i64 := by
    intro hf
    cases he : x.exponent with
    | none =>
      have hnil : scanTail = [] := by
        simp [scanTail, dotBytes, dotNat, expBytes, expNat, hf, he]
      have hv : scanRest.val = [] := by rw [hscanRestEq, hnil]
      have hs : scanRest = ⟨[], by rw [← hv]; exact scanRest.property⟩ :=
        (Slice.eq_iff _ _).2 hv
      have hd : dotOpt = none := by
        rw [hs] at hsplit
        simp [core.slice.Slice.split_first, ModelSliceSplitFirst] at hsplit
        exact hsplit.symm
      rw [hd] at hsplitContinuation
      simp at hsplitContinuation
      rcases hsplitContinuation with ⟨h1, h2, h3, h4⟩
      exact ⟨h1.symm, h2.symm, h3.symm, h4.symm⟩
    | some exponentData =>
      rcases exponentData with ⟨upper, sign, digits⟩
      let marker : Std.U8 := if upper then 69#u8 else 101#u8
      let signNat := (match sign with
          | none => []
          | some neg => [if neg then 45 else 43])
      let rest := signNat.map byteOfNat ++
        digits.map (fun n => byteOfNat (48 + n))
      have htail : scanTail = marker :: rest := by
        cases upper <;> simp [scanTail, dotBytes, dotNat, expBytes,
          expNat, hf, he, marker, rest, signNat, List.map_append,
          byteOfNat]
      have hrestLen : rest.length ≤ Usize.max := by
        have h := scanRest.property
        rw [hscanRestEq, htail] at h
        simp at h
        omega
      let restSlice : Slice Std.U8 := ⟨rest, hrestLen⟩
      have hv : scanRest.val = marker :: rest := by
        rw [hscanRestEq, htail]
      have hs : scanRest = ⟨marker :: rest, by rw [← hv]; exact scanRest.property⟩ :=
        (Slice.eq_iff _ _).2 hv
      have hd : dotOpt = some (marker, restSlice) := by
        rw [hs] at hsplit
        simp [core.slice.Slice.split_first, ModelSliceSplitFirst, restSlice] at hsplit
        exact hsplit.symm
      rw [hd] at hsplitContinuation
      cases upper with
      | false =>
        have htuple : scanRest = s2 ∧ scanValue = mantissa1 ∧
            (0#isize : Std.Isize) = nAfterDot ∧
            (0#i64 : Std.I64) = baseExponent := by
          simpa [marker, UScalar.ofNat, UScalar.ofNatCore] using hsplitContinuation
        rcases htuple with ⟨h1, h2, h3, h4⟩
        exact ⟨h1.symm, h2.symm, h3.symm, h4.symm⟩
      | true =>
        have htuple : scanRest = s2 ∧ scanValue = mantissa1 ∧
            (0#isize : Std.Isize) = nAfterDot ∧
            (0#i64 : Std.I64) = baseExponent := by
          simpa [marker, UScalar.ofNat, UScalar.ofNatCore] using hsplitContinuation
        rcases htuple with ⟨h1, h2, h3, h4⟩
        exact ⟨h1.symm, h2.symm, h3.symm, h4.symm⟩
  have hmantissaZero : mantissa1.val = 0 := by
    cases hf : x.fractionDigits with
    | none =>
      rw [(hnoFractionOutputs hf).2.1]
      exact hscanValueZero
    | some ds =>
      rw [(hfracOutputs ds hf).2.1]
      exact hfractionValueZero
  have hpartialFull : num.imp.dec2flt.parse.parse_partial_number s = ok (some (d, len)) :=
    hpartial
  unfold num.imp.dec2flt.parse.parse_partial_number at hpartialFull
  simp [hsourceNonempty, hscan, hoffset, hsplit] at hpartialFull
  rw [hsplitContinuation] at hpartialFull
  simp only [bind_tc_ok] at hpartialFull
  obtain ⟨totalDigits, htotal, hpartialAfterCount⟩ :=
    bind_ok_inv _ _ _ hpartialFull
  have htotalVal : totalDigits.val = nDigits.val + nAfterDot.val := by
    have heq := IScalar.add_equiv nDigits nAfterDot
    rw [htotal] at heq
    exact heq.2.1
  let fractionalCount := match x.fractionDigits with
    | none => 0
    | some ds => ds.length
  let digitCount := x.integerDigits.length + fractionalCount
  have htotalDigitCount : totalDigits.val = digitCount := by
    cases hf : x.fractionDigits with
    | none =>
      have hna := (hnoFractionOutputs hf).2.2.1
      rw [hcountEq, hna] at htotalVal
      simp [digitCount, fractionalCount, hf] at htotalVal ⊢
      omega
    | some ds =>
      have hna := (hfracOutputs ds hf).2.2.1
      rw [hcountEq, hna] at htotalVal
      simp [digitCount, fractionalCount, hf] at htotalVal ⊢
      omega
  have hsourceLength : s.val.length =
      intBytes.length + dotBytes.length + expBytes.length := by
    rw [hsourceBytes]
    simp [List.length_append, Nat.add_assoc]
  have hintByteLength : intBytes.length = x.integerDigits.length := by
    simp [intBytes, intNat]
  have hfractionalByteLength : fractionalCount = fracBytes.length := by
    cases hf : x.fractionDigits with
    | none => simp [fractionalCount, fracBytes, fracNat, fracDigits, hf]
    | some ds => simp [fractionalCount, fracBytes, fracNat, fracDigits, hf]
  have hdigitCountLe : digitCount ≤ s.val.length := by
    change x.integerDigits.length + fractionalCount ≤ s.val.length
    rw [← hintByteLength, hfractionalByteLength]
    rw [hsourceLength]
    omega
  have hdigitCountPos : 0 < digitCount := by
    cases hf : x.fractionDigits with
    | none =>
      simp [digitCount, fractionalCount, hf]
      rcases hnonempty with hi | hfrac
      · have hp : 0 < x.integerDigits.length := by
          cases hx : x.integerDigits with
          | nil => simp [hx] at hi
          | cons a ds => simp
        omega
      · simp [hf] at hfrac
    | some ds =>
      simp [digitCount, fractionalCount, hf]
      rcases hnonempty with hi | hfrac
      · have hp : 0 < x.integerDigits.length := by
          cases hx : x.integerDigits with
          | nil => simp [hx] at hi
          | cons a rest => simp
        omega
      · have hp : 0 < ds.length := by
          cases hd : ds with
          | nil =>
            have hds : ds ≠ [] := by simpa [hf] using hfrac
            exact False.elim (hds (by simp [hd]))
          | cons a rest => simp
        omega
  let zeroPrefix := intBytes ++ dotBytes
  have hbyte48 : byteOfNat 48 = 48#u8 := by
    apply UScalar.eq_of_val_eq
    simp [byteOfNat, UScalar.ofNatCore_val_eq]
  have hintBytesZero : ∀ b, b ∈ intBytes → b = 48#u8 := by
    intro b hb
    rcases List.mem_map.mp hb with ⟨n, hn, rfl⟩
    rcases List.mem_map.mp hn with ⟨digit, _, rfl⟩
    exact hbyte48
  have hdotCase : ∀ ds, x.fractionDigits = some ds →
      dotBytes = 46#u8 :: fracBytes := by
    intro ds hf
    simp only [dotBytes, dotNat, hf, List.map_cons, fracBytes]
    have h46 : byteOfNat 46 = 46#u8 := by
      apply UScalar.eq_of_val_eq
      simp [byteOfNat, UScalar.ofNatCore_val_eq]
    rw [h46]
  have hprefixChar : ∀ b, b ∈ zeroPrefix → b = 48#u8 ∨ b = 46#u8 := by
    intro b hb
    rcases List.mem_append.mp hb with hi | hd
    · left
      exact hintBytesZero b hi
    · cases hf : x.fractionDigits with
      | none => simp [dotBytes, dotNat, hf] at hd
      | some ds =>
        rw [hdotCase ds hf] at hd
        rcases List.mem_cons.mp hd with heq | hfrac
        · exact Or.inr heq
        · left
          have hbval := hfracBytesZero b hfrac
          apply UScalar.eq_of_val_eq
          simpa using hbval
  have countZeros : ∀ bytes : List Std.U8,
      (∀ b, b ∈ bytes → b = 48#u8) → bytes.count 48#u8 = bytes.length := by
    intro bytes
    induction bytes with
    | nil => intro; rfl
    | cons b bs ih =>
      intro hall
      have hb := hall b List.mem_cons_self
      have htail : ∀ c, c ∈ bs → c = 48#u8 := by
        intro c hc
        exact hall c (List.mem_cons_of_mem _ hc)
      subst b
      simp [ih htail]
  have hintCount : intBytes.count 48#u8 = x.integerDigits.length := by
    rw [countZeros intBytes hintBytesZero, hintByteLength]
  have hfracCount : fracBytes.count 48#u8 = fracBytes.length :=
    countZeros fracBytes (by intro b hb; apply UScalar.eq_of_val_eq; simpa using hfracBytesZero b hb)
  have hdotCount : dotBytes.count 48#u8 = fractionalCount := by
    cases hf : x.fractionDigits with
    | none => simp [dotBytes, dotNat, fractionalCount, hf]
    | some ds =>
      rw [hdotCase ds hf]
      simp [hfracCount, fractionalCount, hf, hfractionalByteLength]
  have hprefixCount : zeroPrefix.count 48#u8 = digitCount := by
    change (intBytes ++ dotBytes).count 48#u8 = digitCount
    rw [List.count_append, hintCount, hdotCount]
  have hstartAdjustment : s.val = zeroPrefix ++ expBytes := by
    simpa [zeroPrefix, List.append_assoc] using hsourceBytes
  have htailAdjustment : expBytes = [] ∨
      ∃ b rest, expBytes = b :: rest ∧ b ≠ 48#u8 ∧ b ≠ 46#u8 := by
    cases ht : expBytes with
    | nil => exact Or.inl rfl
    | cons b rest =>
      cases hx : x.exponent with
      | none => simp [expBytes, expNat, hx] at ht
      | some tuple =>
        rcases tuple with ⟨upper, sign, digits⟩
        have hhead : List.head? expBytes = some b := by rw [ht]; rfl
        cases upper with
        | false =>
          have hb : b = byteOfNat 101 := by
            simpa [expBytes, expNat, hx] using hhead.symm
          subst b
          exact Or.inr ⟨byteOfNat 101, rest, rfl, by norm_num [byteOfNat],
            by norm_num [byteOfNat]⟩
        | true =>
          have hb : b = byteOfNat 69 := by
            simpa [expBytes, expNat, hx] using hhead.symm
          subst b
          exact Or.inr ⟨byteOfNat 69, rest, rfl, by norm_num [byteOfNat],
            by norm_num [byteOfNat]⟩
  have hadjustmentExact : ∀ nMore, totalDigits - 19#isize = ok nMore →
      ¬ (totalDigits.val ≤ 19) →
      ∃ adjusted, num.imp.dec2flt.parse.adjust_many_digit_count s nMore =
          ok adjusted ∧ adjusted.val = -19 := by
    intro nMore hsub hlarge
    have hsubEquiv := IScalar.sub_equiv totalDigits 19#isize
    rw [hsub] at hsubEquiv
    have hnMoreVal : nMore.val = totalDigits.val - 19 := by
      simpa using hsubEquiv.2.1
    have hnMoreNonneg : 0 ≤ nMore.val := by
      rw [hnMoreVal]
      omega
    have hnMoreLe : nMore.val ≤ s.val.length := by
      rw [hnMoreVal, htotalDigitCount]
      omega
    have hadjustLower : IScalar.min .Isize ≤
        nMore.val - (zeroPrefix.count 48#u8 : Int) := by
      rw [hnMoreVal, hprefixCount, htotalDigitCount]
      simp [IScalar.min, IScalarTy.numBits,
        Dec2Flt.P340_T1_selected_target_numBits]
    obtain ⟨adjusted, hadjusted, hadjustedVal⟩ :=
      P364_T1_NumberHelperAdjustCountExact s nMore zeroPrefix expBytes
        hstartAdjustment hprefixChar htailAdjustment hsource
        hnMoreNonneg hnMoreLe hadjustLower
    have hadjustedExact : adjusted.val = -19 := by
      rw [hprefixCount, ← htotalDigitCount] at hadjustedVal
      rw [hnMoreVal] at hadjustedVal
      simp at hadjustedVal
      omega
    exact ⟨adjusted, hadjusted, hadjustedExact⟩
  have hnoRetry : ∀ nMore adjusted,
      totalDigits - 19#isize = ok nMore →
      num.imp.dec2flt.parse.adjust_many_digit_count s nMore = ok adjusted →
      ¬ (totalDigits.val ≤ 19) → ¬ (0 < adjusted.val) := by
    intro nMore adjusted hsub hadjust hlarge hpos
    obtain ⟨adjustedExact, hadjustedExact, hvalue⟩ :=
      hadjustmentExact nMore hsub hlarge
    rw [hadjust] at hadjustedExact
    injection hadjustedExact with hEq
    subst adjustedExact
    rw [hvalue] at hpos
    norm_num at hpos
  have htotalNonzero : totalDigits ≠ 0#isize := by
    intro hz
    simp [hz] at hpartialAfterCount
  obtain ⟨suffixOpt, hsplitSuffix, hpartialAfterSuffixSplit⟩ :=
    bind_ok_inv _ _ _ (by simpa [htotalNonzero] using hpartialAfterCount)
  have recordBranchNegative : ∀ (total : Std.Isize) (shortMantissa : Std.U64)
      (intEnd : Slice Std.U8) (shortExponent retryExponent : Std.I64)
      (consumed outLen : Std.Usize),
      (if total.val ≤ 19 then
          ok (some (num.imp.dec2flt.decimal.Decimal.mk shortExponent
            shortMantissa false false, consumed))
        else do
          let nMore ← total - 19#isize
          let adjusted ← num.imp.dec2flt.parse.adjust_many_digit_count s nMore
          if 0 < adjusted.val then
            let (manyMantissa, manyExponent) ←
              num.imp.dec2flt.parse.parse_many_digits s intEnd retryExponent
            ok (some (num.imp.dec2flt.decimal.Decimal.mk manyExponent
              manyMantissa false true, consumed))
          else
            ok (some (num.imp.dec2flt.decimal.Decimal.mk shortExponent
              shortMantissa false false, consumed))) = ok (some (d, outLen)) →
        d.negative = false := by
    intro total shortMantissa intEnd shortExponent retryExponent consumed outLen hresult
    by_cases hsmall : total.val ≤ 19
    · simp [hsmall] at hresult
      rcases hresult with ⟨rfl, rfl⟩
      rfl
    · simp [hsmall] at hresult
      obtain ⟨nMore, hsub, hresult⟩ := bind_ok_inv _ _ _ hresult
      obtain ⟨adjusted, hadjust, hresult⟩ := bind_ok_inv _ _ _ hresult
      by_cases hpositive : 0 < adjusted.val
      · simp [hpositive] at hresult
        obtain ⟨manyResult, hmany, hresult⟩ := bind_ok_inv _ _ _ hresult
        rcases manyResult with ⟨manyMantissa, manyExponent⟩
        rcases hresult with ⟨rfl, rfl⟩
        rfl
      · simp [hpositive] at hresult
        rcases hresult with ⟨rfl, rfl⟩
        rfl
  have recordBranchZero : ∀ (total : Std.Isize) (shortMantissa : Std.U64)
      (intEnd : Slice Std.U8) (shortExponent retryExponent : Std.I64)
      (consumed outLen : Std.Usize),
      shortMantissa.val = 0 →
      (∀ nMore adjusted,
        total - 19#isize = ok nMore →
        num.imp.dec2flt.parse.adjust_many_digit_count s nMore = ok adjusted →
        ¬ (total.val ≤ 19) → ¬ (0 < adjusted.val)) →
      (if total.val ≤ 19 then
          ok (some (num.imp.dec2flt.decimal.Decimal.mk shortExponent
            shortMantissa false false, consumed))
        else do
          let nMore ← total - 19#isize
          let adjusted ← num.imp.dec2flt.parse.adjust_many_digit_count s nMore
          if 0 < adjusted.val then
            let (manyMantissa, manyExponent) ←
              num.imp.dec2flt.parse.parse_many_digits s intEnd retryExponent
            ok (some (num.imp.dec2flt.decimal.Decimal.mk manyExponent
              manyMantissa false true, consumed))
          else
            ok (some (num.imp.dec2flt.decimal.Decimal.mk shortExponent
              shortMantissa false false, consumed))) = ok (some (d, outLen)) →
        d.mantissa.val = 0 ∧ d.many_digits = false := by
    intro total shortMantissa intEnd shortExponent retryExponent consumed outLen hshort hretry hresult
    by_cases hsmall : total.val ≤ 19
    · simp [hsmall] at hresult
      rcases hresult with ⟨rfl, rfl⟩
      exact ⟨hshort, rfl⟩
    · simp [hsmall] at hresult
      obtain ⟨nMore, hsub, hresult⟩ := bind_ok_inv _ _ _ hresult
      obtain ⟨adjusted, hadjust, hresult⟩ := bind_ok_inv _ _ _ hresult
      by_cases hpositive : 0 < adjusted.val
      · have hfalse := hretry nMore adjusted hsub hadjust hsmall hpositive
        contradiction
      · simp [hpositive] at hresult
        rcases hresult with ⟨rfl, rfl⟩
        exact ⟨hshort, rfl⟩
  have hnegative : d.negative = false := by
    cases suffixOpt with
    | none =>
      simp at hpartialAfterSuffixSplit
      obtain ⟨off, hoff, hrest⟩ := bind_ok_inv _ _ _ hpartialAfterSuffixSplit
      obtain ⟨outLen, hcast, hrest⟩ := bind_ok_inv _ _ _ hrest
      exact recordBranchNegative totalDigits mantissa1 scanRest baseExponent
        0#i64 outLen len (by simpa using hrest)
    | some pair =>
      rcases pair with ⟨marker, suffix⟩
      by_cases hlower : marker = 101#u8
      · subst marker
        obtain ⟨sciResult, hsci, hrest⟩ := bind_ok_inv _ _ _ hpartialAfterSuffixSplit
        rcases sciResult with ⟨optionExp, sciRest⟩
        cases optionExp with
        | none =>
          simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch, ModelOptionBranch,
            core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
            ModelOptionFromResidual] at hrest
        | some parsedExp =>
          simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch, ModelOptionBranch] at hrest
          obtain ⟨combined, hsum, hrest⟩ := bind_ok_inv _ _ _ hrest
          obtain ⟨off, hoff, hrest⟩ := bind_ok_inv _ _ _ hrest
          obtain ⟨outLen, hcast, hrest⟩ := bind_ok_inv _ _ _ hrest
          exact recordBranchNegative totalDigits mantissa1 scanRest combined
            parsedExp outLen len (by simpa using hrest)
      · by_cases hupper : marker = 69#u8
        · subst marker
          obtain ⟨sciResult, hsci, hrest⟩ := bind_ok_inv _ _ _ hpartialAfterSuffixSplit
          rcases sciResult with ⟨optionExp, sciRest⟩
          cases optionExp with
          | none =>
            simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch, ModelOptionBranch,
              core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
              ModelOptionFromResidual] at hrest
          | some parsedExp =>
            simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch, ModelOptionBranch] at hrest
            obtain ⟨combined, hsum, hrest⟩ := bind_ok_inv _ _ _ hrest
            obtain ⟨off, hoff, hrest⟩ := bind_ok_inv _ _ _ hrest
            obtain ⟨outLen, hcast, hrest⟩ := bind_ok_inv _ _ _ hrest
            exact recordBranchNegative totalDigits mantissa1 scanRest combined
              parsedExp outLen len (by simpa using hrest)
        · simp [hlower, hupper] at hpartialAfterSuffixSplit
          obtain ⟨off, hoff, hrest⟩ := bind_ok_inv _ _ _ hpartialAfterSuffixSplit
          obtain ⟨outLen, hcast, hrest⟩ := bind_ok_inv _ _ _ hrest
          exact recordBranchNegative totalDigits mantissa1 scanRest baseExponent
            0#i64 outLen len (by simpa using hrest)
  have hfields : d.mantissa.val = 0 ∧ d.many_digits = false := by
    cases suffixOpt with
    | none =>
      simp at hpartialAfterSuffixSplit
      obtain ⟨off, hoff, hrest⟩ := bind_ok_inv _ _ _ hpartialAfterSuffixSplit
      obtain ⟨outLen, hcast, hrest⟩ := bind_ok_inv _ _ _ hrest
      apply recordBranchZero totalDigits mantissa1 scanRest baseExponent
        0#i64 outLen len
      · exact hmantissaZero
      · exact hnoRetry
      · simpa using hrest
    | some pair =>
      rcases pair with ⟨marker, suffix⟩
      by_cases hlower : marker = 101#u8
      · subst marker
        obtain ⟨sciResult, hsci, hrest⟩ := bind_ok_inv _ _ _ hpartialAfterSuffixSplit
        rcases sciResult with ⟨optionExp, sciRest⟩
        cases optionExp with
        | none =>
          simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch, ModelOptionBranch,
            core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
            ModelOptionFromResidual] at hrest
        | some parsedExp =>
          simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch, ModelOptionBranch] at hrest
          obtain ⟨combined, hsum, hrest⟩ := bind_ok_inv _ _ _ hrest
          obtain ⟨off, hoff, hrest⟩ := bind_ok_inv _ _ _ hrest
          obtain ⟨outLen, hcast, hrest⟩ := bind_ok_inv _ _ _ hrest
          apply recordBranchZero totalDigits mantissa1 scanRest combined
            parsedExp outLen len
          · exact hmantissaZero
          · exact hnoRetry
          · simpa using hrest
      · by_cases hupper : marker = 69#u8
        · subst marker
          obtain ⟨sciResult, hsci, hrest⟩ := bind_ok_inv _ _ _ hpartialAfterSuffixSplit
          rcases sciResult with ⟨optionExp, sciRest⟩
          cases optionExp with
          | none =>
            simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch, ModelOptionBranch,
              core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
              ModelOptionFromResidual] at hrest
          | some parsedExp =>
            simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch, ModelOptionBranch] at hrest
            obtain ⟨combined, hsum, hrest⟩ := bind_ok_inv _ _ _ hrest
            obtain ⟨off, hoff, hrest⟩ := bind_ok_inv _ _ _ hrest
            obtain ⟨outLen, hcast, hrest⟩ := bind_ok_inv _ _ _ hrest
            apply recordBranchZero totalDigits mantissa1 scanRest combined
              parsedExp outLen len
            · exact hmantissaZero
            · exact hnoRetry
            · simpa using hrest
        · simp [hlower, hupper] at hpartialAfterSuffixSplit
          obtain ⟨off, hoff, hrest⟩ := bind_ok_inv _ _ _ hpartialAfterSuffixSplit
          obtain ⟨outLen, hcast, hrest⟩ := bind_ok_inv _ _ _ hrest
          apply recordBranchZero totalDigits mantissa1 scanRest baseExponent
            0#i64 outLen len
          · exact hmantissaZero
          · exact hnoRetry
          · simpa using hrest
  refine ⟨?_, ?_, hnegative⟩
  · exact hfields.1
  · exact hfields.2

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalGoalVocabularyDefault
import Tablet.Assumptions
import Tablet.SourceValidByteSlice
import Tablet.NumberHelperDigitScanExact
import Tablet.P364_T1_NumberHelperOffsetSourceLength
import Tablet.P364_T1_NumberHelperAdjustCountExact
import Tablet.ModelSliceSplitFirst
import Tablet.ModelOptionBranch
import Tablet.ModelOptionFromResidual
import Tablet.num_imp_dec2flt_parse_parse_number
import Tablet.num_imp_dec2flt_parse_parse_partial_number

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P401_T1_UnsignedZeroRecord]
theorem P401_T1_UnsignedZeroRecord
    (s : Slice Std.U8) (x : DecimalLexeme)
    (d : num.imp.dec2flt.decimal.Decimal)
    (hsource : SourceValidByteSlice s)
    (hsign : x.leadingSign = none)
    (hvalid : DecimalGoalVocabularyDefault.validNumeric x)
    (hrender : DecimalGoalVocabularyDefault.renderNumeric x =
      DecimalGoalVocabularyDefault.bytes s)
    (hzero : ∀ digit ∈ (x.integerDigits ++
      match x.fractionDigits with | none => [] | some ds => ds), digit = 0)
    (hresult : num.imp.dec2flt.parse.parse_number s = ok (some d)) :
    d.mantissa.val = 0 ∧ d.many_digits = false ∧ d.negative = false := by
-- BODY
  have hpartial : ∃ len : Std.Usize,
      num.imp.dec2flt.parse.parse_partial_number s = ok (some (d, len)) := by
    unfold num.imp.dec2flt.parse.parse_number at hresult
    cases hp : num.imp.dec2flt.parse.parse_partial_number s with
    | fail err => simp [hp] at hresult
    | div => simp [hp] at hresult
    | ok out =>
      cases out with
      | none => simp [hp] at hresult
      | some pair =>
        rcases pair with ⟨d', len⟩
        simp [hp] at hresult
        split at hresult
        · simp_all
        · simp at hresult
  rcases hpartial with ⟨len, hpartial⟩
  have bind_ok_inv : ∀ {α β : Type} (r : Result α)
      (f : α → Result β) y, Bind.bind r f = ok y →
      ∃ z, r = ok z ∧ f z = ok y := by
    intro α β r f y h
    cases r with
    | fail err => simp [Bind.bind, Aeneas.Std.bind] at h
    | div => simp [Bind.bind, Aeneas.Std.bind] at h
    | ok z => exact ⟨z, rfl, h⟩
  have hpartialExec := hpartial
  unfold num.imp.dec2flt.parse.parse_partial_number at hpartialExec
  obtain ⟨isEmpty, hempty, hafterEmpty⟩ := bind_ok_inv _ _ _ hpartialExec
  obtain ⟨_, hmassert, hafterAssert⟩ := bind_ok_inv _ _ _ hafterEmpty
  cases isEmpty <;> simp [massert] at hmassert
  obtain ⟨scanOut, hscan, hafterScan⟩ := bind_ok_inv _ _ _ hafterAssert
  have hvalid' := hvalid
  simp [DecimalGoalVocabularyDefault] at hvalid'
  rcases hvalid' with ⟨hint, hfrac, hnonempty, hexp⟩
  let fracDigits := match x.fractionDigits with | none => [] | some ds => ds
  have hzeroInt : ∀ digit, digit ∈ x.integerDigits → digit = 0 := by
    intro digit hd
    exact hzero digit (List.mem_append_left _ hd)
  have hzeroFrac : ∀ digit, digit ∈ fracDigits → digit = 0 := by
    intro digit hd
    cases hf : x.fractionDigits with
    | none => simp [fracDigits, hf] at hd
    | some ds =>
      simp [fracDigits, hf] at hd
      exact hzero digit (by simpa [fracDigits, hf] using List.mem_append_right x.integerDigits hd)
  have mapZero : ∀ ds : List Nat, (∀ n, n ∈ ds → n = 0) →
      ds.map (fun n => 48 + n) = ds.map (fun _ => 48) := by
    intro ds
    induction ds with
    | nil => intro; rfl
    | cons n ns ih =>
      intro hn
      have hn0 := hn n List.mem_cons_self
      simp only [List.map_cons, hn0]
      exact congrArg (List.cons 48) (ih (by intro m hm; exact hn m (List.mem_cons_of_mem _ hm)))
  have hrenderNat :
      (x.integerDigits.map (fun _ => 48) ++
        (match x.fractionDigits with
          | none => []
          | some _ => 46 :: fracDigits.map (fun _ => 48))) ++
        (match x.exponent with
          | none => []
          | some (upper, sign, ds) =>
              (if upper then 69 else 101) ::
                (match sign with | none => [] | some neg => [if neg then 45 else 43]) ++
                  ds.map (fun n => 48 + n)) = s.val.map (fun b => b.val) := by
    have hvals := hrender
    simp [DecimalGoalVocabularyDefault, hsign] at hvals
    rw [mapZero x.integerDigits hzeroInt] at hvals
    cases hf : x.fractionDigits with
    | none => simpa [fracDigits, hf, List.append_assoc] using hvals
    | some ds =>
      have hz := mapZero ds (by
        intro n hn
        exact hzero n (by simpa [hf] using List.mem_append_right x.integerDigits hn))
      simpa [fracDigits, hf, hz, List.append_assoc] using hvals
  let intNat := x.integerDigits.map (fun _ => 48)
  let fracNat := fracDigits.map (fun _ => 48)
  let dotNat := match x.fractionDigits with | none => [] | some _ => 46 :: fracNat
  let expNat := match x.exponent with
    | none => []
    | some (upper, sign, ds) =>
        (if upper then 69 else 101) ::
          (match sign with | none => [] | some neg => [if neg then 45 else 43]) ++
            ds.map (fun n => 48 + n)
  let renderedNat := intNat ++ dotNat ++ expNat
  have hrenderNat' : renderedNat = s.val.map (fun b => b.val) := by
    simpa [renderedNat, intNat, dotNat, expNat, fracNat, fracDigits,
      List.append_assoc] using hrenderNat
  have hrenderNonempty : renderedNat ≠ [] := by
    rcases hnonempty with hi | hf
    · cases hx : x.integerDigits with
      | nil => simp [hx] at hi
      | cons a ds => simp [renderedNat, intNat, hx]
    · cases hx : x.fractionDigits with
      | none => simp [hx] at hf
      | some ds =>
        cases hd : ds with
        | nil => simp [hx, hd] at hf
        | cons a ds' => simp [renderedNat, intNat, dotNat, fracNat, hx, hd]
  have hsourceNonempty : s.val ≠ [] := by
    intro hs
    apply hrenderNonempty
    simpa [hs] using hrenderNat'
  have hrenderSmall : ∀ n, n ∈ renderedNat → n < 256 := by
    intro n hn
    have hp : n ∈ intNat ++ dotNat ++ expNat := by
      simpa [renderedNat] using hn
    rcases List.mem_append.mp hp with hprefix | he
    · rcases List.mem_append.mp hprefix with hi | hd
      · rcases List.mem_map.mp hi with ⟨d, _, rfl⟩
        norm_num
      · cases hf : x.fractionDigits with
        | none => simp [dotNat, hf] at hd
        | some ds =>
          simp [dotNat, hf] at hd
          rcases hd with rfl | hd
          · norm_num
          · rcases List.mem_map.mp hd with ⟨d, _, rfl⟩
            norm_num
    · cases hx : x.exponent with
      | none => simp [expNat, hx] at he
      | some e =>
        rcases e with ⟨upper, sign, ds⟩
        simp [expNat, hx] at he
        rcases he with hhead | hs
        · rw [hhead]
          split <;> norm_num
        · rcases hs with hsign | hd
          · cases sign with
            | none => simp at hsign
            | some neg => cases neg <;> simp at hsign <;> omega
          · rcases hd with ⟨d, hdm, heq⟩
            have hexp' : ds ≠ [] ∧ ∀ d, d ∈ ds → d < 10 := by
              simpa [hx] using hexp
            have hdigit := hexp'.2 d hdm
            omega
  let byteOfNat := fun n : Nat =>
    @UScalar.ofNatCore .U8 (n % 256) (by exact Nat.mod_lt _ (by omega))
  have mapByteValues : ∀ ns : List Nat,
      (∀ n, n ∈ ns → n < 256) →
      List.map (fun b : Std.U8 => b.val) (ns.map byteOfNat) = ns := by
    intro ns
    induction ns with
    | nil => intro; rfl
    | cons n ns ih =>
      intro hn
      simp only [List.map_cons, List.map_map, Function.comp_apply]
      have hlt := hn n List.mem_cons_self
      have htail := ih (by intro m hm; exact hn m (List.mem_cons_of_mem _ hm))
      have hhead : (byteOfNat n).val = n := by
        simp [byteOfNat, UScalar.ofNatCore_val_eq, Nat.mod_eq_of_lt hlt]
      rw [hhead]
      simpa only [List.map_map] using congrArg (List.cons n) htail
  let intBytes := intNat.map byteOfNat
  let dotBytes := dotNat.map byteOfNat
  let expBytes := expNat.map byteOfNat
  have mapByteInj : Function.Injective (List.map (fun b : Std.U8 => b.val)) := by
    intro l1 l2 heq
    induction l1 generalizing l2 with
    | nil => cases l2 <;> simp at heq ⊢
    | cons a xs ih =>
      cases l2 with
      | nil => simp at heq
      | cons b bs =>
        simp only [List.map_cons] at heq
        injection heq with hhead htail
        have hab : a = b := UScalar.eq_of_val_eq hhead
        subst b
        exact congrArg (List.cons a) (ih htail)
  have hsourceBytes : s.val = intBytes ++ dotBytes ++ expBytes := by
    apply mapByteInj
    have hmap : s.val.map (fun b => b.val) =
        (renderedNat.map byteOfNat).map (fun b => b.val) := by
      rw [mapByteValues renderedNat hrenderSmall]
      exact hrenderNat'.symm
    simpa [intBytes, dotBytes, expBytes, renderedNat, List.map_append,
      List.append_assoc] using hmap
  let scanTail := dotBytes ++ expBytes
  have hscanPartition : s.val = intBytes ++ scanTail := by
    simpa [scanTail, List.append_assoc] using hsourceBytes
  have hscanDigits : ∀ b, b ∈ intBytes → 48 ≤ b.val ∧ b.val ≤ 57 := by
    intro b hb
    rcases List.mem_map.mp hb with ⟨n, hn, rfl⟩
    rcases List.mem_map.mp hn with ⟨d, _, rfl⟩
    simp [byteOfNat]
  have hscanTail : ∀ b rest, scanTail = b :: rest →
      ¬ (48 ≤ b.val ∧ b.val ≤ 57) := by
    intro b rest htail
    cases hf : x.fractionDigits with
    | some ds =>
      have : b = byteOfNat 46 := by
        simp [scanTail, dotBytes, dotNat, hf, List.map_append] at htail
        exact htail.1.symm
      rw [this]
      norm_num [byteOfNat]
    | none =>
      cases he : x.exponent with
      | none => simp [scanTail, dotBytes, dotNat, expBytes, expNat, hf, he] at htail
      | some e =>
        rcases e with ⟨upper, sign, ds⟩
        have : b = byteOfNat (if upper then 69 else 101) := by
          simp [scanTail, dotBytes, dotNat, expBytes, expNat, hf, he,
            List.map_append] at htail
          exact htail.1.symm
        rw [this]
        cases upper <;> norm_num [byteOfNat]
  have foldZero : ∀ ns : List Nat, (∀ n, n ∈ ns → n = 48) →
      (ns.map byteOfNat).foldl (fun a b => 10 * a + (b.val - 48)) 0 = 0 := by
    intro ns
    induction ns with
    | nil => intro; rfl
    | cons n ns ih =>
      intro hn
      have hn48 := hn n List.mem_cons_self
      simp only [List.map_cons, List.foldl_cons]
      have hb : (byteOfNat n).val = 48 := by rw [hn48]; norm_num [byteOfNat]
      simp [hb, ih (by intro m hm; exact hn m (List.mem_cons_of_mem _ hm))]
  have hscanFold : intBytes.foldl
      (fun a b => 10 * a + (b.val - 48)) 0 = 0 := by
    simpa [intBytes] using foldZero intNat (by
      intro n hn
      rcases List.mem_map.mp hn with ⟨v, _, rfl⟩
      rfl)
  let fracBytes := fracNat.map byteOfNat
  have hfracFold : fracBytes.foldl
      (fun a b => 10 * a + (b.val - 48)) 0 = 0 := by
    simpa [fracBytes] using foldZero fracNat (by
      intro n hn
      rcases List.mem_map.mp hn with ⟨v, _, rfl⟩
      rfl)
  have hfracBytesZero : ∀ b, b ∈ fracBytes → b.val = 48 := by
    intro b hb
    rcases List.mem_map.mp hb with ⟨n, hn, rfl⟩
    rcases List.mem_map.mp hn with ⟨v, _, rfl⟩
    simp [byteOfNat]
  have hfracLeDot : fracBytes.length ≤ dotBytes.length := by
    cases hf : x.fractionDigits with
    | none => simp [dotBytes, dotNat, fracBytes, fracNat, fracDigits, hf]
    | some ds =>
      simp [dotBytes, dotNat, fracBytes, fracNat, fracDigits, hf]
  have hfracSuffixLe : (fracBytes ++ expBytes).length ≤ s.val.length := by
    calc
      (fracBytes ++ expBytes).length = fracBytes.length + expBytes.length := by simp
      _ ≤ dotBytes.length + expBytes.length := Nat.add_le_add_right hfracLeDot _
      _ ≤ (intBytes ++ dotBytes ++ expBytes).length := by simp [List.length_append]
      _ = s.val.length := by rw [hsourceBytes]
  let fractionSlice : Slice Std.U8 := ⟨fracBytes ++ expBytes,
    le_trans hfracSuffixLe s.property⟩
  have hfracTailNotDigit : ∀ b rest, expBytes = b :: rest →
      ¬ (48 ≤ b.val ∧ b.val ≤ 57) := by
    intro b rest he
    cases hx : x.exponent with
    | none => simp [expBytes, expNat, hx] at he
    | some tuple =>
      rcases tuple with ⟨upper, sign, digits⟩
      have hhead : List.head? expBytes = some b := by rw [he]; rfl
      cases upper <;> simp [expBytes, expNat, hx, byteOfNat] at hhead
      all_goals rw [← hhead] <;> norm_num
  have hfracByteDigits : ∀ b, b ∈ fracBytes → 48 ≤ b.val ∧ b.val ≤ 57 := by
    intro b hb
    rw [hfracBytesZero b hb]
    norm_num
  have hfracFoldBound : fracBytes.foldl
      (fun a b => 10 * a + (b.val - 48)) (0#u64).val ≤ U64.max := by
    change fracBytes.foldl (fun a b => 10 * a + (b.val - 48)) 0 ≤ U64.max
    rw [hfracFold]
    exact Nat.zero_le _
  have hfracSource : SourceValidByteSlice fractionSlice := by
    change fractionSlice.val.length ≤ 9223372036854775807
    exact Nat.le_trans hfracSuffixLe hsource
  obtain ⟨fractionValue, fractionRest, hfractionScan, hfractionRest,
      hfractionValue⟩ := NumberHelperDigitScanExact fractionSlice 0#u64
    fracBytes expBytes (by simp [fractionSlice]) hfracByteDigits
    hfracTailNotDigit hfracSource hfracFoldBound
  have hfractionValueZero : fractionValue.val = 0 := by
    simpa [hfracFold] using hfractionValue
  have hfoldBound : intBytes.foldl
      (fun a b => 10 * a + (b.val - 48)) (0#u64).val ≤ U64.max := by
    simpa [hscanFold] using (Nat.zero_le U64.max)
  have hscanCert := NumberHelperDigitScanExact s 0#u64 intBytes scanTail
    hscanPartition hscanDigits hscanTail hsource hfoldBound
  rcases hscanCert with ⟨scanValue, scanRest, hcert, hrest, hscanValue⟩
  have hscanPair : scanOut = (scanRest, scanValue) := by
    rw [hcert] at hscan
    injection hscan with hpair
    exact hpair.symm
  subst scanOut
  have hscanValueZero : scanValue.val = 0 := by
    simpa [hscanFold] using hscanValue
  have hscanRestEq : scanRest.val = scanTail := hrest
  let tailSlice : Slice Std.U8 := ⟨scanTail, by
    rw [← hscanRestEq]
    exact scanRest.property⟩
  have hscanRestSlice : scanRest = tailSlice :=
    (Slice.eq_iff _ _).2 hscanRestEq
  obtain ⟨nDigits, hoffset, hafterOffset⟩ :=
    bind_ok_inv _ _ _ hafterScan
  have htailLe : scanRest.val.length ≤ s.val.length := by
    rw [hscanRestEq, hscanPartition]
    simp
  obtain ⟨off, hoff, hoffVal⟩ :=
    P364_T1_NumberHelperOffsetSourceLength s scanRest hsource htailLe
  have hoffEq : nDigits = off := by
    rw [hoff] at hoffset
    injection hoffset with h
    exact h.symm
  have hcountEq : nDigits.val = x.integerDigits.length := by
    have hintByteLen : intBytes.length = x.integerDigits.length := by
      simp [intBytes, intNat]
    have hlenPartitionNat : s.val.length = intBytes.length + scanTail.length := by
      rw [hscanPartition]
      simp
    have hlenPartition : (s.val.length : Int) =
        (intBytes.length : Int) + (scanTail.length : Int) := by
      exact_mod_cast hlenPartitionNat
    have hrestLen : (scanRest.val.length : Int) = (scanTail.length : Int) := by
      exact_mod_cast congrArg List.length hscanRestEq
    have hoffInt : off.val = (intBytes.length : Int) := by
      rw [hoffVal, hrestLen, hlenPartition]
      omega
    rw [hoffEq, hoffInt, hintByteLen]
  obtain ⟨dotOpt, hsplit, hafterSplit⟩ :=
    bind_ok_inv _ _ _ hafterOffset
  have hfracActual : ∀ ds, x.fractionDigits = some ds →
      dotOpt = some (46#u8, fractionSlice) := by
    intro ds hf
    have hdotBytes : dotBytes = 46#u8 :: fracBytes := by
      simp only [dotBytes, dotNat, hf, List.map_cons, fracBytes]
      have h46 : byteOfNat 46 = 46#u8 := by
        apply UScalar.eq_of_val_eq
        simp [byteOfNat, UScalar.ofNatCore_val_eq]
      rw [h46]
    have hshape : scanTail = 46#u8 :: (fracBytes ++ expBytes) := by
      simp [scanTail, hdotBytes]
    have hv : scanRest.val = 46#u8 :: (fracBytes ++ expBytes) := by
      rw [hscanRestEq, hshape]
    have hs : scanRest = ⟨46#u8 :: (fracBytes ++ expBytes), by
        rw [← hv]
        exact scanRest.property⟩ := (Slice.eq_iff _ _).2 hv
    rw [hs] at hsplit
    simp [core.slice.Slice.split_first, ModelSliceSplitFirst, fractionSlice] at hsplit
    exact hsplit.symm
  obtain ⟨afterSplit, hsplitContinuation, hafterSplitContinuation⟩ :=
    bind_ok_inv _ _ _ hafterSplit
  rcases afterSplit with ⟨s2, mantissa1, nAfterDot, baseExponent⟩
  have hscanValueEq : scanValue = 0#u64 := by
    apply UScalar.eq_of_val_eq
    exact hscanValueZero
  have hfracOutputs : ∀ ds, x.fractionDigits = some ds →
      s2 = fractionRest ∧ mantissa1 = fractionValue ∧
        nAfterDot.val = ds.length ∧ baseExponent.val = -(ds.length : Int) := by
    intro ds hf
    have hfracLenDs : fracBytes.length = ds.length := by
      simp [fracBytes, fracNat, fracDigits, hf, List.length_map]
    have hrestLe : fractionRest.val.length ≤ fractionSlice.val.length := by
      rw [hfractionRest]
      change expBytes.length ≤ (fracBytes ++ expBytes).length
      simp
    obtain ⟨fracCount, hoffFrac, hoffFracVal⟩ :=
      P364_T1_NumberHelperOffsetSourceLength fractionSlice fractionRest
        hfracSource hrestLe
    have hfracCountVal : fracCount.val = ds.length := by
      rw [hoffFracVal, hfractionRest]
      simp [fractionSlice, hfracLenDs]
    have hnotmin : fracCount.val ≠ IScalar.min .Isize := by
      rw [hfracCountVal, IScalar.min]
      norm_num [IScalarTy.numBits, Dec2Flt.P340_T1_selected_target_numBits]
      have hds : ds.length ≤ s.val.length := by
        rw [← hfracLenDs]
        exact Nat.le_trans (by simp) hfracSuffixLe
      have hsmax : s.val.length ≤ 9223372036854775807 := by
        simpa [SourceValidByteSlice] using hsource
      omega
    obtain ⟨fracNeg, hneg, hnegVal⟩ :=
      Aeneas.Std.WP.spec_imp_exists (HNeg.hNeg.step fracCount hnotmin)
    have hnegBounds : IScalar.min .I64 ≤ fracNeg.val ∧
        fracNeg.val ≤ IScalar.max .I64 := by
      rw [hnegVal, hfracCountVal,
        IScalar.min_IScalarTy_I64_eq, I64.min_eq,
        IScalar.max_IScalarTy_I64_eq, I64.max_eq]
      have hds : ds.length ≤ s.val.length := by
        rw [← hfracLenDs]
        exact Nat.le_trans (by simp) hfracSuffixLe
      have hsmax : s.val.length ≤ 9223372036854775807 := by
        simpa [SourceValidByteSlice] using hsource
      omega
    obtain ⟨base, hcast, hbaseVal⟩ :=
      Aeneas.Std.WP.spec_imp_exists (IScalar.cast_inBounds_spec .I64 fracNeg hnegBounds)
    rw [hfracActual ds hf] at hsplitContinuation
    dsimp at hsplitContinuation
    rw [hscanValueEq, hfractionScan] at hsplitContinuation
    simp only [bind_tc_ok] at hsplitContinuation
    simp [UScalar.ofNat, UScalar.ofNatCore] at hsplitContinuation
    rw [hoffFrac] at hsplitContinuation
    simp only [bind_tc_ok] at hsplitContinuation
    rw [hneg] at hsplitContinuation
    simp only [bind_tc_ok] at hsplitContinuation
    rw [hcast] at hsplitContinuation
    simp only [bind_tc_ok] at hsplitContinuation
    simp at hsplitContinuation
    rcases hsplitContinuation with ⟨h1, h2, h3, h4⟩
    exact ⟨h1.symm, h2.symm, by rw [← h3, hfracCountVal],
      by rw [← h4, hbaseVal, hnegVal, hfracCountVal]⟩
  have hnoFractionOutputs : x.fractionDigits = none →
      s2 = scanRest ∧ mantissa1 = scanValue ∧
        nAfterDot = 0#isize ∧ baseExponent = 0#i64 := by
    intro hf
    cases he : x.exponent with
    | none =>
      have hnil : scanTail = [] := by
        simp [scanTail, dotBytes, dotNat, expBytes, expNat, hf, he]
      have hv : scanRest.val = [] := by rw [hscanRestEq, hnil]
      have hs : scanRest = ⟨[], by rw [← hv]; exact scanRest.property⟩ :=
        (Slice.eq_iff _ _).2 hv
      have hd : dotOpt = none := by
        rw [hs] at hsplit
        simp [core.slice.Slice.split_first, ModelSliceSplitFirst] at hsplit
        exact hsplit.symm
      rw [hd] at hsplitContinuation
      simp at hsplitContinuation
      rcases hsplitContinuation with ⟨h1, h2, h3, h4⟩
      exact ⟨h1.symm, h2.symm, h3.symm, h4.symm⟩
    | some exponentData =>
      rcases exponentData with ⟨upper, sign, digits⟩
      let marker : Std.U8 := if upper then 69#u8 else 101#u8
      let signNat := (match sign with
          | none => []
          | some neg => [if neg then 45 else 43])
      let rest := signNat.map byteOfNat ++
        digits.map (fun n => byteOfNat (48 + n))
      have htail : scanTail = marker :: rest := by
        cases upper <;> simp [scanTail, dotBytes, dotNat, expBytes,
          expNat, hf, he, marker, rest, signNat, List.map_append,
          byteOfNat]
      have hrestLen : rest.length ≤ Usize.max := by
        have h := scanRest.property
        rw [hscanRestEq, htail] at h
        simp at h
        omega
      let restSlice : Slice Std.U8 := ⟨rest, hrestLen⟩
      have hv : scanRest.val = marker :: rest := by
        rw [hscanRestEq, htail]
      have hs : scanRest = ⟨marker :: rest, by rw [← hv]; exact scanRest.property⟩ :=
        (Slice.eq_iff _ _).2 hv
      have hd : dotOpt = some (marker, restSlice) := by
        rw [hs] at hsplit
        simp [core.slice.Slice.split_first, ModelSliceSplitFirst, restSlice] at hsplit
        exact hsplit.symm
      rw [hd] at hsplitContinuation
      cases upper with
      | false =>
        have htuple : scanRest = s2 ∧ scanValue = mantissa1 ∧
            (0#isize : Std.Isize) = nAfterDot ∧
            (0#i64 : Std.I64) = baseExponent := by
          simpa [marker, UScalar.ofNat, UScalar.ofNatCore] using hsplitContinuation
        rcases htuple with ⟨h1, h2, h3, h4⟩
        exact ⟨h1.symm, h2.symm, h3.symm, h4.symm⟩
      | true =>
        have htuple : scanRest = s2 ∧ scanValue = mantissa1 ∧
            (0#isize : Std.Isize) = nAfterDot ∧
            (0#i64 : Std.I64) = baseExponent := by
          simpa [marker, UScalar.ofNat, UScalar.ofNatCore] using hsplitContinuation
        rcases htuple with ⟨h1, h2, h3, h4⟩
        exact ⟨h1.symm, h2.symm, h3.symm, h4.symm⟩
  have hmantissaZero : mantissa1.val = 0 := by
    cases hf : x.fractionDigits with
    | none =>
      rw [(hnoFractionOutputs hf).2.1]
      exact hscanValueZero
    | some ds =>
      rw [(hfracOutputs ds hf).2.1]
      exact hfractionValueZero
  have hpartialFull : num.imp.dec2flt.parse.parse_partial_number s = ok (some (d, len)) :=
    hpartial
  unfold num.imp.dec2flt.parse.parse_partial_number at hpartialFull
  simp [hsourceNonempty, hscan, hoffset, hsplit] at hpartialFull
  rw [hsplitContinuation] at hpartialFull
  simp only [bind_tc_ok] at hpartialFull
  obtain ⟨totalDigits, htotal, hpartialAfterCount⟩ :=
    bind_ok_inv _ _ _ hpartialFull
  have htotalVal : totalDigits.val = nDigits.val + nAfterDot.val := by
    have heq := IScalar.add_equiv nDigits nAfterDot
    rw [htotal] at heq
    exact heq.2.1
  let fractionalCount := match x.fractionDigits with
    | none => 0
    | some ds => ds.length
  let digitCount := x.integerDigits.length + fractionalCount
  have htotalDigitCount : totalDigits.val = digitCount := by
    cases hf : x.fractionDigits with
    | none =>
      have hna := (hnoFractionOutputs hf).2.2.1
      rw [hcountEq, hna] at htotalVal
      simp [digitCount, fractionalCount, hf] at htotalVal ⊢
      omega
    | some ds =>
      have hna := (hfracOutputs ds hf).2.2.1
      rw [hcountEq, hna] at htotalVal
      simp [digitCount, fractionalCount, hf] at htotalVal ⊢
      omega
  have hsourceLength : s.val.length =
      intBytes.length + dotBytes.length + expBytes.length := by
    rw [hsourceBytes]
    simp [List.length_append, Nat.add_assoc]
  have hintByteLength : intBytes.length = x.integerDigits.length := by
    simp [intBytes, intNat]
  have hfractionalByteLength : fractionalCount = fracBytes.length := by
    cases hf : x.fractionDigits with
    | none => simp [fractionalCount, fracBytes, fracNat, fracDigits, hf]
    | some ds => simp [fractionalCount, fracBytes, fracNat, fracDigits, hf]
  have hdigitCountLe : digitCount ≤ s.val.length := by
    change x.integerDigits.length + fractionalCount ≤ s.val.length
    rw [← hintByteLength, hfractionalByteLength]
    rw [hsourceLength]
    omega
  have hdigitCountPos : 0 < digitCount := by
    cases hf : x.fractionDigits with
    | none =>
      simp [digitCount, fractionalCount, hf]
      rcases hnonempty with hi | hfrac
      · have hp : 0 < x.integerDigits.length := by
          cases hx : x.integerDigits with
          | nil => simp [hx] at hi
          | cons a ds => simp
        omega
      · simp [hf] at hfrac
    | some ds =>
      simp [digitCount, fractionalCount, hf]
      rcases hnonempty with hi | hfrac
      · have hp : 0 < x.integerDigits.length := by
          cases hx : x.integerDigits with
          | nil => simp [hx] at hi
          | cons a rest => simp
        omega
      · have hp : 0 < ds.length := by
          cases hd : ds with
          | nil =>
            have hds : ds ≠ [] := by simpa [hf] using hfrac
            exact False.elim (hds (by simp [hd]))
          | cons a rest => simp
        omega
  let zeroPrefix := intBytes ++ dotBytes
  have hbyte48 : byteOfNat 48 = 48#u8 := by
    apply UScalar.eq_of_val_eq
    simp [byteOfNat, UScalar.ofNatCore_val_eq]
  have hintBytesZero : ∀ b, b ∈ intBytes → b = 48#u8 := by
    intro b hb
    rcases List.mem_map.mp hb with ⟨n, hn, rfl⟩
    rcases List.mem_map.mp hn with ⟨digit, _, rfl⟩
    exact hbyte48
  have hdotCase : ∀ ds, x.fractionDigits = some ds →
      dotBytes = 46#u8 :: fracBytes := by
    intro ds hf
    simp only [dotBytes, dotNat, hf, List.map_cons, fracBytes]
    have h46 : byteOfNat 46 = 46#u8 := by
      apply UScalar.eq_of_val_eq
      simp [byteOfNat, UScalar.ofNatCore_val_eq]
    rw [h46]
  have hprefixChar : ∀ b, b ∈ zeroPrefix → b = 48#u8 ∨ b = 46#u8 := by
    intro b hb
    rcases List.mem_append.mp hb with hi | hd
    · left
      exact hintBytesZero b hi
    · cases hf : x.fractionDigits with
      | none => simp [dotBytes, dotNat, hf] at hd
      | some ds =>
        rw [hdotCase ds hf] at hd
        rcases List.mem_cons.mp hd with heq | hfrac
        · exact Or.inr heq
        · left
          have hbval := hfracBytesZero b hfrac
          apply UScalar.eq_of_val_eq
          simpa using hbval
  have countZeros : ∀ bytes : List Std.U8,
      (∀ b, b ∈ bytes → b = 48#u8) → bytes.count 48#u8 = bytes.length := by
    intro bytes
    induction bytes with
    | nil => intro; rfl
    | cons b bs ih =>
      intro hall
      have hb := hall b List.mem_cons_self
      have htail : ∀ c, c ∈ bs → c = 48#u8 := by
        intro c hc
        exact hall c (List.mem_cons_of_mem _ hc)
      subst b
      simp [ih htail]
  have hintCount : intBytes.count 48#u8 = x.integerDigits.length := by
    rw [countZeros intBytes hintBytesZero, hintByteLength]
  have hfracCount : fracBytes.count 48#u8 = fracBytes.length :=
    countZeros fracBytes (by intro b hb; apply UScalar.eq_of_val_eq; simpa using hfracBytesZero b hb)
  have hdotCount : dotBytes.count 48#u8 = fractionalCount := by
    cases hf : x.fractionDigits with
    | none => simp [dotBytes, dotNat, fractionalCount, hf]
    | some ds =>
      rw [hdotCase ds hf]
      simp [hfracCount, fractionalCount, hf, hfractionalByteLength]
  have hprefixCount : zeroPrefix.count 48#u8 = digitCount := by
    change (intBytes ++ dotBytes).count 48#u8 = digitCount
    rw [List.count_append, hintCount, hdotCount]
  have hstartAdjustment : s.val = zeroPrefix ++ expBytes := by
    simpa [zeroPrefix, List.append_assoc] using hsourceBytes
  have htailAdjustment : expBytes = [] ∨
      ∃ b rest, expBytes = b :: rest ∧ b ≠ 48#u8 ∧ b ≠ 46#u8 := by
    cases ht : expBytes with
    | nil => exact Or.inl rfl
    | cons b rest =>
      cases hx : x.exponent with
      | none => simp [expBytes, expNat, hx] at ht
      | some tuple =>
        rcases tuple with ⟨upper, sign, digits⟩
        have hhead : List.head? expBytes = some b := by rw [ht]; rfl
        cases upper with
        | false =>
          have hb : b = byteOfNat 101 := by
            simpa [expBytes, expNat, hx] using hhead.symm
          subst b
          exact Or.inr ⟨byteOfNat 101, rest, rfl, by norm_num [byteOfNat],
            by norm_num [byteOfNat]⟩
        | true =>
          have hb : b = byteOfNat 69 := by
            simpa [expBytes, expNat, hx] using hhead.symm
          subst b
          exact Or.inr ⟨byteOfNat 69, rest, rfl, by norm_num [byteOfNat],
            by norm_num [byteOfNat]⟩
  have hadjustmentExact : ∀ nMore, totalDigits - 19#isize = ok nMore →
      ¬ (totalDigits.val ≤ 19) →
      ∃ adjusted, num.imp.dec2flt.parse.adjust_many_digit_count s nMore =
          ok adjusted ∧ adjusted.val = -19 := by
    intro nMore hsub hlarge
    have hsubEquiv := IScalar.sub_equiv totalDigits 19#isize
    rw [hsub] at hsubEquiv
    have hnMoreVal : nMore.val = totalDigits.val - 19 := by
      simpa using hsubEquiv.2.1
    have hnMoreNonneg : 0 ≤ nMore.val := by
      rw [hnMoreVal]
      omega
    have hnMoreLe : nMore.val ≤ s.val.length := by
      rw [hnMoreVal, htotalDigitCount]
      omega
    have hadjustLower : IScalar.min .Isize ≤
        nMore.val - (zeroPrefix.count 48#u8 : Int) := by
      rw [hnMoreVal, hprefixCount, htotalDigitCount]
      simp [IScalar.min, IScalarTy.numBits,
        Dec2Flt.P340_T1_selected_target_numBits]
    obtain ⟨adjusted, hadjusted, hadjustedVal⟩ :=
      P364_T1_NumberHelperAdjustCountExact s nMore zeroPrefix expBytes
        hstartAdjustment hprefixChar htailAdjustment hsource
        hnMoreNonneg hnMoreLe hadjustLower
    have hadjustedExact : adjusted.val = -19 := by
      rw [hprefixCount, ← htotalDigitCount] at hadjustedVal
      rw [hnMoreVal] at hadjustedVal
      simp at hadjustedVal
      omega
    exact ⟨adjusted, hadjusted, hadjustedExact⟩
  have hnoRetry : ∀ nMore adjusted,
      totalDigits - 19#isize = ok nMore →
      num.imp.dec2flt.parse.adjust_many_digit_count s nMore = ok adjusted →
      ¬ (totalDigits.val ≤ 19) → ¬ (0 < adjusted.val) := by
    intro nMore adjusted hsub hadjust hlarge hpos
    obtain ⟨adjustedExact, hadjustedExact, hvalue⟩ :=
      hadjustmentExact nMore hsub hlarge
    rw [hadjust] at hadjustedExact
    injection hadjustedExact with hEq
    subst adjustedExact
    rw [hvalue] at hpos
    norm_num at hpos
  have htotalNonzero : totalDigits ≠ 0#isize := by
    intro hz
    simp [hz] at hpartialAfterCount
  obtain ⟨suffixOpt, hsplitSuffix, hpartialAfterSuffixSplit⟩ :=
    bind_ok_inv _ _ _ (by simpa [htotalNonzero] using hpartialAfterCount)
  have recordBranchNegative : ∀ (total : Std.Isize) (shortMantissa : Std.U64)
      (intEnd : Slice Std.U8) (shortExponent retryExponent : Std.I64)
      (consumed outLen : Std.Usize),
      (if total.val ≤ 19 then
          ok (some (num.imp.dec2flt.decimal.Decimal.mk shortExponent
            shortMantissa false false, consumed))
        else do
          let nMore ← total - 19#isize
          let adjusted ← num.imp.dec2flt.parse.adjust_many_digit_count s nMore
          if 0 < adjusted.val then
            let (manyMantissa, manyExponent) ←
              num.imp.dec2flt.parse.parse_many_digits s intEnd retryExponent
            ok (some (num.imp.dec2flt.decimal.Decimal.mk manyExponent
              manyMantissa false true, consumed))
          else
            ok (some (num.imp.dec2flt.decimal.Decimal.mk shortExponent
              shortMantissa false false, consumed))) = ok (some (d, outLen)) →
        d.negative = false := by
    intro total shortMantissa intEnd shortExponent retryExponent consumed outLen hresult
    by_cases hsmall : total.val ≤ 19
    · simp [hsmall] at hresult
      rcases hresult with ⟨rfl, rfl⟩
      rfl
    · simp [hsmall] at hresult
      obtain ⟨nMore, hsub, hresult⟩ := bind_ok_inv _ _ _ hresult
      obtain ⟨adjusted, hadjust, hresult⟩ := bind_ok_inv _ _ _ hresult
      by_cases hpositive : 0 < adjusted.val
      · simp [hpositive] at hresult
        obtain ⟨manyResult, hmany, hresult⟩ := bind_ok_inv _ _ _ hresult
        rcases manyResult with ⟨manyMantissa, manyExponent⟩
        rcases hresult with ⟨rfl, rfl⟩
        rfl
      · simp [hpositive] at hresult
        rcases hresult with ⟨rfl, rfl⟩
        rfl
  have recordBranchZero : ∀ (total : Std.Isize) (shortMantissa : Std.U64)
      (intEnd : Slice Std.U8) (shortExponent retryExponent : Std.I64)
      (consumed outLen : Std.Usize),
      shortMantissa.val = 0 →
      (∀ nMore adjusted,
        total - 19#isize = ok nMore →
        num.imp.dec2flt.parse.adjust_many_digit_count s nMore = ok adjusted →
        ¬ (total.val ≤ 19) → ¬ (0 < adjusted.val)) →
      (if total.val ≤ 19 then
          ok (some (num.imp.dec2flt.decimal.Decimal.mk shortExponent
            shortMantissa false false, consumed))
        else do
          let nMore ← total - 19#isize
          let adjusted ← num.imp.dec2flt.parse.adjust_many_digit_count s nMore
          if 0 < adjusted.val then
            let (manyMantissa, manyExponent) ←
              num.imp.dec2flt.parse.parse_many_digits s intEnd retryExponent
            ok (some (num.imp.dec2flt.decimal.Decimal.mk manyExponent
              manyMantissa false true, consumed))
          else
            ok (some (num.imp.dec2flt.decimal.Decimal.mk shortExponent
              shortMantissa false false, consumed))) = ok (some (d, outLen)) →
        d.mantissa.val = 0 ∧ d.many_digits = false := by
    intro total shortMantissa intEnd shortExponent retryExponent consumed outLen hshort hretry hresult
    by_cases hsmall : total.val ≤ 19
    · simp [hsmall] at hresult
      rcases hresult with ⟨rfl, rfl⟩
      exact ⟨hshort, rfl⟩
    · simp [hsmall] at hresult
      obtain ⟨nMore, hsub, hresult⟩ := bind_ok_inv _ _ _ hresult
      obtain ⟨adjusted, hadjust, hresult⟩ := bind_ok_inv _ _ _ hresult
      by_cases hpositive : 0 < adjusted.val
      · have hfalse := hretry nMore adjusted hsub hadjust hsmall hpositive
        contradiction
      · simp [hpositive] at hresult
        rcases hresult with ⟨rfl, rfl⟩
        exact ⟨hshort, rfl⟩
  have hnegative : d.negative = false := by
    cases suffixOpt with
    | none =>
      simp at hpartialAfterSuffixSplit
      obtain ⟨off, hoff, hrest⟩ := bind_ok_inv _ _ _ hpartialAfterSuffixSplit
      obtain ⟨outLen, hcast, hrest⟩ := bind_ok_inv _ _ _ hrest
      exact recordBranchNegative totalDigits mantissa1 scanRest baseExponent
        0#i64 outLen len (by simpa using hrest)
    | some pair =>
      rcases pair with ⟨marker, suffix⟩
      by_cases hlower : marker = 101#u8
      · subst marker
        obtain ⟨sciResult, hsci, hrest⟩ := bind_ok_inv _ _ _ hpartialAfterSuffixSplit
        rcases sciResult with ⟨optionExp, sciRest⟩
        cases optionExp with
        | none =>
          simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch, ModelOptionBranch,
            core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
            ModelOptionFromResidual] at hrest
        | some parsedExp =>
          simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch, ModelOptionBranch] at hrest
          obtain ⟨combined, hsum, hrest⟩ := bind_ok_inv _ _ _ hrest
          obtain ⟨off, hoff, hrest⟩ := bind_ok_inv _ _ _ hrest
          obtain ⟨outLen, hcast, hrest⟩ := bind_ok_inv _ _ _ hrest
          exact recordBranchNegative totalDigits mantissa1 scanRest combined
            parsedExp outLen len (by simpa using hrest)
      · by_cases hupper : marker = 69#u8
        · subst marker
          obtain ⟨sciResult, hsci, hrest⟩ := bind_ok_inv _ _ _ hpartialAfterSuffixSplit
          rcases sciResult with ⟨optionExp, sciRest⟩
          cases optionExp with
          | none =>
            simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch, ModelOptionBranch,
              core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
              ModelOptionFromResidual] at hrest
          | some parsedExp =>
            simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch, ModelOptionBranch] at hrest
            obtain ⟨combined, hsum, hrest⟩ := bind_ok_inv _ _ _ hrest
            obtain ⟨off, hoff, hrest⟩ := bind_ok_inv _ _ _ hrest
            obtain ⟨outLen, hcast, hrest⟩ := bind_ok_inv _ _ _ hrest
            exact recordBranchNegative totalDigits mantissa1 scanRest combined
              parsedExp outLen len (by simpa using hrest)
        · simp [hlower, hupper] at hpartialAfterSuffixSplit
          obtain ⟨off, hoff, hrest⟩ := bind_ok_inv _ _ _ hpartialAfterSuffixSplit
          obtain ⟨outLen, hcast, hrest⟩ := bind_ok_inv _ _ _ hrest
          exact recordBranchNegative totalDigits mantissa1 scanRest baseExponent
            0#i64 outLen len (by simpa using hrest)
  have hfields : d.mantissa.val = 0 ∧ d.many_digits = false := by
    cases suffixOpt with
    | none =>
      simp at hpartialAfterSuffixSplit
      obtain ⟨off, hoff, hrest⟩ := bind_ok_inv _ _ _ hpartialAfterSuffixSplit
      obtain ⟨outLen, hcast, hrest⟩ := bind_ok_inv _ _ _ hrest
      apply recordBranchZero totalDigits mantissa1 scanRest baseExponent
        0#i64 outLen len
      · exact hmantissaZero
      · exact hnoRetry
      · simpa using hrest
    | some pair =>
      rcases pair with ⟨marker, suffix⟩
      by_cases hlower : marker = 101#u8
      · subst marker
        obtain ⟨sciResult, hsci, hrest⟩ := bind_ok_inv _ _ _ hpartialAfterSuffixSplit
        rcases sciResult with ⟨optionExp, sciRest⟩
        cases optionExp with
        | none =>
          simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch, ModelOptionBranch,
            core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
            ModelOptionFromResidual] at hrest
        | some parsedExp =>
          simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch, ModelOptionBranch] at hrest
          obtain ⟨combined, hsum, hrest⟩ := bind_ok_inv _ _ _ hrest
          obtain ⟨off, hoff, hrest⟩ := bind_ok_inv _ _ _ hrest
          obtain ⟨outLen, hcast, hrest⟩ := bind_ok_inv _ _ _ hrest
          apply recordBranchZero totalDigits mantissa1 scanRest combined
            parsedExp outLen len
          · exact hmantissaZero
          · exact hnoRetry
          · simpa using hrest
      · by_cases hupper : marker = 69#u8
        · subst marker
          obtain ⟨sciResult, hsci, hrest⟩ := bind_ok_inv _ _ _ hpartialAfterSuffixSplit
          rcases sciResult with ⟨optionExp, sciRest⟩
          cases optionExp with
          | none =>
            simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch, ModelOptionBranch,
              core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
              ModelOptionFromResidual] at hrest
          | some parsedExp =>
            simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch, ModelOptionBranch] at hrest
            obtain ⟨combined, hsum, hrest⟩ := bind_ok_inv _ _ _ hrest
            obtain ⟨off, hoff, hrest⟩ := bind_ok_inv _ _ _ hrest
            obtain ⟨outLen, hcast, hrest⟩ := bind_ok_inv _ _ _ hrest
            apply recordBranchZero totalDigits mantissa1 scanRest combined
              parsedExp outLen len
            · exact hmantissaZero
            · exact hnoRetry
            · simpa using hrest
        · simp [hlower, hupper] at hpartialAfterSuffixSplit
          obtain ⟨off, hoff, hrest⟩ := bind_ok_inv _ _ _ hpartialAfterSuffixSplit
          obtain ⟨outLen, hcast, hrest⟩ := bind_ok_inv _ _ _ hrest
          apply recordBranchZero totalDigits mantissa1 scanRest baseExponent
            0#i64 outLen len
          · exact hmantissaZero
          · exact hnoRetry
          · simpa using hrest
  refine ⟨?_, ?_, hnegative⟩
  · exact hfields.1
  · exact hfields.2

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (69)
More program dependencies (36)
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 57 entries
Technical checking records
Local closure summary
{
  "node": "P401_T1_UnsignedZeroRecord",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "21f110a16065b2ec626f386c6f03f678bb72c42ad47b418eb14ef854302b7ce6",
  "active_statement_hash": "37000405340688a9cfbeb12390f4dc3b3ceb5098de19a67d43549fdd2b84604b",
  "kernel_axioms": [
    "Classical.choice",
    "Dec2Flt.P340_T1_selected_target_numBits",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "576e6bf9480cfd32f53c309c7ac8fb115c1ba6e413f299ed5ff9fa7c647e6769",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-181",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DecimalGoalVocabularyDefault": "2bbf2be48b5a4a4b",
    "ModelSliceSplitFirst": "f617ee05dd2925a9",
    "NumberHelperDigitScanExact": "6bcf20c61d10dea3",
    "P364_T1_NumberHelperAdjustCountExact": "8999fa99d4681219",
    "P364_T1_NumberHelperOffsetSourceLength": "de0168dfeba3b802",
    "num_imp_dec2flt_parse_parse_partial_number": "854af4cc12136a58"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "0717fd246d7ea78a",
    "DecimalGoalVocabularyDefault": "71a18a6c119a3cdc",
    "DecimalLexeme": "c43614ff2149ecf2",
    "F64": "ec4e25fbaf4e11d4",
    "ModelOptionBranch": "2b227898dbe15e59",
    "ModelOptionFromResidual": "6d48ecfbc617744f",
    "ModelSliceSplitFirst": "4ed9c51a5bb9fb58",
    "Preamble": "4adf4172ae751d7d",
    "SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from": "7e7284dc9bc88830",
    "SourceValidByteSlice": "3dc42716a6378d26",
    "num_imp_dec2flt_common_BiasedFp": "5c88d5d7976c5e8f",
    "num_imp_dec2flt_decimal_Decimal": "c43614ff2149ecf2",
    "num_imp_dec2flt_parse_adjust_many_digit_count": "4e59e3776b6cfdaa",
    "num_imp_dec2flt_parse_parse_many_digits": "50c9ef13b3ed7fe8",
    "num_imp_dec2flt_parse_parse_number": "b8693ec58f01c43c",
    "num_imp_dec2flt_parse_parse_partial_number": "94ed7b2ff71604ef",
    "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:471f0c5c14606cccc9292da118634a90dd70d3283932644a8d60b33735bcfbc4",
  "current_fingerprint": "sound-v2:471f0c5c14606cccc9292da118634a90dd70d3283932644a8d60b33735bcfbc4",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}