DecimalSeqIntegerExponentState

Lean checked

Statement

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

Lemma · Exact integer decimal-sequence state with exponent

Let a source-valid slice consist of a decimal integer I followed by a rendered, nonempty explicit exponent, and suppose the integer has a nonzero digit and parse_decimal_seq succeeds. After removing maximal leading and terminal zero runs from I, call the resulting lists S and R. The returned record has count \min(|R|,768), stored prefix R up to that count, and truncation flag true exactly when 768<|R|. Its point is congruent modulo 2^{32} to |S|+E, where E is the guarded accumulated explicit exponent.

Lean statement

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

import Tablet.DecimalDigitTrimDecomposition
import Tablet.DecimalSeqDigitRunExact
import Tablet.DecimalSeqDuplicateLoops
import Tablet.DecimalSeqExponentSuffixExact
import Tablet.DecimalSeqFinalizationExact
import Tablet.DecimalSeqLeadingZeroLoopExact
import Tablet.DecimalSeqScalarScanExact
import Tablet.DecimalGoalVocabularyDefault
import Tablet.SourceValidByteSlice

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 2000000
set_option maxRecDepth 10000
namespace dec2flt_model

-- [TABLET NODE: DecimalSeqIntegerExponentState]
theorem DecimalSeqIntegerExponentState (s : Slice Std.U8) (I : List Nat)
    (upper : Bool) (sign : Option Bool) (expDigits : List Nat)
    (d : num.imp.dec2flt.decimal_seq.DecimalSeq)
    (hsource : SourceValidByteSlice s)
    (hIdigits : forall z, z ∈ I -> z < 10)
    (hExpNe : expDigits ≠ [])
    (hExpDigits : forall z, z ∈ expDigits -> z < 10)
    (hSigNe : I.dropWhile (fun digit => digit == 0) ≠ [])
    (hbytes : s.val.map (fun b => b.val) =
      I.map (fun z => 48 + z) ++
        (if upper then 69 else 101) ::
          (match sign with
          | none => []
          | some negative => [if negative then 45 else 43]) ++
          expDigits.map (fun z => 48 + z))
    (hparse : num.imp.dec2flt.decimal_seq.parse_decimal_seq s = ok d) :
    let significant := I.dropWhile (fun digit => digit == 0)
    let trimmed :=
      (significant.reverse.dropWhile (fun digit => digit == 0)).reverse
    let E : Int :=
      let n : Nat := expDigits.foldl
        (fun n digit => if n < 65536 then 10 * n + digit else n) 0
      match sign with | some true => -(n : Int) | _ => (n : Int)
    (d.num_digits.val = min trimmed.length 768 /\
      (d.digits.val.take d.num_digits.val).map (fun z => z.val) =
        trimmed.take d.num_digits.val /\
      (d.truncated = true <-> 768 < trimmed.length)) /\
    exists k : Int,
      d.decimal_point.val = (significant.length : Int) + E +
        k * 4294967296 := 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

Use DecimalDigitTrimDecomposition to write I=0^zR0^q. The leading loop is exact by DecimalSeqLeadingZeroLoopExact, and DecimalSeqDigitRunExact consumes precisely S, preserves the exponent suffix, and records the first 768 digits with logical count |S|. The source-valid length bound discharges all Usize additions.
The suffix is nonempty and begins with its rendered 101 or 69 marker. DecimalSeqExponentSuffixExact evaluates its optional sign and guarded digit fold to an I32 word of value E and identifies the final checked point addition. The duplicate final-fill loop is identified with the common loop by DecimalSeqDuplicateLoops. Before the exponent, the zero scan adds q and trimming adds |R|, whose sum is |S|; thus the scan point satisfies the congruence required by the common finalizer.
Apply DecimalSeqFinalizationExact to the exact source prefix, terminal-zero suffix, residual exponent slice, digit array, and point facts. It proves the cap, truncation, fill-prefix, and final exponent conclusions stated here.

