DecimalSeqScalarScanExact

Lean checked

Statement

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

Helper · Exact maximal scalar digit scan

Let a slice render a decimal digit list D followed by a residual value list T, where every digit of D is below ten and T is empty or begins with point, lowercase exponent, or uppercase exponent. Let d be an input decimal-sequence record and assume d.\mathtt{num\_digits}+|D| is Usize-representable. Then the extracted scalar digit parser returns a slice whose values are exactly T and a record d' such that:
d'.\mathtt{num\_digits}=d.\mathtt{num\_digits}+|D|,
its point and truncation fields are unchanged, the stored cells below the old count are unchanged, every cell from the old count up to the lesser of the new count and 768 contains the corresponding member of D, and every cell at or above that lesser count remains unchanged.

Lean statement

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

import Tablet.DecimalSeqPrimitiveSemantics
import Tablet.num_imp_dec2flt_decimal_seq_parse_digits_into_seq

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

namespace dec2flt_model

-- [TABLET NODE: DecimalSeqScalarScanExact]
theorem DecimalSeqScalarScanExact (s : Slice Std.U8)
    (d : num.imp.dec2flt.decimal_seq.DecimalSeq)
    (digits tail : List Nat)
    (hs : s.val.map (fun b => b.val) = digits.map (fun z => 48 + z) ++ tail)
    (hdigits : forall z, z ∈ digits -> z < 10)
    (hstop : tail = [] \/ tail[0]? = some 46 \/ tail[0]? = some 69 \/
      tail[0]? = some 101)
    (hbound : d.num_digits.val + digits.length <= UScalar.max .Usize) :
    exists (rest : Slice Std.U8)
      (d' : num.imp.dec2flt.decimal_seq.DecimalSeq),
      num.imp.dec2flt.decimal_seq.parse_digits_into_seq s d = ok (rest, d') /\
      rest.val.map (fun b => b.val) = tail /\
      d'.num_digits.val = d.num_digits.val + digits.length /\
      d'.decimal_point = d.decimal_point /\
      d'.truncated = d.truncated /\
      (forall j, j < min d.num_digits.val 768 ->
        d'.digits.val[j]? = d.digits.val[j]?) /\
      (forall j, d.num_digits.val <= j ->
        j < min (d.num_digits.val + digits.length) 768 ->
        (d'.digits.val[j]?).map (fun b => b.val) =
          digits[j - d.num_digits.val]?) /\
      (forall j, min (d.num_digits.val + digits.length) 768 <= j ->
        j < 768 -> d'.digits.val[j]? = d.digits.val[j]?) := 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 the extracted scalar loop in num imp dec2flt decimal seq parse digits into seq and the one-digit record semantics of DecimalSeqPrimitiveSemantics. At cursor k maintain: 0\le k\le|D|; the logical count is the old count plus k; point and truncation equal their input values; the old stored prefix is unchanged; the interval from the old count to \min(d.\mathtt{num\_digits}+k,768) contains exactly take k D; and all later cells below 768 retain their input values. The decreasing measure is |D|-k.
If k<|D|, the byte-list equation puts the cursor inside the rendered digit prefix, so the checked slice index reads exactly 48+D[k]. The bound D[k]<10 makes wrapping subtraction by 48 ordinary subtraction and makes the digit test true. The extracted try_add_digit increments the logical count in all cases; below 768 its in-bounds array update writes D[k], while at or above 768 it leaves the array unchanged and sets truncation exactly as stated by DecimalSeqPrimitiveSemantics. The assumed Usize sum justifies both the record-count and cursor increments. The list update law then establishes each of the three cell regions for k+1.
When k=|D|, the cursor is at the end of the slice if T is empty. Otherwise it reads the first residual byte. The four allowed residual forms have value 46, 69, or 101; subtracting 48 modulo 256 produces a U8 value outside 0,\ldots,9, so the loop stops without consuming it. In both cases the range-from-k wrapper returns exactly the residual slice. Instantiating the invariant at k=|D| proves the count, field, exact-write, and outside-cell claims.

Lean proof


  let Inv := fun p : num.imp.dec2flt.decimal_seq.DecimalSeq × Std.Usize =>
    p.2.val <= digits.length /\
    p.1.num_digits.val = d.num_digits.val + p.2.val /\
    p.1.decimal_point = d.decimal_point /\
    p.1.truncated = d.truncated /\
    (forall j, j < min d.num_digits.val 768 ->
      p.1.digits.val[j]? = d.digits.val[j]?) /\
    (forall j, d.num_digits.val <= j ->
      j < min (d.num_digits.val + p.2.val) 768 ->
      (p.1.digits.val[j]?).map (fun b => b.val) =
        digits[j - d.num_digits.val]?) /\
    (forall j, min (d.num_digits.val + p.2.val) 768 <= j ->
      j < 768 -> p.1.digits.val[j]? = d.digits.val[j]?)
  let Post := fun p : num.imp.dec2flt.decimal_seq.DecimalSeq × Std.Usize =>
    p.2.val = digits.length /\ Inv p
  have hloop : Aeneas.Std.WP.spec
      (num.imp.dec2flt.decimal_seq.parse_digits_into_seq_loop s d 0#usize)
      Post := by
    unfold num.imp.dec2flt.decimal_seq.parse_digits_into_seq_loop
    apply Aeneas.Std.loop.spec_decr_nat
      (fun p : num.imp.dec2flt.decimal_seq.DecimalSeq × Std.Usize =>
        digits.length - p.2.val)
      Inv Post
      (fun p =>
        num.imp.dec2flt.decimal_seq.parse_digits_into_seq_loop.body s p.1 p.2)
      (d, 0#usize)
    · intro p hp
      rcases p with ⟨e, count⟩
      rcases hp with ⟨hcount, hecount, hepoint, hetrunc,
        heold, hewritten, heoutside⟩
      simp only [Prod.fst, Prod.snd] at hcount hecount hepoint hetrunc heold hewritten heoutside ⊢
      unfold num.imp.dec2flt.decimal_seq.parse_digits_into_seq_loop.body
      by_cases hk : count.val < digits.length
      · have hks : count.val < s.val.length := by
          have hlen := congrArg List.length hs
          simp at hlen
          omega
        have hsindex : (s.val[count.val]'hks).val =
            48 + digits[count.val] := by
          have hm := congrArg (fun xs => xs[count.val]?) hs
          simp only [List.getElem?_append, List.length_map] at hm
          simp [hk] at hm
          rcases hm with ⟨a, ha, haval⟩
          rw [List.getElem?_eq_getElem hks] at ha
          cases ha
          exact haval
        simp [Slice.length, hks]
        step
        have hi1 : i1 = s.val[count.val]'hks := by
          exact i1_post
        have hdigit := hdigits digits[count.val] (List.getElem_mem _)
        step
        have hi2val : i2.val = digits[count.val] := by
          rw [i2_post, core.num.U8.wrapping_sub_val_eq, hi1, hsindex]
          simp only [UScalar.size_UScalarTyU8, U8.size_eq]
          norm_num
          omega
        have hi2lt : i2.val < 10 := by omega
        simp [hi2lt]
        step
        have hdigitval : digit.val = digits[count.val] := by
          rw [digit_post, core.num.U8.wrapping_sub_val_eq, hi1, hsindex]
          simp only [UScalar.size_UScalarTyU8, U8.size_eq]
          norm_num
          omega
        have headd : e.num_digits.val + 1 <= UScalar.max .Usize := by
          rw [hecount]
          omega
        have hcountadd : count.val + 1 <= UScalar.max .Usize := by
          omega
        obtain ⟨d1, hd1⟩ : exists d1,
            num.imp.dec2flt.decimal_seq.DecimalSeq.try_add_digit e digit =
              ok d1 := by
          unfold num.imp.dec2flt.decimal_seq.DecimalSeq.try_add_digit
          by_cases hstore : e.num_digits.val < 768
          · have hword : e.num_digits <
                num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS := by
              simpa [num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS.eq_def,
                UScalar.lt_equiv] using hstore
            simp only [hword, if_true]
            obtain ⟨a, ha, _⟩ := Aeneas.Std.WP.spec_imp_exists
              (Array.update_spec e.digits e.num_digits digit (by
                simpa [Array.length] using hstore))
            rw [ha]
            obtain ⟨next, hnext, _⟩ := Aeneas.Std.WP.spec_imp_exists
              (UScalar.add_spec (x := e.num_digits) (y := 1#usize) (by
                simpa using headd))
            rw [hnext]
            simp
          · have hword : ¬ e.num_digits <
                num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS := by
              simpa [num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS.eq_def,
                UScalar.lt_equiv] using hstore
            simp only [hword, if_false]
            obtain ⟨next, hnext, _⟩ := Aeneas.Std.WP.spec_imp_exists
              (UScalar.add_spec (x := e.num_digits) (y := 1#usize) (by
                simpa using headd))
            rw [hnext]
            simp
        rw [hd1]
        obtain ⟨he'count, he'point, he'trunc, he'arr⟩ :=
          DecimalSeqPrimitiveSemantics.2.2.2 e d1 digit hd1
        obtain ⟨count', hcount', hcount'val⟩ :=
          Aeneas.Std.WP.spec_imp_exists
            (UScalar.add_spec (x := count) (y := 1#usize) (by
              simpa using hcountadd))
        rw [hcount']
        change count'.val = count.val + 1 at hcount'val
        refine ⟨?_, ?_⟩
        · simp only [Inv, Prod.fst, Prod.snd]
          refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_⟩
          · omega
          · omega
          · exact he'point.trans hepoint
          · exact he'trunc.trans hetrunc
          · intro j hj
            by_cases hstore : e.num_digits.val < 768
            · simp [hstore] at he'arr
              rw [he'arr]
              simp only [Aeneas.Std.Array.set, List.getElem?_set]
              split
              · rename_i heq
                have : j = e.num_digits.val := by omega
                omega
              · exact heold j hj
            · simp [hstore] at he'arr
              rw [he'arr]
              exact heold j hj
          · intro j hjlo hjhi
            by_cases hjnew : j = e.num_digits.val
            · subst j
              have hstore : e.num_digits.val < 768 := by omega
              simp [hstore] at he'arr
              rw [he'arr]
              simp only [Aeneas.Std.Array.set, List.getElem?_set]
              have hidx : e.num_digits.val - d.num_digits.val = count.val := by
                omega
              rw [hidx, List.getElem?_eq_getElem hk]
              simp [hstore, hdigitval]
            · have hjprev : j < min (d.num_digits.val + count.val) 768 := by
                omega
              have hprev := hewritten j hjlo hjprev
              by_cases hstore : e.num_digits.val < 768
              · simp [hstore] at he'arr
                rw [he'arr]
                simp only [Aeneas.Std.Array.set, List.getElem?_set]
                have hne : e.num_digits.val ≠ j := Ne.symm hjnew
                simp [hne, hprev]
              · simp [hstore] at he'arr
                rw [he'arr]
                exact hprev
          · intro j hjlo hj768
            have hjne : j ≠ e.num_digits.val := by omega
            by_cases hstore : e.num_digits.val < 768
            · simp [hstore] at he'arr
              rw [he'arr]
              simp only [Aeneas.Std.Array.set, List.getElem?_set]
              have hne : e.num_digits.val ≠ j := Ne.symm hjne
              simp [hne]
              exact heoutside j (by omega) hj768
            · simp [hstore] at he'arr
              rw [he'arr]
              exact heoutside j (by omega) hj768
        · simp only [Prod.fst, Prod.snd]
          omega
      · have hkEq : count.val = digits.length := by omega
        have hlen := congrArg List.length hs
        simp at hlen
        by_cases htail : tail = []
        · have hsend : count.val = s.val.length := by
            rw [htail] at hlen
            simp at hlen
            omega
          simp [hsend, WP.spec_ok]
          exact ⟨hkEq, hcount, hecount, hepoint, hetrunc,
            heold, hewritten, heoutside⟩
        · have hlt : count.val < s.val.length := by
            rw [hkEq]
            have htlen : tail.length ≠ 0 := by simpa using htail
            have : 0 < tail.length := by omega
            omega
          simp [Slice.length, hlt]
          step
          have hi1tail : i1.val = tail[0] := by
            have hm := congrArg List.head?
              (congrArg (List.drop count.val) hs)
            simp [hkEq, List.map_drop] at hm
            have htlen : tail.length ≠ 0 := by simpa using htail
            have htpos : 0 < tail.length := by omega
            have htailHead : tail.head? = some tail[0] := by
              rw [List.head?_eq_getElem?, List.getElem?_eq_getElem htpos]
            rw [← hkEq, List.getElem?_eq_getElem hlt, htailHead] at hm
            simp only [Option.map_some, Option.some.injEq] at hm
            rw [i1_post]
            exact hm
          step
          have hi2nondigit : ¬ i2.val < 10 := by
            rw [i2_post, core.num.U8.wrapping_sub_val_eq, hi1tail]
            have htlen : tail.length ≠ 0 := by simpa using htail
            have htpos : 0 < tail.length := by omega
            rcases hstop with hnil | hpoint | he | hE
            · contradiction
            · rw [List.getElem?_eq_getElem htpos] at hpoint
              simp only [Option.some.injEq] at hpoint
              rw [hpoint]
              norm_num [U8.size_eq]
            · rw [List.getElem?_eq_getElem htpos] at he
              simp only [Option.some.injEq] at he
              rw [he]
              norm_num [U8.size_eq]
            · rw [List.getElem?_eq_getElem htpos] at hE
              simp only [Option.some.injEq] at hE
              rw [hE]
              norm_num [U8.size_eq]
          simp [hi2nondigit, WP.spec_ok]
          exact ⟨hkEq, hcount, hecount, hepoint, hetrunc,
            heold, hewritten, heoutside⟩
    · simp [Inv]
      intro j hjlo hjhi hj768
      omega
  obtain ⟨p, hp, hpPost⟩ := Aeneas.Std.WP.spec_imp_exists hloop
  rcases p with ⟨d', count⟩
  rcases hpPost with ⟨hcountEq, _, hd'count, hd'point, hd'trunc,
    hd'old, hd'written, hd'outside⟩
  simp only [Prod.fst, Prod.snd] at hcountEq hd'count hd'point hd'trunc hd'old hd'written hd'outside
  unfold num.imp.dec2flt.decimal_seq.parse_digits_into_seq
  rw [hp]
  have hcountLe : count.val <= s.val.length := by
    have hlen := congrArg List.length hs
    simp at hlen
    omega
  simp [core.slice.index.SliceIndexRangeFromUsizeSlice.index,
    Slice.drop, Slice.length, hcountLe]
  refine ⟨?_, ?_, hd'point, hd'trunc, ?_, ?_, ?_⟩
  · rw [hs, hcountEq]
    simp
  · omega
  · intro j hjlo hj768
    apply hd'old j
    omega
  · intro j hjlo hjhi hj768
    apply hd'written j hjlo
    omega
  · intro j hjlo hj768
    apply hd'outside j
    · rcases hjlo with hjlo | hjlo
      · omega
      · omega
    · exact hj768

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalSeqPrimitiveSemantics
import Tablet.num_imp_dec2flt_decimal_seq_parse_digits_into_seq

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

namespace dec2flt_model

-- [TABLET NODE: DecimalSeqScalarScanExact]
theorem DecimalSeqScalarScanExact (s : Slice Std.U8)
    (d : num.imp.dec2flt.decimal_seq.DecimalSeq)
    (digits tail : List Nat)
    (hs : s.val.map (fun b => b.val) = digits.map (fun z => 48 + z) ++ tail)
    (hdigits : forall z, z ∈ digits -> z < 10)
    (hstop : tail = [] \/ tail[0]? = some 46 \/ tail[0]? = some 69 \/
      tail[0]? = some 101)
    (hbound : d.num_digits.val + digits.length <= UScalar.max .Usize) :
    exists (rest : Slice Std.U8)
      (d' : num.imp.dec2flt.decimal_seq.DecimalSeq),
      num.imp.dec2flt.decimal_seq.parse_digits_into_seq s d = ok (rest, d') /\
      rest.val.map (fun b => b.val) = tail /\
      d'.num_digits.val = d.num_digits.val + digits.length /\
      d'.decimal_point = d.decimal_point /\
      d'.truncated = d.truncated /\
      (forall j, j < min d.num_digits.val 768 ->
        d'.digits.val[j]? = d.digits.val[j]?) /\
      (forall j, d.num_digits.val <= j ->
        j < min (d.num_digits.val + digits.length) 768 ->
        (d'.digits.val[j]?).map (fun b => b.val) =
          digits[j - d.num_digits.val]?) /\
      (forall j, min (d.num_digits.val + digits.length) 768 <= j ->
        j < 768 -> d'.digits.val[j]? = d.digits.val[j]?) := by
-- BODY
  let Inv := fun p : num.imp.dec2flt.decimal_seq.DecimalSeq × Std.Usize =>
    p.2.val <= digits.length /\
    p.1.num_digits.val = d.num_digits.val + p.2.val /\
    p.1.decimal_point = d.decimal_point /\
    p.1.truncated = d.truncated /\
    (forall j, j < min d.num_digits.val 768 ->
      p.1.digits.val[j]? = d.digits.val[j]?) /\
    (forall j, d.num_digits.val <= j ->
      j < min (d.num_digits.val + p.2.val) 768 ->
      (p.1.digits.val[j]?).map (fun b => b.val) =
        digits[j - d.num_digits.val]?) /\
    (forall j, min (d.num_digits.val + p.2.val) 768 <= j ->
      j < 768 -> p.1.digits.val[j]? = d.digits.val[j]?)
  let Post := fun p : num.imp.dec2flt.decimal_seq.DecimalSeq × Std.Usize =>
    p.2.val = digits.length /\ Inv p
  have hloop : Aeneas.Std.WP.spec
      (num.imp.dec2flt.decimal_seq.parse_digits_into_seq_loop s d 0#usize)
      Post := by
    unfold num.imp.dec2flt.decimal_seq.parse_digits_into_seq_loop
    apply Aeneas.Std.loop.spec_decr_nat
      (fun p : num.imp.dec2flt.decimal_seq.DecimalSeq × Std.Usize =>
        digits.length - p.2.val)
      Inv Post
      (fun p =>
        num.imp.dec2flt.decimal_seq.parse_digits_into_seq_loop.body s p.1 p.2)
      (d, 0#usize)
    · intro p hp
      rcases p with ⟨e, count⟩
      rcases hp with ⟨hcount, hecount, hepoint, hetrunc,
        heold, hewritten, heoutside⟩
      simp only [Prod.fst, Prod.snd] at hcount hecount hepoint hetrunc heold hewritten heoutside ⊢
      unfold num.imp.dec2flt.decimal_seq.parse_digits_into_seq_loop.body
      by_cases hk : count.val < digits.length
      · have hks : count.val < s.val.length := by
          have hlen := congrArg List.length hs
          simp at hlen
          omega
        have hsindex : (s.val[count.val]'hks).val =
            48 + digits[count.val] := by
          have hm := congrArg (fun xs => xs[count.val]?) hs
          simp only [List.getElem?_append, List.length_map] at hm
          simp [hk] at hm
          rcases hm with ⟨a, ha, haval⟩
          rw [List.getElem?_eq_getElem hks] at ha
          cases ha
          exact haval
        simp [Slice.length, hks]
        step
        have hi1 : i1 = s.val[count.val]'hks := by
          exact i1_post
        have hdigit := hdigits digits[count.val] (List.getElem_mem _)
        step
        have hi2val : i2.val = digits[count.val] := by
          rw [i2_post, core.num.U8.wrapping_sub_val_eq, hi1, hsindex]
          simp only [UScalar.size_UScalarTyU8, U8.size_eq]
          norm_num
          omega
        have hi2lt : i2.val < 10 := by omega
        simp [hi2lt]
        step
        have hdigitval : digit.val = digits[count.val] := by
          rw [digit_post, core.num.U8.wrapping_sub_val_eq, hi1, hsindex]
          simp only [UScalar.size_UScalarTyU8, U8.size_eq]
          norm_num
          omega
        have headd : e.num_digits.val + 1 <= UScalar.max .Usize := by
          rw [hecount]
          omega
        have hcountadd : count.val + 1 <= UScalar.max .Usize := by
          omega
        obtain ⟨d1, hd1⟩ : exists d1,
            num.imp.dec2flt.decimal_seq.DecimalSeq.try_add_digit e digit =
              ok d1 := by
          unfold num.imp.dec2flt.decimal_seq.DecimalSeq.try_add_digit
          by_cases hstore : e.num_digits.val < 768
          · have hword : e.num_digits <
                num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS := by
              simpa [num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS.eq_def,
                UScalar.lt_equiv] using hstore
            simp only [hword, if_true]
            obtain ⟨a, ha, _⟩ := Aeneas.Std.WP.spec_imp_exists
              (Array.update_spec e.digits e.num_digits digit (by
                simpa [Array.length] using hstore))
            rw [ha]
            obtain ⟨next, hnext, _⟩ := Aeneas.Std.WP.spec_imp_exists
              (UScalar.add_spec (x := e.num_digits) (y := 1#usize) (by
                simpa using headd))
            rw [hnext]
            simp
          · have hword : ¬ e.num_digits <
                num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS := by
              simpa [num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS.eq_def,
                UScalar.lt_equiv] using hstore
            simp only [hword, if_false]
            obtain ⟨next, hnext, _⟩ := Aeneas.Std.WP.spec_imp_exists
              (UScalar.add_spec (x := e.num_digits) (y := 1#usize) (by
                simpa using headd))
            rw [hnext]
            simp
        rw [hd1]
        obtain ⟨he'count, he'point, he'trunc, he'arr⟩ :=
          DecimalSeqPrimitiveSemantics.2.2.2 e d1 digit hd1
        obtain ⟨count', hcount', hcount'val⟩ :=
          Aeneas.Std.WP.spec_imp_exists
            (UScalar.add_spec (x := count) (y := 1#usize) (by
              simpa using hcountadd))
        rw [hcount']
        change count'.val = count.val + 1 at hcount'val
        refine ⟨?_, ?_⟩
        · simp only [Inv, Prod.fst, Prod.snd]
          refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_⟩
          · omega
          · omega
          · exact he'point.trans hepoint
          · exact he'trunc.trans hetrunc
          · intro j hj
            by_cases hstore : e.num_digits.val < 768
            · simp [hstore] at he'arr
              rw [he'arr]
              simp only [Aeneas.Std.Array.set, List.getElem?_set]
              split
              · rename_i heq
                have : j = e.num_digits.val := by omega
                omega
              · exact heold j hj
            · simp [hstore] at he'arr
              rw [he'arr]
              exact heold j hj
          · intro j hjlo hjhi
            by_cases hjnew : j = e.num_digits.val
            · subst j
              have hstore : e.num_digits.val < 768 := by omega
              simp [hstore] at he'arr
              rw [he'arr]
              simp only [Aeneas.Std.Array.set, List.getElem?_set]
              have hidx : e.num_digits.val - d.num_digits.val = count.val := by
                omega
              rw [hidx, List.getElem?_eq_getElem hk]
              simp [hstore, hdigitval]
            · have hjprev : j < min (d.num_digits.val + count.val) 768 := by
                omega
              have hprev := hewritten j hjlo hjprev
              by_cases hstore : e.num_digits.val < 768
              · simp [hstore] at he'arr
                rw [he'arr]
                simp only [Aeneas.Std.Array.set, List.getElem?_set]
                have hne : e.num_digits.val ≠ j := Ne.symm hjnew
                simp [hne, hprev]
              · simp [hstore] at he'arr
                rw [he'arr]
                exact hprev
          · intro j hjlo hj768
            have hjne : j ≠ e.num_digits.val := by omega
            by_cases hstore : e.num_digits.val < 768
            · simp [hstore] at he'arr
              rw [he'arr]
              simp only [Aeneas.Std.Array.set, List.getElem?_set]
              have hne : e.num_digits.val ≠ j := Ne.symm hjne
              simp [hne]
              exact heoutside j (by omega) hj768
            · simp [hstore] at he'arr
              rw [he'arr]
              exact heoutside j (by omega) hj768
        · simp only [Prod.fst, Prod.snd]
          omega
      · have hkEq : count.val = digits.length := by omega
        have hlen := congrArg List.length hs
        simp at hlen
        by_cases htail : tail = []
        · have hsend : count.val = s.val.length := by
            rw [htail] at hlen
            simp at hlen
            omega
          simp [hsend, WP.spec_ok]
          exact ⟨hkEq, hcount, hecount, hepoint, hetrunc,
            heold, hewritten, heoutside⟩
        · have hlt : count.val < s.val.length := by
            rw [hkEq]
            have htlen : tail.length ≠ 0 := by simpa using htail
            have : 0 < tail.length := by omega
            omega
          simp [Slice.length, hlt]
          step
          have hi1tail : i1.val = tail[0] := by
            have hm := congrArg List.head?
              (congrArg (List.drop count.val) hs)
            simp [hkEq, List.map_drop] at hm
            have htlen : tail.length ≠ 0 := by simpa using htail
            have htpos : 0 < tail.length := by omega
            have htailHead : tail.head? = some tail[0] := by
              rw [List.head?_eq_getElem?, List.getElem?_eq_getElem htpos]
            rw [← hkEq, List.getElem?_eq_getElem hlt, htailHead] at hm
            simp only [Option.map_some, Option.some.injEq] at hm
            rw [i1_post]
            exact hm
          step
          have hi2nondigit : ¬ i2.val < 10 := by
            rw [i2_post, core.num.U8.wrapping_sub_val_eq, hi1tail]
            have htlen : tail.length ≠ 0 := by simpa using htail
            have htpos : 0 < tail.length := by omega
            rcases hstop with hnil | hpoint | he | hE
            · contradiction
            · rw [List.getElem?_eq_getElem htpos] at hpoint
              simp only [Option.some.injEq] at hpoint
              rw [hpoint]
              norm_num [U8.size_eq]
            · rw [List.getElem?_eq_getElem htpos] at he
              simp only [Option.some.injEq] at he
              rw [he]
              norm_num [U8.size_eq]
            · rw [List.getElem?_eq_getElem htpos] at hE
              simp only [Option.some.injEq] at hE
              rw [hE]
              norm_num [U8.size_eq]
          simp [hi2nondigit, WP.spec_ok]
          exact ⟨hkEq, hcount, hecount, hepoint, hetrunc,
            heold, hewritten, heoutside⟩
    · simp [Inv]
      intro j hjlo hjhi hj768
      omega
  obtain ⟨p, hp, hpPost⟩ := Aeneas.Std.WP.spec_imp_exists hloop
  rcases p with ⟨d', count⟩
  rcases hpPost with ⟨hcountEq, _, hd'count, hd'point, hd'trunc,
    hd'old, hd'written, hd'outside⟩
  simp only [Prod.fst, Prod.snd] at hcountEq hd'count hd'point hd'trunc hd'old hd'written hd'outside
  unfold num.imp.dec2flt.decimal_seq.parse_digits_into_seq
  rw [hp]
  have hcountLe : count.val <= s.val.length := by
    have hlen := congrArg List.length hs
    simp at hlen
    omega
  simp [core.slice.index.SliceIndexRangeFromUsizeSlice.index,
    Slice.drop, Slice.length, hcountLe]
  refine ⟨?_, ?_, hd'point, hd'trunc, ?_, ?_, ?_⟩
  · rw [hs, hcountEq]
    simp
  · omega
  · intro j hjlo hj768
    apply hd'old j
    omega
  · intro j hjlo hjhi hj768
    apply hd'written j hjlo
    omega
  · intro j hjlo hj768
    apply hd'outside j
    · rcases hjlo with hjlo | hjlo
      · omega
      · omega
    · exact hj768

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (51)
More program dependencies (18)
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 8 entries
Technical checking records
Local closure summary
{
  "node": "DecimalSeqScalarScanExact",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "03a999f335834bcb695d0977846acbf0c66f57a17ed0cac74f566b88bc098d7a",
  "active_statement_hash": "edd2eaf79149b722edb9bd69bdf3a65c68fa60a49c57d32940f294a368eca799",
  "kernel_axioms": [
    "Classical.choice",
    "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-167",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DecimalSeqPrimitiveSemantics": "d1871c68600bfbcd",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS": "0eb6fb2627d0ff5c",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_try_add_digit": "0eb6fb2627d0ff5c",
    "num_imp_dec2flt_decimal_seq_parse_digits_into_seq": "faf0081b4c91301b"
  },
  "strict_definition_deps": {
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "6799fe6525ddb761",
    "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_DecimalSeq_try_add_digit": "69a4869a11307175",
    "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:2fd02c19bcbd5096238f3b303c4a34cfc3dbd7d23dd76c9d09a8ab8def59d3d3",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}