P495_T1_BulkLoopExact

Lean checked

Statement

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

Lemma · Bulk scan with exact residual and splice

Let a slice render decimal digits D followed by R, with every digit below ten and with R empty or headed by 46, 69, or 101. Assume i.\mathit{val}+|D|+|R|\le\texttt{Usize.max}. Bulk loop 3 returns normally after consuming a length k\le|D| divisible by eight. Its residual renders \operatorname{drop}(k,D) followed by R, its count is i.\mathit{val}+k, and there is a k-byte list W with value list \operatorname{take}(k,D) such that its returned array is \operatorname{take}(i.\mathit{val},a.\mathit{val})\mathbin{++}W \mathbin{++}\operatorname{drop}(i.\mathit{val}+k,a.\mathit{val}).

Lean statement

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

import Tablet.P495_T1_BulkMixedStop
import Tablet.P495_T1_BulkStepExact

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P495_T1_BulkLoopExact]
theorem P495_T1_BulkLoopExact (s : Slice Std.U8) (i : Std.Usize)
    (a : Array Std.U8 768#usize) (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)
    (htail : tail = [] \/ exists marker rest,
      tail = marker :: rest /\ (marker = 46 \/ marker = 69 \/ marker = 101))
    (hbound : i.val + digits.length + tail.length <= UScalar.max .Usize) :
    exists (k : Nat) (rest : Slice Std.U8) (i' : Std.Usize)
      (a' : Array Std.U8 768#usize) (written : List Std.U8),
      num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop3 s i a =
        ok (rest, i', a') /\
      k <= digits.length /\ k % 8 = 0 /\
      rest.val.map (fun b => b.val) =
        (digits.drop k).map (fun z => 48 + z) ++ tail /\
      i'.val = i.val + k /\ written.length = k /\
      written.map (fun b => b.val) = digits.take k /\
      a'.val = a.val.take i.val ++ written ++ a.val.drop (i.val + k) := 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 loop in num imp dec2flt decimal seq parse decimal seq. Maintain the displayed residual/count/splice equations for the consumed k and written W, together with k\le|D| and 8\mid k. Initially k=0, W=[], and take/drop reconstructs the array, including when i.\mathit{val}>768. Use residual source length as the decreasing rank.
At any state the current count is j=i.\mathit{val}+k, and current source length is |D|-k+|R|. Their sum is i.\mathit{val}+|D|+|R|, within the assumed maximum. Whenever the first length guard permits a word read, that length is at least eight, so j+8\le\texttt{Usize.max}. This proves safety of the addition which is executed BEFORE the storage guard, even when j\ge768 or a mixed block remains.
If at least eight digits remain and j+8<768, their ASCII ranges follow from the residual equation. Apply BulkStepExact. Append its eight-byte block to W and replace k by k+8. The identities \operatorname{take}(k,D)\mathbin{++}\operatorname{take}(8, \operatorname{drop}(k,D))=\operatorname{take}(k+8,D) and drop/drop give the written and residual equations. For the array splice, the current prefix of length j is the original prefix of length i followed by W, and its suffix after j+8 is the original array suffix after i+k+8. These lengths are in bounds by the strict guard. Thus the two splices combine into the asserted single splice. The rank falls by eight.
If the source has fewer than eight bytes, the body stops before the addition. Otherwise the addition is safe by the bound above; if the storage guard is false, the body stops without reading, regardless of the number of remaining digits. In the remaining case both guards hold. If fewer than eight digits remain and the source still has eight bytes, R cannot be empty. When j+8<768, apply BulkMixedStop at marker position |D|-k; the state is returned unchanged. If at least eight digits remain, the continuation case already proved applies. These alternatives exhaust the body and establish the postcondition on every done branch. Well-founded loop induction now supplies the claimed normal return and all invariant equations.

Lean proof


  let Inv := fun p : Slice Std.U8 × Std.Usize × Array Std.U8 768#usize =>
    ∃ k written,
      k ≤ digits.length ∧ k % 8 = 0 ∧ written.length = k ∧
      written.map (fun b => b.val) = digits.take k ∧
      p.1.val.map (fun b => b.val) =
        (digits.drop k).map (fun z => 48 + z) ++ tail ∧
      p.2.1.val = i.val + k ∧
      p.2.2.val = a.val.take i.val ++ written ++ a.val.drop (i.val + k)
  let Post := fun out : Slice Std.U8 × Std.Usize × Array Std.U8 768#usize =>
    ∃ k written,
      k ≤ digits.length ∧ k % 8 = 0 ∧
      out.1.val.map (fun b => b.val) =
        (digits.drop k).map (fun z => 48 + z) ++ tail ∧
      out.2.1.val = i.val + k ∧ written.length = k ∧
      written.map (fun b => b.val) = digits.take k ∧
      out.2.2.val = a.val.take i.val ++ written ++ a.val.drop (i.val + k)
  have hloop : Aeneas.Std.WP.spec
      (num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop3 s i a) Post := by
    unfold num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop3
    apply Aeneas.Std.loop.spec_decr_nat
      (fun p : Slice Std.U8 × Std.Usize × Array Std.U8 768#usize => p.1.val.length)
      Inv Post
      (fun p => num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop3.body
        p.1 p.2.1 p.2.2)
      (s, i, a)
    · intro p hp
      rcases p with ⟨s0, i0, a0⟩
      rcases hp with ⟨k, written, hk, hmod, hwlen, hwmap, hs0, hi0, ha0⟩
      simp only [Prod.fst, Prod.snd] at hs0 hi0 ha0 ⊢
      have hlen : s0.val.length = (digits.drop k).length + tail.length := by
        have h := congrArg List.length hs0
        simpa using h
      have hbodySpec :
          num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop3.body s0 i0 a0
            ⦃ r => match r with
              | done y => Post y
              | cont x' => Inv x' ∧ x'.1.val.length < s0.val.length ⦄ := by
        by_cases hlen8 : 8 ≤ s0.val.length
        · have hsum : i0.val + s0.val.length ≤ UScalar.max .Usize := by
            calc
              i0.val + s0.val.length =
                  i.val + k + ((digits.drop k).length + tail.length) := by
                rw [hi0, hlen]
              _ = i.val + digits.length + tail.length := by
                rw [List.length_drop]
                omega
              _ ≤ UScalar.max .Usize := hbound
          have hadd : i0.val + 8 ≤ UScalar.max .Usize := by
            calc
              i0.val + 8 ≤ i0.val + s0.val.length := Nat.add_le_add_left hlen8 _
              _ ≤ UScalar.max .Usize := hsum
          obtain ⟨i2, hi2, hi2val⟩ := Aeneas.Std.WP.spec_imp_exists
            (UScalar.add_spec (x := i0) (y := 8#usize) (by simpa using hadd))
          change i2.val = i0.val + 8 at hi2val
          by_cases hcap : i2.val <
              num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS.val
          · have hstrict : i0.val + 8 < 768 := by
              have hc : i2.val < 768 := by
                simpa [num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS.eq_def] using hcap
              rw [← hi2val]
              exact hc
            by_cases hrem8 : 8 ≤ (digits.drop k).length
            · have htake :
                  (s0.val.take 8).map (fun b => b.val) =
                    ((digits.drop k).take 8).map (fun z => 48 + z) := by
                have h := congrArg (List.take 8) hs0
                rw [← List.map_take] at h
                rw [List.take_append_of_le_length (by simpa using hrem8)] at h
                rw [← List.map_take] at h
                exact h
              have hbytes : ∀ (q : Nat) (hq : q < 8),
                  48 ≤ (s0.val[q]'(by omega)).val ∧
                    (s0.val[q]'(by omega)).val ≤ 57 := by
                intro q hq
                have hqrem : q < (digits.drop k).length := by omega
                have hqTake : q < (s0.val.take 8).length := by
                  simp [List.length_take, hq, hlen8]
                have hqGet : (s0.val.take 8)[q]'hqTake = s0.val[q]'(by omega) := by
                  simp [List.getElem_take, hq]
                have hbyteMem : s0.val[q]'(by omega) ∈ s0.val.take 8 := by
                  rw [← hqGet]
                  exact List.getElem_mem hqTake
                have hvalMem : (s0.val[q]'(by omega)).val ∈
                    (s0.val.take 8).map (fun b => b.val) :=
                  List.mem_map.mpr ⟨_, hbyteMem, rfl⟩
                rw [htake] at hvalMem
                rcases List.mem_map.mp hvalMem with ⟨z, hzTake, hval⟩
                have hzDrop : z ∈ digits.drop k := List.mem_of_mem_take hzTake
                have hzDigits : z ∈ digits := List.mem_of_mem_drop hzDrop
                have hz := hdigits _ hzDigits
                omega
              obtain ⟨s1, i1, a1, w1, hbody, hs1, hi1, hwlen1,
                hwmap1, ha1⟩ := P495_T1_BulkStepExact s0 i0 a0 hlen8 hstrict hbytes
              rw [hbody]
              simp only [WP.spec_ok]
              refine ⟨⟨k + 8, written ++ w1, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩, ?_⟩
              · have hdropLen : (digits.drop k).length = digits.length - k :=
                  List.length_drop
                omega
              · omega
              · simp [hwlen, hwlen1]
              · have hwmap8 : w1.map (fun b => b.val) = (digits.drop k).take 8 := by
                  rw [hwmap1]
                  calc
                    (s0.val.take 8).map (fun b => b.val - 48) =
                        ((s0.val.take 8).map (fun b => b.val)).map
                          (fun z => z - 48) := by
                      induction s0.val.take 8 with
                      | nil => rfl
                      | cons b bs ih => simp [ih]
                    _ = (((digits.drop k).take 8).map (fun z => 48 + z)).map
                          (fun z => z - 48) := by rw [htake]
                    _ = (digits.drop k).take 8 := by
                      simp [List.map_map, Function.comp_def]
                have htakeplus : digits.take k ++ (digits.drop k).take 8 =
                    digits.take (k + 8) := by
                  have h := congrArg (List.take (k + 8))
                    (List.take_append_drop k digits)
                  rw [List.take_append] at h
                  have hleft : (digits.take k).take (k + 8) = digits.take k := by
                    rw [List.take_take]
                    simp [Nat.min_eq_left hk]
                  have hlen : (digits.take k).length = k := by
                    simp [List.length_take, Nat.min_eq_left hk]
                  rw [hleft, hlen] at h
                  simpa using h
                calc
                  (written ++ w1).map (fun b => b.val) =
                      written.map (fun b => b.val) ++ w1.map (fun b => b.val) := by
                    rw [List.map_append]
                  _ = digits.take k ++ (digits.drop k).take 8 := by
                    rw [hwmap, hwmap8]
                  _ = digits.take (k + 8) := htakeplus
              · calc
                  s1.val.map (fun b => b.val) =
                      (s0.val.map (fun b => b.val)).drop 8 := by
                    rw [hs1, List.map_drop]
                  _ = ((digits.drop k).map (fun z => 48 + z) ++ tail).drop 8 := by
                    rw [hs0]
                  _ = (digits.drop (k + 8)).map (fun z => 48 + z) ++ tail := by
                    rw [List.drop_append_of_le_length (by simpa using hrem8)]
                    simp [List.map_drop, List.drop_drop, Nat.add_comm]
              · rw [hi1, hi0]
                omega
              · rw [ha1, ha0, hi0]
                have hi768 : i.val ≤ 768 := by omega
                have hiBound : i.val ≤ a.val.length := by
                  rw [a.property]
                  simpa using hi768
                have htakeArr :
                    (a.val.take i.val ++ written ++ a.val.drop (i.val + k)).take
                        (i.val + k) = a.val.take i.val ++ written := by
                  have hprefixlen : (a.val.take i.val).length = i.val := by
                    simp [List.length_take, Nat.min_eq_left hi768]
                  rw [List.take_append]
                  simp [hprefixlen, hwlen]
                have hdropArr :
                    (a.val.take i.val ++ written ++ a.val.drop (i.val + k)).drop
                        (i.val + k + 8) = a.val.drop (i.val + k + 8) := by
                  have hprefixlen : (a.val.take i.val).length = i.val := by
                    simp [List.length_take, Nat.min_eq_left hi768]
                  simp [List.drop_append, hprefixlen, hwlen,
                    List.drop_drop, Nat.add_assoc]
                rw [htakeArr, hdropArr]
                simp [Nat.add_assoc]
              · rw [hs1]
                have hdec : (List.drop 8 s0.val).length < s0.val.length := by
                  rw [List.length_drop]
                  omega
                simpa using hdec
            · rcases htail with hnil | ⟨marker, rest, hmarkerTail, hmarker⟩
              · have : s0.val.length < 8 := by
                  have hdropShort : (digits.drop k).length < 8 := by omega
                  rw [hlen, hnil]
                  simpa using hdropShort
                omega
              · have htailState : tail = marker :: rest := hmarkerTail
                have hshortDigits : (digits.drop k).length < 8 := by omega
                have hstate : s0.val.map (fun b => b.val) =
                    (digits.drop k).map (fun z => 48 + z) ++ marker :: rest := by
                  simpa [htailState, List.map_drop] using hs0
                have hbody := P495_T1_BulkMixedStop s0 i0 a0
                  (digits.drop k) marker rest hstate hshortDigits hlen8 hmarker hstrict
                rw [hbody]
                simp only [WP.spec_ok, Post]
                refine ⟨k, written, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ <;>
                  simp_all [hs0, hi0, ha0, hwlen, hwmap, hmod, htailState]
          · have hbody :
                num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop3.body s0 i0 a0 =
                  ok (done (s0, i0, a0)) := by
              unfold num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop3.body
              simp only [Slice.length, if_pos hlen8]
              rw [hi2]
              simp [hcap]
            rw [hbody]
            simp only [WP.spec_ok, Post]
            refine ⟨k, written, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ <;>
              simp_all [hs0, hi0, ha0, hwlen, hwmap, hmod]
        · have hbody :
              num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop3.body s0 i0 a0 =
                ok (done (s0, i0, a0)) := by
            simp [num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop3.body,
              hlen8, Slice.length]
          rw [hbody]
          simp only [WP.spec_ok, Post]
          refine ⟨k, written, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ <;>
            simp_all [hs0, hi0, ha0, hwlen, hwmap, hmod]
      convert hbodySpec using 1
      funext r
      cases r <;> rfl
    · refine ⟨0, [], ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩
      · simp
      · simp
      · simp
      · simp
      · simpa using hs
      · simp
      · simp [List.take_append_drop]
  obtain ⟨out, hout, hpost⟩ := Aeneas.Std.WP.spec_imp_exists hloop
  rcases hpost with ⟨k, written, hk, hmod, hrest, hi', hwlen, hwmap, ha'⟩
  exact ⟨k, out.1, out.2.1, out.2.2, written, hout,
    hk, hmod, hrest, hi', hwlen, hwmap, ha'⟩

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.P495_T1_BulkMixedStop
import Tablet.P495_T1_BulkStepExact

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P495_T1_BulkLoopExact]
theorem P495_T1_BulkLoopExact (s : Slice Std.U8) (i : Std.Usize)
    (a : Array Std.U8 768#usize) (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)
    (htail : tail = [] \/ exists marker rest,
      tail = marker :: rest /\ (marker = 46 \/ marker = 69 \/ marker = 101))
    (hbound : i.val + digits.length + tail.length <= UScalar.max .Usize) :
    exists (k : Nat) (rest : Slice Std.U8) (i' : Std.Usize)
      (a' : Array Std.U8 768#usize) (written : List Std.U8),
      num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop3 s i a =
        ok (rest, i', a') /\
      k <= digits.length /\ k % 8 = 0 /\
      rest.val.map (fun b => b.val) =
        (digits.drop k).map (fun z => 48 + z) ++ tail /\
      i'.val = i.val + k /\ written.length = k /\
      written.map (fun b => b.val) = digits.take k /\
      a'.val = a.val.take i.val ++ written ++ a.val.drop (i.val + k) := by
-- BODY
  let Inv := fun p : Slice Std.U8 × Std.Usize × Array Std.U8 768#usize =>
    ∃ k written,
      k ≤ digits.length ∧ k % 8 = 0 ∧ written.length = k ∧
      written.map (fun b => b.val) = digits.take k ∧
      p.1.val.map (fun b => b.val) =
        (digits.drop k).map (fun z => 48 + z) ++ tail ∧
      p.2.1.val = i.val + k ∧
      p.2.2.val = a.val.take i.val ++ written ++ a.val.drop (i.val + k)
  let Post := fun out : Slice Std.U8 × Std.Usize × Array Std.U8 768#usize =>
    ∃ k written,
      k ≤ digits.length ∧ k % 8 = 0 ∧
      out.1.val.map (fun b => b.val) =
        (digits.drop k).map (fun z => 48 + z) ++ tail ∧
      out.2.1.val = i.val + k ∧ written.length = k ∧
      written.map (fun b => b.val) = digits.take k ∧
      out.2.2.val = a.val.take i.val ++ written ++ a.val.drop (i.val + k)
  have hloop : Aeneas.Std.WP.spec
      (num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop3 s i a) Post := by
    unfold num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop3
    apply Aeneas.Std.loop.spec_decr_nat
      (fun p : Slice Std.U8 × Std.Usize × Array Std.U8 768#usize => p.1.val.length)
      Inv Post
      (fun p => num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop3.body
        p.1 p.2.1 p.2.2)
      (s, i, a)
    · intro p hp
      rcases p with ⟨s0, i0, a0⟩
      rcases hp with ⟨k, written, hk, hmod, hwlen, hwmap, hs0, hi0, ha0⟩
      simp only [Prod.fst, Prod.snd] at hs0 hi0 ha0 ⊢
      have hlen : s0.val.length = (digits.drop k).length + tail.length := by
        have h := congrArg List.length hs0
        simpa using h
      have hbodySpec :
          num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop3.body s0 i0 a0
            ⦃ r => match r with
              | done y => Post y
              | cont x' => Inv x' ∧ x'.1.val.length < s0.val.length ⦄ := by
        by_cases hlen8 : 8 ≤ s0.val.length
        · have hsum : i0.val + s0.val.length ≤ UScalar.max .Usize := by
            calc
              i0.val + s0.val.length =
                  i.val + k + ((digits.drop k).length + tail.length) := by
                rw [hi0, hlen]
              _ = i.val + digits.length + tail.length := by
                rw [List.length_drop]
                omega
              _ ≤ UScalar.max .Usize := hbound
          have hadd : i0.val + 8 ≤ UScalar.max .Usize := by
            calc
              i0.val + 8 ≤ i0.val + s0.val.length := Nat.add_le_add_left hlen8 _
              _ ≤ UScalar.max .Usize := hsum
          obtain ⟨i2, hi2, hi2val⟩ := Aeneas.Std.WP.spec_imp_exists
            (UScalar.add_spec (x := i0) (y := 8#usize) (by simpa using hadd))
          change i2.val = i0.val + 8 at hi2val
          by_cases hcap : i2.val <
              num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS.val
          · have hstrict : i0.val + 8 < 768 := by
              have hc : i2.val < 768 := by
                simpa [num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS.eq_def] using hcap
              rw [← hi2val]
              exact hc
            by_cases hrem8 : 8 ≤ (digits.drop k).length
            · have htake :
                  (s0.val.take 8).map (fun b => b.val) =
                    ((digits.drop k).take 8).map (fun z => 48 + z) := by
                have h := congrArg (List.take 8) hs0
                rw [← List.map_take] at h
                rw [List.take_append_of_le_length (by simpa using hrem8)] at h
                rw [← List.map_take] at h
                exact h
              have hbytes : ∀ (q : Nat) (hq : q < 8),
                  48 ≤ (s0.val[q]'(by omega)).val ∧
                    (s0.val[q]'(by omega)).val ≤ 57 := by
                intro q hq
                have hqrem : q < (digits.drop k).length := by omega
                have hqTake : q < (s0.val.take 8).length := by
                  simp [List.length_take, hq, hlen8]
                have hqGet : (s0.val.take 8)[q]'hqTake = s0.val[q]'(by omega) := by
                  simp [List.getElem_take, hq]
                have hbyteMem : s0.val[q]'(by omega) ∈ s0.val.take 8 := by
                  rw [← hqGet]
                  exact List.getElem_mem hqTake
                have hvalMem : (s0.val[q]'(by omega)).val ∈
                    (s0.val.take 8).map (fun b => b.val) :=
                  List.mem_map.mpr ⟨_, hbyteMem, rfl⟩
                rw [htake] at hvalMem
                rcases List.mem_map.mp hvalMem with ⟨z, hzTake, hval⟩
                have hzDrop : z ∈ digits.drop k := List.mem_of_mem_take hzTake
                have hzDigits : z ∈ digits := List.mem_of_mem_drop hzDrop
                have hz := hdigits _ hzDigits
                omega
              obtain ⟨s1, i1, a1, w1, hbody, hs1, hi1, hwlen1,
                hwmap1, ha1⟩ := P495_T1_BulkStepExact s0 i0 a0 hlen8 hstrict hbytes
              rw [hbody]
              simp only [WP.spec_ok]
              refine ⟨⟨k + 8, written ++ w1, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩, ?_⟩
              · have hdropLen : (digits.drop k).length = digits.length - k :=
                  List.length_drop
                omega
              · omega
              · simp [hwlen, hwlen1]
              · have hwmap8 : w1.map (fun b => b.val) = (digits.drop k).take 8 := by
                  rw [hwmap1]
                  calc
                    (s0.val.take 8).map (fun b => b.val - 48) =
                        ((s0.val.take 8).map (fun b => b.val)).map
                          (fun z => z - 48) := by
                      induction s0.val.take 8 with
                      | nil => rfl
                      | cons b bs ih => simp [ih]
                    _ = (((digits.drop k).take 8).map (fun z => 48 + z)).map
                          (fun z => z - 48) := by rw [htake]
                    _ = (digits.drop k).take 8 := by
                      simp [List.map_map, Function.comp_def]
                have htakeplus : digits.take k ++ (digits.drop k).take 8 =
                    digits.take (k + 8) := by
                  have h := congrArg (List.take (k + 8))
                    (List.take_append_drop k digits)
                  rw [List.take_append] at h
                  have hleft : (digits.take k).take (k + 8) = digits.take k := by
                    rw [List.take_take]
                    simp [Nat.min_eq_left hk]
                  have hlen : (digits.take k).length = k := by
                    simp [List.length_take, Nat.min_eq_left hk]
                  rw [hleft, hlen] at h
                  simpa using h
                calc
                  (written ++ w1).map (fun b => b.val) =
                      written.map (fun b => b.val) ++ w1.map (fun b => b.val) := by
                    rw [List.map_append]
                  _ = digits.take k ++ (digits.drop k).take 8 := by
                    rw [hwmap, hwmap8]
                  _ = digits.take (k + 8) := htakeplus
              · calc
                  s1.val.map (fun b => b.val) =
                      (s0.val.map (fun b => b.val)).drop 8 := by
                    rw [hs1, List.map_drop]
                  _ = ((digits.drop k).map (fun z => 48 + z) ++ tail).drop 8 := by
                    rw [hs0]
                  _ = (digits.drop (k + 8)).map (fun z => 48 + z) ++ tail := by
                    rw [List.drop_append_of_le_length (by simpa using hrem8)]
                    simp [List.map_drop, List.drop_drop, Nat.add_comm]
              · rw [hi1, hi0]
                omega
              · rw [ha1, ha0, hi0]
                have hi768 : i.val ≤ 768 := by omega
                have hiBound : i.val ≤ a.val.length := by
                  rw [a.property]
                  simpa using hi768
                have htakeArr :
                    (a.val.take i.val ++ written ++ a.val.drop (i.val + k)).take
                        (i.val + k) = a.val.take i.val ++ written := by
                  have hprefixlen : (a.val.take i.val).length = i.val := by
                    simp [List.length_take, Nat.min_eq_left hi768]
                  rw [List.take_append]
                  simp [hprefixlen, hwlen]
                have hdropArr :
                    (a.val.take i.val ++ written ++ a.val.drop (i.val + k)).drop
                        (i.val + k + 8) = a.val.drop (i.val + k + 8) := by
                  have hprefixlen : (a.val.take i.val).length = i.val := by
                    simp [List.length_take, Nat.min_eq_left hi768]
                  simp [List.drop_append, hprefixlen, hwlen,
                    List.drop_drop, Nat.add_assoc]
                rw [htakeArr, hdropArr]
                simp [Nat.add_assoc]
              · rw [hs1]
                have hdec : (List.drop 8 s0.val).length < s0.val.length := by
                  rw [List.length_drop]
                  omega
                simpa using hdec
            · rcases htail with hnil | ⟨marker, rest, hmarkerTail, hmarker⟩
              · have : s0.val.length < 8 := by
                  have hdropShort : (digits.drop k).length < 8 := by omega
                  rw [hlen, hnil]
                  simpa using hdropShort
                omega
              · have htailState : tail = marker :: rest := hmarkerTail
                have hshortDigits : (digits.drop k).length < 8 := by omega
                have hstate : s0.val.map (fun b => b.val) =
                    (digits.drop k).map (fun z => 48 + z) ++ marker :: rest := by
                  simpa [htailState, List.map_drop] using hs0
                have hbody := P495_T1_BulkMixedStop s0 i0 a0
                  (digits.drop k) marker rest hstate hshortDigits hlen8 hmarker hstrict
                rw [hbody]
                simp only [WP.spec_ok, Post]
                refine ⟨k, written, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ <;>
                  simp_all [hs0, hi0, ha0, hwlen, hwmap, hmod, htailState]
          · have hbody :
                num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop3.body s0 i0 a0 =
                  ok (done (s0, i0, a0)) := by
              unfold num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop3.body
              simp only [Slice.length, if_pos hlen8]
              rw [hi2]
              simp [hcap]
            rw [hbody]
            simp only [WP.spec_ok, Post]
            refine ⟨k, written, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ <;>
              simp_all [hs0, hi0, ha0, hwlen, hwmap, hmod]
        · have hbody :
              num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop3.body s0 i0 a0 =
                ok (done (s0, i0, a0)) := by
            simp [num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop3.body,
              hlen8, Slice.length]
          rw [hbody]
          simp only [WP.spec_ok, Post]
          refine ⟨k, written, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ <;>
            simp_all [hs0, hi0, ha0, hwlen, hwmap, hmod]
      convert hbodySpec using 1
      funext r
      cases r <;> rfl
    · refine ⟨0, [], ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩
      · simp
      · simp
      · simp
      · simp
      · simpa using hs
      · simp
      · simp [List.take_append_drop]
  obtain ⟨out, hout, hpost⟩ := Aeneas.Std.WP.spec_imp_exists hloop
  rcases hpost with ⟨k, written, hk, hmod, hrest, hi', hwlen, hwmap, ha'⟩
  exact ⟨k, out.1, out.2.1, out.2.2, written, hout,
    hk, hmod, hrest, hi', hwlen, hwmap, ha'⟩

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (79)
More program dependencies (46)
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 52 entries
Technical checking records
Local closure summary
{
  "node": "P495_T1_BulkLoopExact",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "60cda08826e02bd2e3e018cc6782d1fe8aba09b741836d6f68446c0fecbd6cb8",
  "active_statement_hash": "9a89ab66963efc9a4407fd5153a77745f492af91ba200047be01a3ece3d734c9",
  "kernel_axioms": [
    "Classical.choice",
    "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": {
    "P495_T1_BulkMixedStop": "22eade145488c507",
    "P495_T1_BulkStepExact": "c220a06ddad2fe5e",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS": "0eb6fb2627d0ff5c",
    "num_imp_dec2flt_decimal_seq_parse_decimal_seq": "effb8a26907859a5"
  },
  "strict_definition_deps": {
    "SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_read_u64": "279b0c1cd8ec9e39",
    "SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_write_u64": "7bfa0dbe8c4d23de",
    "num_imp_dec2flt_common_is_8digits": "53e9de5212d69bf5",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS": "39f6cb231ef80388",
    "num_imp_dec2flt_decimal_seq_parse_decimal_seq": "da95d2d9e37f0c9d"
  }
}
Prose assessment
{
  "label": "Recorded Sound: VerifierPass",
  "assessment_status": "VerifierPass",
  "fingerprint_relation": "matches current fingerprint",
  "assessment_fingerprint": "sound-v2:970ecc9bb825e4d89775005929efd90dcc12ec357ea6f614bbf07bd5a9402382",
  "current_fingerprint": "sound-v2:970ecc9bb825e4d89775005929efd90dcc12ec357ea6f614bbf07bd5a9402382",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}