Lean proof


  dsimp only
  obtain ⟨z, q, hz, hq, hI, hsig, hsigstop, htrimstop⟩ :=
    DecimalDigitTrimDecomposition I
  let sig := I.dropWhile (fun digit => digit == 0)
  let trim := (sig.reverse.dropWhile (fun digit => digit == 0)).reverse
  let tail :=
    (if upper then 69 else 101) ::
      (match sign with
      | none => []
      | some negative => [if negative then 45 else 43]) ++
      expDigits.map (fun z => 48 + z)
  let E : Int :=
    let n : Nat := expDigits.foldl
      (fun n digit => if n < 65536 then 10 * n + digit else n) 0
    match sign with | some true => -(n : Int) | _ => (n : Int)
  change (_ /\ _ /\ _) /\ exists k : Int,
    d.decimal_point.val = (sig.length : Int) + E + k * 4294967296
  have hzmap : (List.replicate z 0).map (fun n => 48 + n) =
      List.replicate z 48 := by simp
  have hslead : s.val.map (fun b => b.val) =
      List.replicate z 48 ++ sig.map (fun n => 48 + n) ++ tail := by
    rw [hbytes, hI, List.map_append, hzmap]
    simp [tail, sig, List.append_assoc]
  have hleadstop :
      (sig.map (fun n => 48 + n) ++ tail)[0]? ≠ some 48 := by
    cases hsigeq : sig with
    | nil => exact (hSigNe (by simpa [sig] using hsigeq)).elim
    | cons a xs =>
      intro heq
      have ha : a = 0 := by simp [hsigeq] at heq; omega
      subst a
      rcases hsigstop with h | h
      · simp [sig, hsigeq] at h
      · exact h (by simp [sig, hsigeq])
  obtain ⟨s1, hlead, hs1⟩ := DecimalSeqLeadingZeroLoopExact s z
    (sig.map (fun n => 48 + n) ++ tail)
      (by simpa [List.append_assoc] using hslead) (Or.inr hleadstop)
  let d0 : num.imp.dec2flt.decimal_seq.DecimalSeq := {
    num_digits := 0#usize
    decimal_point := 0#i32
    truncated := false
    digits := Array.repeat 768#usize 0#u8 }
  have hbound : sig.length <= UScalar.max .Usize := by
    unfold SourceValidByteSlice at hsource
    have hlen := congrArg List.length hslead
    simp at hlen
    simp [UScalar.max, Usize.max, Usize.numBits,
      Dec2Flt.configured_x86_64_numBits]
    omega
  obtain ⟨rest, d1, hscan, hrest, hd1count, hd1point, hd1trunc,
    hd1old, hd1written, hd1outside⟩ :=
      DecimalSeqScalarScanExact s1 d0 sig tail hs1
        (fun n hn => hIdigits n (by rw [hI]; exact List.mem_append_right _ hn))
        (by cases upper <;> simp [tail])
        (by simpa [d0, Nat.zero_add] using hbound)
  have hrestTail : rest.val.map (fun b => b.val) = tail := hrest
  have hrestNe : rest.val ≠ [] := by
    intro hr
    have hh := congrArg List.length hrestTail
    simp [tail, hr] at hh
  have hscanDigits :
      (d1.digits.val.take (min sig.length 768)).map (fun b => b.val) =
        sig.take (min sig.length 768) := by
    apply List.ext_getElem?
    intro j
    by_cases hj : j < min sig.length 768
    · rw [List.getElem?_map, List.getElem?_take, List.getElem?_take]
      simp only [hj, if_true]
      have hw := hd1written j (by simp [d0]) (by simpa [d0] using hj)
      simpa [d0] using hw
    · simp [List.getElem?_map, List.getElem?_take, hj]
  have hprefixBytes : s.val.map (fun b => b.val) =
      (List.replicate z 48 ++ trim.map (fun n => 48 + n)) ++
        List.replicate q 48 ++ tail := by
    rw [hslead]
    have hs : sig = trim ++ List.replicate q 0 := by
      simpa [sig, trim] using hsig
    rw [hs, List.map_append]
    simp [List.append_assoc]
  let prefx := List.replicate z 48 ++ trim.map (fun n => 48 + n)
  let suffix := List.replicate q 48
  have hprefx : prefx = [] ∨ exists pre b,
      prefx = pre ++ [b] /\ b ≠ 48 /\ b ≠ 46 := by
    right
    have htrimNe : trim ≠ [] := by
      intro ht
      have hs : sig = trim ++ List.replicate q 0 := by
        simpa [sig, trim] using hsig
      rw [ht] at hs
      simp at hs
      rcases hsigstop with h | h
      · exact hSigNe (by simpa [sig] using h)
      · cases q with
        | zero => exact hSigNe (by simpa [sig] using hs)
        | succ q => exact h (by simp [sig, hs, List.replicate_succ])
    let last := trim.getLast htrimNe
    refine ⟨List.replicate z 48 ++
        trim.dropLast.map (fun n => 48 + n), 48 + last, ?_, ?_, ?_⟩
    · dsimp [prefx]
      rw [List.append_assoc]
      congr 1
      have ht := congrArg (List.map (fun n => 48 + n))
        (List.dropLast_append_getLast htrimNe)
      simpa [last, List.map_append] using ht.symm
    · intro heq
      have hlast0 : last = 0 := by omega
      rcases htrimstop with h | h
      · exact htrimNe (by simpa [trim] using h)
      · apply h
        rw [List.getLast?_eq_getLast htrimNe]
        simp [last, hlast0]
    · omega
  have hsuffix : forall b, b ∈ suffix -> b = 48 ∨ b = 46 := by
    intro b hb
    left
    simpa [suffix] using (List.mem_replicate.mp hb).2
  have hsuffixCount : suffix.count 48 = q := by simp [suffix]
  let suffixEval : Std.I32 -> Result Std.I32 := fun base => do
    let ch <- Slice.index_usize rest 0#usize
    if ch = 101#u8 then
      let s3 <- core.slice.index.Slice.index
        (core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) rest
        { start := 1#usize }
      let b2 <- core.slice.Slice.is_empty s3
      let (s4, exp_sign) <- if b2 then ok (s3, 1#i32) else do
        let ch1 <- Slice.index_usize s3 0#usize
        let exp_sign1 <- if ch1 = 45#u8 then ok (-1)#i32 else ok 1#i32
        let s5 <- if ch1 = 45#u8 then
            core.slice.index.Slice.index
              (core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) s3
              { start := 1#usize }
          else if ch1 = 43#u8 then
            core.slice.index.Slice.index
              (core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) s3
              { start := 1#usize }
          else ok s3
        ok (s5, exp_sign1)
      let exp_num <- num.imp.dec2flt.decimal_seq.parse_decimal_exponent s4
      let signed <- exp_sign * exp_num
      base + signed
    else if ch = 69#u8 then
      let s3 <- core.slice.index.Slice.index
        (core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) rest
        { start := 1#usize }
      let b2 <- core.slice.Slice.is_empty s3
      let (s4, exp_sign) <- if b2 then ok (s3, 1#i32) else do
        let ch1 <- Slice.index_usize s3 0#usize
        let exp_sign1 <- if ch1 = 45#u8 then ok (-1)#i32 else ok 1#i32
        let s5 <- if ch1 = 45#u8 then
            core.slice.index.Slice.index
              (core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) s3
              { start := 1#usize }
          else if ch1 = 43#u8 then
            core.slice.index.Slice.index
              (core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) s3
              { start := 1#usize }
          else ok s3
        ok (s5, exp_sign1)
      let exp_num <- num.imp.dec2flt.decimal_seq.parse_decimal_exponent s4
      let signed <- exp_sign * exp_num
      base + signed
    else ok base
  obtain ⟨signed, hsignedVal, hsuffixEval⟩ :=
    DecimalSeqExponentSuffixExact rest upper sign expDigits
      (by unfold SourceValidByteSlice at hsource ⊢
          have hlen := congrArg List.length hrestTail
          simp [tail] at hlen
          have hrestLe : rest.val.length <= s.val.length := by
            have hslen := congrArg List.length hslead
            simp [tail] at hslen
            omega
          omega)
      hExpNe hExpDigits (by simpa [tail] using hrestTail)
  have hsignedE : signed.val = E := by
    cases sign with
    | none =>
      dsimp only [E]
      exact hsignedVal
    | some negative =>
      cases negative <;> dsimp only [E] <;> exact hsignedVal
  have hsuffixValue : forall base result,
      suffixEval base = ok result -> result.val = base.val + E := by
    intro base result heval
    rw [show suffixEval base = base + signed by
      simpa [suffixEval] using hsuffixEval base] at heval
    have hadd := IScalar.add_equiv base signed
    rw [heval] at hadd
    rw [hadd.2.1, hsignedE]
  have hscanPoint : exists k : Int,
      d1.decimal_point.val + (q : Int) + (trim.length : Int) =
        (sig.length : Int) + k * 4294967296 := by
    refine ⟨0, ?_⟩
    rw [hd1point]
    have hsig' : sig = trim ++ List.replicate q 0 := by
      simpa [sig, trim] using hsig
    have hlen : sig.length = trim.length + q := by
      have hh := congrArg List.length hsig'
      simpa using hh
    simp [d0]
    push_cast
    omega
  have hmarkerIndex : Slice.index_usize rest 0#usize =
      ok (if upper then 69#u8 else 101#u8) := by
    cases hr : rest.val with
    | nil => exact (hrestNe hr).elim
    | cons b bs =>
      have hbval : b.val = if upper then 69 else 101 := by
        have hh := congrArg List.head? hrestTail
        simp [hr, tail] at hh
        exact hh
      have hb : b = if upper then 69#u8 else 101#u8 := by
        cases upper <;> apply UScalar.eq_of_val_eq <;> simpa using hbval
      simp [Slice.index_usize, hr, hb]
  have hloop7 := DecimalSeqDuplicateLoops.2.2.2.2
  have hmarkerNe : (if upper then 69#u8 else 101#u8) ≠ 46#u8 := by
    cases upper <;> decide
  unfold num.imp.dec2flt.decimal_seq.parse_decimal_seq at hparse
  rw [show num.imp.dec2flt.decimal_seq.DecimalSeq.Insts.CoreDefaultDefault.default =
      ok d0 by rfl] at hparse
  simp only [bind_tc_ok] at hparse
  rw [hlead] at hparse
  simp only [bind_tc_ok] at hparse
  rw [hscan] at hparse
  simp only [bind_tc_ok] at hparse
  have hd1ne : d1.num_digits ≠ 0#usize := by
    intro heq
    have hv := congrArg UScalar.val heq
    simp [hd1count, d0, sig, hSigNe] at hv
  have hd1valNe : d1.num_digits.val ≠ 0 := by
    rw [hd1count]
    simp [d0, sig, hSigNe]
  have hcore :
      (do
        let consumed <- Slice.len s - Slice.len rest
        let trailing <-
          num.imp.dec2flt.decimal_seq.count_trailing_zeros s consumed
        let p1 <- d1.decimal_point + UScalar.hcast .I32 trailing
        let kept <- d1.num_digits - trailing
        let point <- p1 + UScalar.hcast .I32 kept
        let (nDigits, flag) <-
          if kept > num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS
          then ok (num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS, true)
          else ok (kept, d1.truncated)
        let finalPoint <- suffixEval point
        let a <- num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop1
          { start := nDigits,
            «end» :=
              num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS_WITHOUT_OVERFLOW }
          d1.digits
        ok (num.imp.dec2flt.decimal_seq.DecimalSeq.mk
          nDigits finalPoint flag a)) = ok d := by
    cases upper <;>
      simp [core.slice.Slice.is_empty, hrestNe, hmarkerIndex, hmarkerNe,
        hd1ne, hd1valNe, hloop7, suffixEval, Aeneas.Std.lift] at hparse ⊢
    all_goals exact hparse
  have hfinal := DecimalSeqFinalizationExact s rest d1 d sig trim prefx
    suffix tail q (sig.length : Int) E suffixEval
    (by simpa [prefx, suffix] using hprefixBytes) hrestTail hprefx hsuffix
    hsuffixCount (by simpa [d0] using hd1count) hscanPoint
    (by simpa [d0] using hd1trunc)
    (by simpa [sig, trim] using hsig) hscanDigits hsuffixValue hcore
  rcases hfinal with ⟨hcount, hdigits, htrunc, k, hk⟩
  exact ⟨⟨by simpa [trim] using hcount,
    by simpa [trim] using hdigits,
    by simpa [trim] using htrunc⟩, k, hk⟩

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalDigitTrimDecomposition
import Tablet.DecimalSeqDigitRunExact
import Tablet.DecimalSeqDuplicateLoops
import Tablet.DecimalSeqExponentSuffixExact
import Tablet.DecimalSeqFinalizationExact
import Tablet.DecimalSeqLeadingZeroLoopExact
import Tablet.DecimalSeqScalarScanExact
import Tablet.DecimalGoalVocabularyDefault
import Tablet.SourceValidByteSlice

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 2000000
set_option maxRecDepth 10000
namespace dec2flt_model

-- [TABLET NODE: DecimalSeqIntegerExponentState]
theorem DecimalSeqIntegerExponentState (s : Slice Std.U8) (I : List Nat)
    (upper : Bool) (sign : Option Bool) (expDigits : List Nat)
    (d : num.imp.dec2flt.decimal_seq.DecimalSeq)
    (hsource : SourceValidByteSlice s)
    (hIdigits : forall z, z ∈ I -> z < 10)
    (hExpNe : expDigits ≠ [])
    (hExpDigits : forall z, z ∈ expDigits -> z < 10)
    (hSigNe : I.dropWhile (fun digit => digit == 0) ≠ [])
    (hbytes : s.val.map (fun b => b.val) =
      I.map (fun z => 48 + z) ++
        (if upper then 69 else 101) ::
          (match sign with
          | none => []
          | some negative => [if negative then 45 else 43]) ++
          expDigits.map (fun z => 48 + z))
    (hparse : num.imp.dec2flt.decimal_seq.parse_decimal_seq s = ok d) :
    let significant := I.dropWhile (fun digit => digit == 0)
    let trimmed :=
      (significant.reverse.dropWhile (fun digit => digit == 0)).reverse
    let E : Int :=
      let n : Nat := expDigits.foldl
        (fun n digit => if n < 65536 then 10 * n + digit else n) 0
      match sign with | some true => -(n : Int) | _ => (n : Int)
    (d.num_digits.val = min trimmed.length 768 /\
      (d.digits.val.take d.num_digits.val).map (fun z => z.val) =
        trimmed.take d.num_digits.val /\
      (d.truncated = true <-> 768 < trimmed.length)) /\
    exists k : Int,
      d.decimal_point.val = (significant.length : Int) + E +
        k * 4294967296 := by
-- BODY
  dsimp only
  obtain ⟨z, q, hz, hq, hI, hsig, hsigstop, htrimstop⟩ :=
    DecimalDigitTrimDecomposition I
  let sig := I.dropWhile (fun digit => digit == 0)
  let trim := (sig.reverse.dropWhile (fun digit => digit == 0)).reverse
  let tail :=
    (if upper then 69 else 101) ::
      (match sign with
      | none => []
      | some negative => [if negative then 45 else 43]) ++
      expDigits.map (fun z => 48 + z)
  let E : Int :=
    let n : Nat := expDigits.foldl
      (fun n digit => if n < 65536 then 10 * n + digit else n) 0
    match sign with | some true => -(n : Int) | _ => (n : Int)
  change (_ /\ _ /\ _) /\ exists k : Int,
    d.decimal_point.val = (sig.length : Int) + E + k * 4294967296
  have hzmap : (List.replicate z 0).map (fun n => 48 + n) =
      List.replicate z 48 := by simp
  have hslead : s.val.map (fun b => b.val) =
      List.replicate z 48 ++ sig.map (fun n => 48 + n) ++ tail := by
    rw [hbytes, hI, List.map_append, hzmap]
    simp [tail, sig, List.append_assoc]
  have hleadstop :
      (sig.map (fun n => 48 + n) ++ tail)[0]? ≠ some 48 := by
    cases hsigeq : sig with
    | nil => exact (hSigNe (by simpa [sig] using hsigeq)).elim
    | cons a xs =>
      intro heq
      have ha : a = 0 := by simp [hsigeq] at heq; omega
      subst a
      rcases hsigstop with h | h
      · simp [sig, hsigeq] at h
      · exact h (by simp [sig, hsigeq])
  obtain ⟨s1, hlead, hs1⟩ := DecimalSeqLeadingZeroLoopExact s z
    (sig.map (fun n => 48 + n) ++ tail)
      (by simpa [List.append_assoc] using hslead) (Or.inr hleadstop)
  let d0 : num.imp.dec2flt.decimal_seq.DecimalSeq := {
    num_digits := 0#usize
    decimal_point := 0#i32
    truncated := false
    digits := Array.repeat 768#usize 0#u8 }
  have hbound : sig.length <= UScalar.max .Usize := by
    unfold SourceValidByteSlice at hsource
    have hlen := congrArg List.length hslead
    simp at hlen
    simp [UScalar.max, Usize.max, Usize.numBits,
      Dec2Flt.configured_x86_64_numBits]
    omega
  obtain ⟨rest, d1, hscan, hrest, hd1count, hd1point, hd1trunc,
    hd1old, hd1written, hd1outside⟩ :=
      DecimalSeqScalarScanExact s1 d0 sig tail hs1
        (fun n hn => hIdigits n (by rw [hI]; exact List.mem_append_right _ hn))
        (by cases upper <;> simp [tail])
        (by simpa [d0, Nat.zero_add] using hbound)
  have hrestTail : rest.val.map (fun b => b.val) = tail := hrest
  have hrestNe : rest.val ≠ [] := by
    intro hr
    have hh := congrArg List.length hrestTail
    simp [tail, hr] at hh
  have hscanDigits :
      (d1.digits.val.take (min sig.length 768)).map (fun b => b.val) =
        sig.take (min sig.length 768) := by
    apply List.ext_getElem?
    intro j
    by_cases hj : j < min sig.length 768
    · rw [List.getElem?_map, List.getElem?_take, List.getElem?_take]
      simp only [hj, if_true]
      have hw := hd1written j (by simp [d0]) (by simpa [d0] using hj)
      simpa [d0] using hw
    · simp [List.getElem?_map, List.getElem?_take, hj]
  have hprefixBytes : s.val.map (fun b => b.val) =
      (List.replicate z 48 ++ trim.map (fun n => 48 + n)) ++
        List.replicate q 48 ++ tail := by
    rw [hslead]
    have hs : sig = trim ++ List.replicate q 0 := by
      simpa [sig, trim] using hsig
    rw [hs, List.map_append]
    simp [List.append_assoc]
  let prefx := List.replicate z 48 ++ trim.map (fun n => 48 + n)
  let suffix := List.replicate q 48
  have hprefx : prefx = [] ∨ exists pre b,
      prefx = pre ++ [b] /\ b ≠ 48 /\ b ≠ 46 := by
    right
    have htrimNe : trim ≠ [] := by
      intro ht
      have hs : sig = trim ++ List.replicate q 0 := by
        simpa [sig, trim] using hsig
      rw [ht] at hs
      simp at hs
      rcases hsigstop with h | h
      · exact hSigNe (by simpa [sig] using h)
      · cases q with
        | zero => exact hSigNe (by simpa [sig] using hs)
        | succ q => exact h (by simp [sig, hs, List.replicate_succ])
    let last := trim.getLast htrimNe
    refine ⟨List.replicate z 48 ++
        trim.dropLast.map (fun n => 48 + n), 48 + last, ?_, ?_, ?_⟩
    · dsimp [prefx]
      rw [List.append_assoc]
      congr 1
      have ht := congrArg (List.map (fun n => 48 + n))
        (List.dropLast_append_getLast htrimNe)
      simpa [last, List.map_append] using ht.symm
    · intro heq
      have hlast0 : last = 0 := by omega
      rcases htrimstop with h | h
      · exact htrimNe (by simpa [trim] using h)
      · apply h
        rw [List.getLast?_eq_getLast htrimNe]
        simp [last, hlast0]
    · omega
  have hsuffix : forall b, b ∈ suffix -> b = 48 ∨ b = 46 := by
    intro b hb
    left
    simpa [suffix] using (List.mem_replicate.mp hb).2
  have hsuffixCount : suffix.count 48 = q := by simp [suffix]
  let suffixEval : Std.I32 -> Result Std.I32 := fun base => do
    let ch <- Slice.index_usize rest 0#usize
    if ch = 101#u8 then
      let s3 <- core.slice.index.Slice.index
        (core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) rest
        { start := 1#usize }
      let b2 <- core.slice.Slice.is_empty s3
      let (s4, exp_sign) <- if b2 then ok (s3, 1#i32) else do
        let ch1 <- Slice.index_usize s3 0#usize
        let exp_sign1 <- if ch1 = 45#u8 then ok (-1)#i32 else ok 1#i32
        let s5 <- if ch1 = 45#u8 then
            core.slice.index.Slice.index
              (core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) s3
              { start := 1#usize }
          else if ch1 = 43#u8 then
            core.slice.index.Slice.index
              (core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) s3
              { start := 1#usize }
          else ok s3
        ok (s5, exp_sign1)
      let exp_num <- num.imp.dec2flt.decimal_seq.parse_decimal_exponent s4
      let signed <- exp_sign * exp_num
      base + signed
    else if ch = 69#u8 then
      let s3 <- core.slice.index.Slice.index
        (core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) rest
        { start := 1#usize }
      let b2 <- core.slice.Slice.is_empty s3
      let (s4, exp_sign) <- if b2 then ok (s3, 1#i32) else do
        let ch1 <- Slice.index_usize s3 0#usize
        let exp_sign1 <- if ch1 = 45#u8 then ok (-1)#i32 else ok 1#i32
        let s5 <- if ch1 = 45#u8 then
            core.slice.index.Slice.index
              (core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) s3
              { start := 1#usize }
          else if ch1 = 43#u8 then
            core.slice.index.Slice.index
              (core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) s3
              { start := 1#usize }
          else ok s3
        ok (s5, exp_sign1)
      let exp_num <- num.imp.dec2flt.decimal_seq.parse_decimal_exponent s4
      let signed <- exp_sign * exp_num
      base + signed
    else ok base
  obtain ⟨signed, hsignedVal, hsuffixEval⟩ :=
    DecimalSeqExponentSuffixExact rest upper sign expDigits
      (by unfold SourceValidByteSlice at hsource ⊢
          have hlen := congrArg List.length hrestTail
          simp [tail] at hlen
          have hrestLe : rest.val.length <= s.val.length := by
            have hslen := congrArg List.length hslead
            simp [tail] at hslen
            omega
          omega)
      hExpNe hExpDigits (by simpa [tail] using hrestTail)
  have hsignedE : signed.val = E := by
    cases sign with
    | none =>
      dsimp only [E]
      exact hsignedVal
    | some negative =>
      cases negative <;> dsimp only [E] <;> exact hsignedVal
  have hsuffixValue : forall base result,
      suffixEval base = ok result -> result.val = base.val + E := by
    intro base result heval
    rw [show suffixEval base = base + signed by
      simpa [suffixEval] using hsuffixEval base] at heval
    have hadd := IScalar.add_equiv base signed
    rw [heval] at hadd
    rw [hadd.2.1, hsignedE]
  have hscanPoint : exists k : Int,
      d1.decimal_point.val + (q : Int) + (trim.length : Int) =
        (sig.length : Int) + k * 4294967296 := by
    refine ⟨0, ?_⟩
    rw [hd1point]
    have hsig' : sig = trim ++ List.replicate q 0 := by
      simpa [sig, trim] using hsig
    have hlen : sig.length = trim.length + q := by
      have hh := congrArg List.length hsig'
      simpa using hh
    simp [d0]
    push_cast
    omega
  have hmarkerIndex : Slice.index_usize rest 0#usize =
      ok (if upper then 69#u8 else 101#u8) := by
    cases hr : rest.val with
    | nil => exact (hrestNe hr).elim
    | cons b bs =>
      have hbval : b.val = if upper then 69 else 101 := by
        have hh := congrArg List.head? hrestTail
        simp [hr, tail] at hh
        exact hh
      have hb : b = if upper then 69#u8 else 101#u8 := by
        cases upper <;> apply UScalar.eq_of_val_eq <;> simpa using hbval
      simp [Slice.index_usize, hr, hb]
  have hloop7 := DecimalSeqDuplicateLoops.2.2.2.2
  have hmarkerNe : (if upper then 69#u8 else 101#u8) ≠ 46#u8 := by
    cases upper <;> decide
  unfold num.imp.dec2flt.decimal_seq.parse_decimal_seq at hparse
  rw [show num.imp.dec2flt.decimal_seq.DecimalSeq.Insts.CoreDefaultDefault.default =
      ok d0 by rfl] at hparse
  simp only [bind_tc_ok] at hparse
  rw [hlead] at hparse
  simp only [bind_tc_ok] at hparse
  rw [hscan] at hparse
  simp only [bind_tc_ok] at hparse
  have hd1ne : d1.num_digits ≠ 0#usize := by
    intro heq
    have hv := congrArg UScalar.val heq
    simp [hd1count, d0, sig, hSigNe] at hv
  have hd1valNe : d1.num_digits.val ≠ 0 := by
    rw [hd1count]
    simp [d0, sig, hSigNe]
  have hcore :
      (do
        let consumed <- Slice.len s - Slice.len rest
        let trailing <-
          num.imp.dec2flt.decimal_seq.count_trailing_zeros s consumed
        let p1 <- d1.decimal_point + UScalar.hcast .I32 trailing
        let kept <- d1.num_digits - trailing
        let point <- p1 + UScalar.hcast .I32 kept
        let (nDigits, flag) <-
          if kept > num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS
          then ok (num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS, true)
          else ok (kept, d1.truncated)
        let finalPoint <- suffixEval point
        let a <- num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop1
          { start := nDigits,
            «end» :=
              num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS_WITHOUT_OVERFLOW }
          d1.digits
        ok (num.imp.dec2flt.decimal_seq.DecimalSeq.mk
          nDigits finalPoint flag a)) = ok d := by
    cases upper <;>
      simp [core.slice.Slice.is_empty, hrestNe, hmarkerIndex, hmarkerNe,
        hd1ne, hd1valNe, hloop7, suffixEval, Aeneas.Std.lift] at hparse ⊢
    all_goals exact hparse
  have hfinal := DecimalSeqFinalizationExact s rest d1 d sig trim prefx
    suffix tail q (sig.length : Int) E suffixEval
    (by simpa [prefx, suffix] using hprefixBytes) hrestTail hprefx hsuffix
    hsuffixCount (by simpa [d0] using hd1count) hscanPoint
    (by simpa [d0] using hd1trunc)
    (by simpa [sig, trim] using hsig) hscanDigits hsuffixValue hcore
  rcases hfinal with ⟨hcount, hdigits, htrunc, k, hk⟩
  exact ⟨⟨by simpa [trim] using hcount,
    by simpa [trim] using hdigits,
    by simpa [trim] using htrunc⟩, k, hk⟩

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (77)
More program dependencies (44)
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 32 entries
Technical checking records
Local closure summary
{
  "node": "DecimalSeqIntegerExponentState",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "380072afbc90d7e80cd396d237a80cc18ddb40270633caa6b2cb6ab16baeedf6",
  "active_statement_hash": "6ac3331e080640f6f57518d2cfe928421d2b9e1f1f9e3b4e2a542d44cd148eab",
  "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-169",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DecimalDigitTrimDecomposition": "74d5424585de54f0",
    "DecimalSeqDuplicateLoops": "4a7630ac67b4834a",
    "DecimalSeqExponentSuffixExact": "ca308790b38535fe",
    "DecimalSeqFinalizationExact": "d3b883652a1f053b",
    "DecimalSeqLeadingZeroLoopExact": "afa2b1ae59f7e9a8",
    "DecimalSeqScalarScanExact": "a9ff88a04accf0ed",
    "num_imp_dec2flt_decimal_seq_parse_decimal_seq": "854af4cc12136a58"
  },
  "strict_definition_deps": {
    "DecimalSeqExponentSuffixExact": "28ca0a8ac503ee01",
    "SourceValidByteSlice": "3dc42716a6378d26",
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "b0286c42454b158d",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_Insts_CoreDefaultDefault_default": "7b9921904495bc2a",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS": "39f6cb231ef80388",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS_WITHOUT_OVERFLOW": "65634ac95536dcca",
    "num_imp_dec2flt_decimal_seq_count_trailing_zeros": "7a77bc9e01c1a09b",
    "num_imp_dec2flt_decimal_seq_parse_decimal_exponent": "e22eec67a6a49ff8",
    "num_imp_dec2flt_decimal_seq_parse_decimal_seq": "ec91b296e225e006",
    "num_imp_dec2flt_decimal_seq_parse_digits_into_seq": "8b2cc3a350f40ce1"
  }
}
Prose assessment
{
  "label": "Lean proof closed; predictive prose review no longer required",
  "assessment_status": null,
  "fingerprint_relation": "unknown",
  "assessment_fingerprint": null,
  "current_fingerprint": "sound-v2:df47107c81d5499930db41fa6bf481ec29e4c226ff6e0c2bb5ef4b431b073e1c",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}