DecimalSeqFractionalZeroState

Lean checked

Statement

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

Lemma · All-zero fractional significand state

Let a source-valid slice render integer digits I, a point, fractional digits F, and an optional well-formed exponent suffix with accumulated value E. Assume deleting leading zeroes from both I and F leaves the empty list, and that the extracted parser returns d. Then the significant and trimmed lists are empty, d has count zero and an empty retained prefix, and truncation is false. With z=|IF|, for some k,
d.\mathit{decimal\_point}=|I|-z+E+k2^{32}.

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.DecimalSeqDigitRunAccumulate
import Tablet.DecimalSeqDuplicateLoops
import Tablet.DecimalSeqExponentEval
import Tablet.DecimalSeqExponentResidualPointwise
import Tablet.DecimalSeqFillPrefixPreserved
import Tablet.DecimalSeqI32HCastCongruence
import Tablet.DecimalSeqLeadingZeroLoopExact
import Tablet.DecimalSeqScalarScanExact
import Tablet.SourceValidByteSlice

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 3000000
set_option maxRecDepth 100000
namespace dec2flt_model

-- [TABLET NODE: DecimalSeqFractionalZeroState]
theorem DecimalSeqFractionalZeroState (s : Slice Std.U8) (I F tail : List Nat) (E : Int)
    (exponent : Option (Bool × Option Bool × List Nat))
    (d : num.imp.dec2flt.decimal_seq.DecimalSeq)
    (hsource : SourceValidByteSlice s)
    (hIdigits : forall z, z ∈ I -> z < 10)
    (hFdigits : forall z, z ∈ F -> z < 10)
    (hExpNe : forall upper sign digits,
      exponent = some (upper, sign, digits) -> digits ≠ [])
    (hExpDigits : forall upper sign digits,
      exponent = some (upper, sign, digits) ->
        forall z, z ∈ digits -> z < 10)
    (htailNone : exponent = none -> tail = [])
    (htailSome : forall upper sign digits,
      exponent = some (upper, sign, digits) -> tail =
        (if upper then 69 else 101) ::
          (match sign with
          | none => []
          | some negative => [if negative then 45 else 43]) ++
          digits.map (fun z => 48 + z))
    (hENone : exponent = none -> E = 0)
    (hESome : forall upper sign digits,
      exponent = some (upper, sign, digits) -> E =
        let n : Nat := digits.foldl
          (fun n digit => if n < 65536 then 10 * n + digit else n) 0
        match sign with | some true => -(n : Int) | _ => (n : Int))
    (hSigI : I.dropWhile (fun digit => digit == 0) = [])
    (hSigF : F.dropWhile (fun digit => digit == 0) = [])
    (hbytes : s.val.map (fun b => b.val) =
      I.map (fun z => 48 + z) ++ 46 :: F.map (fun z => 48 + z) ++ tail)
    (hparse : num.imp.dec2flt.decimal_seq.parse_decimal_seq s = ok d) :
    let significant := (I ++ F).dropWhile (fun digit => digit == 0)
    let trimmed :=
      (significant.reverse.dropWhile (fun digit => digit == 0)).reverse
    let z := (I ++ F).length - significant.length
    let P : Int := (I.length : Int) - z
    (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 = P + 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

Apply DecimalDigitTrimDecomposition separately to I and F. The two empty-remainder hypotheses give I=0^{|I|} and F=0^{|F|}. Consequently the combined significant and trimmed lists are empty. The source starts with exactly |I| ASCII zeroes and then byte 46, so DecimalSeqLeadingZeroLoopExact consumes the integer and DecimalSeqScalarScanExact performs an empty first digit scan, leaving the point and the default zero-count state.
Remove the point exactly. The post-point slice is |F| ASCII zeroes followed by the exponent suffix. The loop~2/loop~0 identity from DecimalSeqDuplicateLoops, together with DecimalSeqLeadingZeroLoopExact, consumes precisely those zeroes. Apply DecimalSeqDigitRunAccumulate to the now-empty significant fractional run. Its exact loop~3 and scalar-scan equations leave the exponent suffix, preserve count zero, the digit array, and false truncation.
Reduce the successful extracted parser by all these equations. Success forces its checked base subtraction to return some b. Because the second count is zero, this branch skips reverse trailing-zero trimming and applies the exponent directly to b. The exact residual equations and DecimalSeqExponentResidualPointwise show that this step adds E. The copied fill loop~4 equals loop~1 by DecimalSeqDuplicateLoops; DecimalSeqFillPrefixPreserved gives its successful result and preserves the empty prefix. Thus the returned record has count zero and false truncation.
The base is the difference of the signed 32-bit casts of the residual length and the whole post-point length. Apply DecimalSeqI32HCastCongruence to both casts. Since those lengths are |\mathit{suffix}| and |F|+|\mathit{suffix}|, respectively, b\equiv-|F|\pmod {2^{32}}. Here z=|I|+|F|, so -|F|=|I|-z. Adding E yields the claimed point congruence.

Lean proof


  dsimp only
  have hSig : (I ++ F).dropWhile (fun digit => digit == 0) = [] := by
    simp [List.dropWhile_append, hSigI, hSigF]
  obtain ⟨zi, qi, hzi, hqi, hI, hIsigTail, hIsigstop, hItrimstop⟩ :=
    DecimalDigitTrimDecomposition I
  obtain ⟨L, qf, hL, hqf, hF, hFsigTail, hFsigstop, hFtrimstop⟩ :=
    DecimalDigitTrimDecomposition F
  have hIzeros : I = List.replicate zi 0 := by simpa [hSigI] using hI
  have hFzeros : F = List.replicate L 0 := by simpa [hSigF] using hF
  have hziLen : zi = I.length := by
    have hh := congrArg List.length hIzeros
    simpa using hh.symm
  have hLLen : L = F.length := by
    have hh := congrArg List.length hFzeros
    simpa using hh.symm
  have hIbytes : I.map (fun n => 48 + n) = List.replicate zi 48 := by
    rw [hIzeros]; simp
  have hFbytes : F.map (fun n => 48 + n) = List.replicate L 48 := by
    rw [hFzeros]; simp
  have hslead : s.val.map (fun b => b.val) =
      List.replicate zi 48 ++ 46 :: List.replicate L 48 ++ tail := by
    rw [hbytes, hIbytes, hFbytes]
  obtain ⟨s1, hlead, hs1⟩ := DecimalSeqLeadingZeroLoopExact s zi
    (46 :: List.replicate L 48 ++ tail)
    (by simpa [List.append_assoc] using hslead) (by simp)
  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 }
  obtain ⟨pointRest, d1, hscan1, hpointRest, hd1count, hd1point,
    hd1trunc, hd1old, hd1written, hd1outside⟩ :=
    DecimalSeqScalarScanExact s1 d0 ([] : List Nat)
      (46 :: List.replicate L 48 ++ tail) (by simpa using hs1)
      (by simp) (by simp) (by simp [d0])
  have hd1zero : d1.num_digits = 0#usize := by
    apply UScalar.eq_of_val_eq
    simpa [d0] using hd1count
  have hpointRestNe : pointRest.val ≠ [] := by
    intro he
    have hh := congrArg List.length hpointRest
    simp [he] at hh
  have hpointIndex : Slice.index_usize pointRest 0#usize = ok 46#u8 := by
    cases hr : pointRest.val with
    | nil => exact (hpointRestNe hr).elim
    | cons b bs =>
      have hbval : b.val = 46 := by
        have hh := congrArg List.head? hpointRest
        simp [hr] at hh
        exact hh
      have hb : b = 46#u8 := UScalar.eq_of_val_eq hbval
      simp [Slice.index_usize, hr, hb]
  let afterPoint := Slice.drop pointRest 1#usize
  have hdropPoint :
      core.slice.index.SliceIndexRangeFromUsizeSlice.index
        { start := 1#usize } pointRest = ok afterPoint := by
    simp [core.slice.index.SliceIndexRangeFromUsizeSlice.index,
      Slice.length, afterPoint, hpointRestNe]
  have hafterPoint : afterPoint.val.map (fun b => b.val) =
      List.replicate L 48 ++ tail := by
    simp [afterPoint, Slice.drop, List.map_drop, hpointRest]
  have htailStop : tail = [] \/ tail[0]? ≠ some 48 := by
    cases he : exponent with
    | none => left; exact htailNone he
    | some data =>
      rcases data with ⟨upper, sign, digits⟩
      right
      rw [htailSome upper sign digits he]
      cases upper <;> simp
  obtain ⟨sigStart, hfracLead, hsigStart⟩ :=
    DecimalSeqLeadingZeroLoopExact afterPoint L tail hafterPoint htailStop
  have hloop2 :
      num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop2 afterPoint =
        ok sigStart := by
    rw [DecimalSeqDuplicateLoops.1]
    exact hfracLead
  have htailForm : tail = [] \/ exists marker rest,
      tail = marker :: rest /\ (marker = 69 \/ marker = 101) := by
    cases he : exponent with
    | none => left; exact htailNone he
    | some data =>
      rcases data with ⟨upper, sign, digits⟩
      right
      refine ⟨if upper then 69 else 101,
        (match sign with
        | none => []
        | some negative => [if negative then 45 else 43]) ++
          digits.map (fun z => 48 + z), ?_, ?_⟩
      · exact htailSome upper sign digits he
      · cases upper <;> simp
  have hbound : d1.num_digits.val + tail.length <= UScalar.max .Usize := by
    have hsmax : s.val.length <= UScalar.max .Usize := by
      unfold SourceValidByteSlice at hsource
      simp [UScalar.max, Usize.max, Usize.numBits,
        Dec2Flt.configured_x86_64_numBits]
      omega
    have hlen := congrArg List.length hbytes
    simp only [List.length_map, List.length_append, List.length_cons] at hlen
    simp [hd1zero]
    omega
  have hd1prefix :
      (d1.digits.val.take 0).map (fun b => b.val) = ([] : List Nat) := by simp
  obtain ⟨bulkRest, rest, bulkCount, bulkArray, d2,
    hloop3, hscan2, hrest, hd2count, hd2point, hd2trunc, hd2prefix⟩ :=
    DecimalSeqDigitRunAccumulate sigStart d1 ([] : List Nat) [] tail
      (by simpa using hsigStart) (by simp) htailForm
      (by simpa using hbound) (by simpa [hd1zero]) (by simpa using hd1prefix)
  have hd2zero : d2.num_digits = 0#usize := by
    apply UScalar.eq_of_val_eq
    simpa [hd1zero] using hd2count
  have hrestTail : rest.val.map (fun b => b.val) = tail := hrest
  have hrestSource : SourceValidByteSlice rest := by
    unfold SourceValidByteSlice at hsource ⊢
    have hslen := congrArg List.length hbytes
    have hrlen := congrArg List.length hrestTail
    simp at hslen hrlen
    omega
  have hsuffixValue : forall base result,
      DecimalSeqExponentEval rest base = ok result ->
        result.val = base.val + E := by
    intro base result heval
    apply DecimalSeqExponentResidualPointwise rest exponent E hrestSource
      hExpNe hExpDigits
      (fun he => by simpa using hrestTail.trans (htailNone he))
      (fun upper sign digits he => by
        simpa using hrestTail.trans (htailSome upper sign digits he))
      hENone hESome base result heval
  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 [hscan1] at hparse
  simp only [bind_tc_ok] at hparse
  simp [core.slice.Slice.is_empty, hpointRestNe, hpointIndex,
    hdropPoint, hd1zero, hloop2, Aeneas.Std.lift] at hparse
  have hloop3zero :
      num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop3 sigStart
        0#usize d1.digits = ok (bulkRest, bulkCount, bulkArray) := by
    simpa [hd1zero] using hloop3
  rw [hloop3zero] at hparse
  simp [hscan2] at hparse
  cases hb : (UScalar.hcast .I32 (Slice.len rest) : Std.I32) -
      UScalar.hcast .I32 (Slice.len afterPoint) with
  | fail err => rw [hb] at hparse; simp at hparse
  | div => rw [hb] at hparse; simp at hparse
  | ok base =>
    rw [hb] at hparse
    simp only [bind_tc_ok, hd2zero, if_false] at hparse
    have hcore :
        (do
          let finalPoint <- DecimalSeqExponentEval rest base
          let a <- num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop4
            { start := 0#usize,
              «end» :=
                num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS_WITHOUT_OVERFLOW }
            d2.digits
          ok (num.imp.dec2flt.decimal_seq.DecimalSeq.mk
            0#usize finalPoint d2.truncated a)) = ok d := by
      simpa [DecimalSeqExponentEval] using hparse
    cases he : DecimalSeqExponentEval rest base with
    | fail err => rw [he] at hcore; simp at hcore
    | div => rw [he] at hcore; simp at hcore
    | ok finalPoint =>
      have hpointVal : finalPoint.val = base.val + E :=
        hsuffixValue base finalPoint he
      obtain ⟨afill, hfill, hpref⟩ :=
        DecimalSeqFillPrefixPreserved 0#usize d2.digits
      have hfill4 :
          num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop4
            { start := 0#usize,
              «end» :=
                num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS_WITHOUT_OVERFLOW }
            d2.digits = ok afill := by
        rw [DecimalSeqDuplicateLoops.2.2.1]
        exact hfill
      rw [he] at hcore
      simp only [bind_tc_ok] at hcore
      rw [hfill4] at hcore
      simp at hcore
      subst d
      obtain ⟨kr, hkr⟩ := DecimalSeqI32HCastCongruence (Slice.len rest)
      obtain ⟨kf, hkf⟩ := DecimalSeqI32HCastCongruence (Slice.len afterPoint)
      have hbaseVal : base.val =
          (UScalar.hcast .I32 (Slice.len rest)).val -
            (UScalar.hcast .I32 (Slice.len afterPoint)).val := by
        have hh := IScalar.sub_equiv
          (UScalar.hcast .I32 (Slice.len rest) : Std.I32)
          (UScalar.hcast .I32 (Slice.len afterPoint) : Std.I32)
        rw [hb] at hh
        exact hh.2.1
      have hlenRest : (Slice.len rest).val = tail.length := by
        have hh := congrArg List.length hrestTail
        simpa [Slice.len] using hh
      have hlenAfter : (Slice.len afterPoint).val = F.length + tail.length := by
        have hh := congrArg List.length hafterPoint
        simpa [Slice.len, hLLen] using hh
      refine ⟨?_, ?_⟩
      · constructor
        · simp [hSig]
        constructor
        · simp [hSig]
        · simp [hSig, d0, hd1trunc, hd2trunc]
      · refine ⟨kr - kf, ?_⟩
        rw [hpointVal, hbaseVal, hkr, hkf, hlenRest, hlenAfter]
        have hlenSig : (I ++ F).length -
            ((I ++ F).dropWhile (fun digit => digit == 0)).length =
              I.length + F.length := by simp [hSig]
        rw [hlenSig]
        push_cast
        ring

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalDigitTrimDecomposition
import Tablet.DecimalSeqDigitRunAccumulate
import Tablet.DecimalSeqDuplicateLoops
import Tablet.DecimalSeqExponentEval
import Tablet.DecimalSeqExponentResidualPointwise
import Tablet.DecimalSeqFillPrefixPreserved
import Tablet.DecimalSeqI32HCastCongruence
import Tablet.DecimalSeqLeadingZeroLoopExact
import Tablet.DecimalSeqScalarScanExact
import Tablet.SourceValidByteSlice

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 3000000
set_option maxRecDepth 100000
namespace dec2flt_model

-- [TABLET NODE: DecimalSeqFractionalZeroState]
theorem DecimalSeqFractionalZeroState (s : Slice Std.U8) (I F tail : List Nat) (E : Int)
    (exponent : Option (Bool × Option Bool × List Nat))
    (d : num.imp.dec2flt.decimal_seq.DecimalSeq)
    (hsource : SourceValidByteSlice s)
    (hIdigits : forall z, z ∈ I -> z < 10)
    (hFdigits : forall z, z ∈ F -> z < 10)
    (hExpNe : forall upper sign digits,
      exponent = some (upper, sign, digits) -> digits ≠ [])
    (hExpDigits : forall upper sign digits,
      exponent = some (upper, sign, digits) ->
        forall z, z ∈ digits -> z < 10)
    (htailNone : exponent = none -> tail = [])
    (htailSome : forall upper sign digits,
      exponent = some (upper, sign, digits) -> tail =
        (if upper then 69 else 101) ::
          (match sign with
          | none => []
          | some negative => [if negative then 45 else 43]) ++
          digits.map (fun z => 48 + z))
    (hENone : exponent = none -> E = 0)
    (hESome : forall upper sign digits,
      exponent = some (upper, sign, digits) -> E =
        let n : Nat := digits.foldl
          (fun n digit => if n < 65536 then 10 * n + digit else n) 0
        match sign with | some true => -(n : Int) | _ => (n : Int))
    (hSigI : I.dropWhile (fun digit => digit == 0) = [])
    (hSigF : F.dropWhile (fun digit => digit == 0) = [])
    (hbytes : s.val.map (fun b => b.val) =
      I.map (fun z => 48 + z) ++ 46 :: F.map (fun z => 48 + z) ++ tail)
    (hparse : num.imp.dec2flt.decimal_seq.parse_decimal_seq s = ok d) :
    let significant := (I ++ F).dropWhile (fun digit => digit == 0)
    let trimmed :=
      (significant.reverse.dropWhile (fun digit => digit == 0)).reverse
    let z := (I ++ F).length - significant.length
    let P : Int := (I.length : Int) - z
    (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 = P + E + k * 4294967296 := by
-- BODY
  dsimp only
  have hSig : (I ++ F).dropWhile (fun digit => digit == 0) = [] := by
    simp [List.dropWhile_append, hSigI, hSigF]
  obtain ⟨zi, qi, hzi, hqi, hI, hIsigTail, hIsigstop, hItrimstop⟩ :=
    DecimalDigitTrimDecomposition I
  obtain ⟨L, qf, hL, hqf, hF, hFsigTail, hFsigstop, hFtrimstop⟩ :=
    DecimalDigitTrimDecomposition F
  have hIzeros : I = List.replicate zi 0 := by simpa [hSigI] using hI
  have hFzeros : F = List.replicate L 0 := by simpa [hSigF] using hF
  have hziLen : zi = I.length := by
    have hh := congrArg List.length hIzeros
    simpa using hh.symm
  have hLLen : L = F.length := by
    have hh := congrArg List.length hFzeros
    simpa using hh.symm
  have hIbytes : I.map (fun n => 48 + n) = List.replicate zi 48 := by
    rw [hIzeros]; simp
  have hFbytes : F.map (fun n => 48 + n) = List.replicate L 48 := by
    rw [hFzeros]; simp
  have hslead : s.val.map (fun b => b.val) =
      List.replicate zi 48 ++ 46 :: List.replicate L 48 ++ tail := by
    rw [hbytes, hIbytes, hFbytes]
  obtain ⟨s1, hlead, hs1⟩ := DecimalSeqLeadingZeroLoopExact s zi
    (46 :: List.replicate L 48 ++ tail)
    (by simpa [List.append_assoc] using hslead) (by simp)
  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 }
  obtain ⟨pointRest, d1, hscan1, hpointRest, hd1count, hd1point,
    hd1trunc, hd1old, hd1written, hd1outside⟩ :=
    DecimalSeqScalarScanExact s1 d0 ([] : List Nat)
      (46 :: List.replicate L 48 ++ tail) (by simpa using hs1)
      (by simp) (by simp) (by simp [d0])
  have hd1zero : d1.num_digits = 0#usize := by
    apply UScalar.eq_of_val_eq
    simpa [d0] using hd1count
  have hpointRestNe : pointRest.val ≠ [] := by
    intro he
    have hh := congrArg List.length hpointRest
    simp [he] at hh
  have hpointIndex : Slice.index_usize pointRest 0#usize = ok 46#u8 := by
    cases hr : pointRest.val with
    | nil => exact (hpointRestNe hr).elim
    | cons b bs =>
      have hbval : b.val = 46 := by
        have hh := congrArg List.head? hpointRest
        simp [hr] at hh
        exact hh
      have hb : b = 46#u8 := UScalar.eq_of_val_eq hbval
      simp [Slice.index_usize, hr, hb]
  let afterPoint := Slice.drop pointRest 1#usize
  have hdropPoint :
      core.slice.index.SliceIndexRangeFromUsizeSlice.index
        { start := 1#usize } pointRest = ok afterPoint := by
    simp [core.slice.index.SliceIndexRangeFromUsizeSlice.index,
      Slice.length, afterPoint, hpointRestNe]
  have hafterPoint : afterPoint.val.map (fun b => b.val) =
      List.replicate L 48 ++ tail := by
    simp [afterPoint, Slice.drop, List.map_drop, hpointRest]
  have htailStop : tail = [] \/ tail[0]? ≠ some 48 := by
    cases he : exponent with
    | none => left; exact htailNone he
    | some data =>
      rcases data with ⟨upper, sign, digits⟩
      right
      rw [htailSome upper sign digits he]
      cases upper <;> simp
  obtain ⟨sigStart, hfracLead, hsigStart⟩ :=
    DecimalSeqLeadingZeroLoopExact afterPoint L tail hafterPoint htailStop
  have hloop2 :
      num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop2 afterPoint =
        ok sigStart := by
    rw [DecimalSeqDuplicateLoops.1]
    exact hfracLead
  have htailForm : tail = [] \/ exists marker rest,
      tail = marker :: rest /\ (marker = 69 \/ marker = 101) := by
    cases he : exponent with
    | none => left; exact htailNone he
    | some data =>
      rcases data with ⟨upper, sign, digits⟩
      right
      refine ⟨if upper then 69 else 101,
        (match sign with
        | none => []
        | some negative => [if negative then 45 else 43]) ++
          digits.map (fun z => 48 + z), ?_, ?_⟩
      · exact htailSome upper sign digits he
      · cases upper <;> simp
  have hbound : d1.num_digits.val + tail.length <= UScalar.max .Usize := by
    have hsmax : s.val.length <= UScalar.max .Usize := by
      unfold SourceValidByteSlice at hsource
      simp [UScalar.max, Usize.max, Usize.numBits,
        Dec2Flt.configured_x86_64_numBits]
      omega
    have hlen := congrArg List.length hbytes
    simp only [List.length_map, List.length_append, List.length_cons] at hlen
    simp [hd1zero]
    omega
  have hd1prefix :
      (d1.digits.val.take 0).map (fun b => b.val) = ([] : List Nat) := by simp
  obtain ⟨bulkRest, rest, bulkCount, bulkArray, d2,
    hloop3, hscan2, hrest, hd2count, hd2point, hd2trunc, hd2prefix⟩ :=
    DecimalSeqDigitRunAccumulate sigStart d1 ([] : List Nat) [] tail
      (by simpa using hsigStart) (by simp) htailForm
      (by simpa using hbound) (by simpa [hd1zero]) (by simpa using hd1prefix)
  have hd2zero : d2.num_digits = 0#usize := by
    apply UScalar.eq_of_val_eq
    simpa [hd1zero] using hd2count
  have hrestTail : rest.val.map (fun b => b.val) = tail := hrest
  have hrestSource : SourceValidByteSlice rest := by
    unfold SourceValidByteSlice at hsource ⊢
    have hslen := congrArg List.length hbytes
    have hrlen := congrArg List.length hrestTail
    simp at hslen hrlen
    omega
  have hsuffixValue : forall base result,
      DecimalSeqExponentEval rest base = ok result ->
        result.val = base.val + E := by
    intro base result heval
    apply DecimalSeqExponentResidualPointwise rest exponent E hrestSource
      hExpNe hExpDigits
      (fun he => by simpa using hrestTail.trans (htailNone he))
      (fun upper sign digits he => by
        simpa using hrestTail.trans (htailSome upper sign digits he))
      hENone hESome base result heval
  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 [hscan1] at hparse
  simp only [bind_tc_ok] at hparse
  simp [core.slice.Slice.is_empty, hpointRestNe, hpointIndex,
    hdropPoint, hd1zero, hloop2, Aeneas.Std.lift] at hparse
  have hloop3zero :
      num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop3 sigStart
        0#usize d1.digits = ok (bulkRest, bulkCount, bulkArray) := by
    simpa [hd1zero] using hloop3
  rw [hloop3zero] at hparse
  simp [hscan2] at hparse
  cases hb : (UScalar.hcast .I32 (Slice.len rest) : Std.I32) -
      UScalar.hcast .I32 (Slice.len afterPoint) with
  | fail err => rw [hb] at hparse; simp at hparse
  | div => rw [hb] at hparse; simp at hparse
  | ok base =>
    rw [hb] at hparse
    simp only [bind_tc_ok, hd2zero, if_false] at hparse
    have hcore :
        (do
          let finalPoint <- DecimalSeqExponentEval rest base
          let a <- num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop4
            { start := 0#usize,
              «end» :=
                num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS_WITHOUT_OVERFLOW }
            d2.digits
          ok (num.imp.dec2flt.decimal_seq.DecimalSeq.mk
            0#usize finalPoint d2.truncated a)) = ok d := by
      simpa [DecimalSeqExponentEval] using hparse
    cases he : DecimalSeqExponentEval rest base with
    | fail err => rw [he] at hcore; simp at hcore
    | div => rw [he] at hcore; simp at hcore
    | ok finalPoint =>
      have hpointVal : finalPoint.val = base.val + E :=
        hsuffixValue base finalPoint he
      obtain ⟨afill, hfill, hpref⟩ :=
        DecimalSeqFillPrefixPreserved 0#usize d2.digits
      have hfill4 :
          num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop4
            { start := 0#usize,
              «end» :=
                num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS_WITHOUT_OVERFLOW }
            d2.digits = ok afill := by
        rw [DecimalSeqDuplicateLoops.2.2.1]
        exact hfill
      rw [he] at hcore
      simp only [bind_tc_ok] at hcore
      rw [hfill4] at hcore
      simp at hcore
      subst d
      obtain ⟨kr, hkr⟩ := DecimalSeqI32HCastCongruence (Slice.len rest)
      obtain ⟨kf, hkf⟩ := DecimalSeqI32HCastCongruence (Slice.len afterPoint)
      have hbaseVal : base.val =
          (UScalar.hcast .I32 (Slice.len rest)).val -
            (UScalar.hcast .I32 (Slice.len afterPoint)).val := by
        have hh := IScalar.sub_equiv
          (UScalar.hcast .I32 (Slice.len rest) : Std.I32)
          (UScalar.hcast .I32 (Slice.len afterPoint) : Std.I32)
        rw [hb] at hh
        exact hh.2.1
      have hlenRest : (Slice.len rest).val = tail.length := by
        have hh := congrArg List.length hrestTail
        simpa [Slice.len] using hh
      have hlenAfter : (Slice.len afterPoint).val = F.length + tail.length := by
        have hh := congrArg List.length hafterPoint
        simpa [Slice.len, hLLen] using hh
      refine ⟨?_, ?_⟩
      · constructor
        · simp [hSig]
        constructor
        · simp [hSig]
        · simp [hSig, d0, hd1trunc, hd2trunc]
      · refine ⟨kr - kf, ?_⟩
        rw [hpointVal, hbaseVal, hkr, hkf, hlenRest, hlenAfter]
        have hlenSig : (I ++ F).length -
            ((I ++ F).dropWhile (fun digit => digit == 0)).length =
              I.length + F.length := by simp [hSig]
        rw [hlenSig]
        push_cast
        ring

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 43 entries
Technical checking records
Local closure summary
{
  "node": "DecimalSeqFractionalZeroState",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "c2b476f776c5b45e733538e6f3a79363ac892e54a8dbad6db68911a276e1fcbb",
  "active_statement_hash": "5ea146c43280fa38395f598dbf1a9985b4f38f71ce92f3e0d2313395bbbefa51",
  "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",
    "DecimalSeqDigitRunAccumulate": "6a6ae3cd643a92d6",
    "DecimalSeqDuplicateLoops": "4a7630ac67b4834a",
    "DecimalSeqExponentEval": "39417be39e20ce5d",
    "DecimalSeqExponentResidualPointwise": "d932a7306198e523",
    "DecimalSeqFillPrefixPreserved": "4eabf1d65bab5e95",
    "DecimalSeqI32HCastCongruence": "bedcc032e9d40104",
    "DecimalSeqLeadingZeroLoopExact": "afa2b1ae59f7e9a8",
    "DecimalSeqScalarScanExact": "a9ff88a04accf0ed",
    "num_imp_dec2flt_decimal_seq_parse_decimal_seq": "39417be39e20ce5d"
  },
  "strict_definition_deps": {
    "DecimalSeqExponentEval": "b51b6389c17b6c1f",
    "DecimalSeqExponentResidualPointwise": "28ca0a8ac503ee01",
    "SourceValidByteSlice": "3dc42716a6378d26",
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "59bf1ff9fe88fa8d",
    "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": "244cf8318357caab",
    "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:e8d44492cd9abb215d05ed2c60d12cec52936d7d7bed6144a91fd3b12f544115",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}