DecimalSeqFillPrefixPreserved

Lean checked

Statement

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

Helper · Final zero fill preserves the digit prefix

For any 768-cell digit array a and Usize start index r, the first final zero-fill loop of the extracted decimal-sequence parser returns normally with an array a', and
\operatorname{take}(r,a')=\operatorname{take}(r,a).
The other three final-fill loops have the same extracted body and hence the same property by definitional equality.

Lean statement

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

import Tablet.num_imp_dec2flt_decimal_seq_parse_decimal_seq

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: DecimalSeqFillPrefixPreserved]
theorem DecimalSeqFillPrefixPreserved (start : Std.Usize)
    (a : Array Std.U8 768#usize) :
    exists a' : Array Std.U8 768#usize,
      num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop1
        { start := start,
          «end» :=
            num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS_WITHOUT_OVERFLOW }
        a = ok a' /\
      a'.val.take start.val = a.val.take start.val := 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

The loop and its range iterator are those in num imp dec2flt decimal seq parse decimal seq; its fixed end is 19 by the extracted constant num imp dec2flt decimal seq DecimalSeq MAX DIGITS WITHOUT OVERFLOW. Maintain that the iterator's current start is at least r, its end is 19, and the current array's first r cells equal those of a. Use the remaining range length as the decreasing measure.
If current start is not below 19, the iterator returns no element and the array is returned with the invariant unchanged. Otherwise the current index i satisfies r\le i<19<768. Its checked successor is representable on the configured 64-bit Usize model, and the array update at i is in bounds. The list law for updating at an index at least r shows that taking the first r cells is unchanged. The iterator start becomes i+1, still at least r, while the natural-number distance to 19 decreases strictly. Well-founded loop induction therefore proves normal return and prefix preservation. The model definitions of loops 4, 6, and 7 are byte-for-byte the same functional body as loop 1, so Lean reduces each of them to this proved loop when used by the shared parser theorem.

Lean proof


  let Inv := fun p : core.ops.range.Range Std.Usize ×
      Array Std.U8 768#usize =>
    start.val <= p.1.start.val /\
    p.1.end.val = 19 /\
    p.2.val.take start.val = a.val.take start.val
  have hloop : Aeneas.Std.WP.spec
      (num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop1
        { start := start,
          «end» :=
            num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS_WITHOUT_OVERFLOW }
        a) (fun out => out.val.take start.val = a.val.take start.val) := by
    unfold num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop1
    apply Aeneas.Std.loop.spec_decr_nat
      (fun p : core.ops.range.Range Std.Usize × Array Std.U8 768#usize =>
        p.1.end.val - p.1.start.val)
      Inv (fun out => out.val.take start.val = a.val.take start.val)
      (fun p =>
        num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop1.body
          p.1 p.2)
      ({ start := start,
         «end» :=
           num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS_WITHOUT_OVERFLOW }, a)
    · intro p hp
      rcases p with ⟨iter, arr⟩
      rcases hp with ⟨hstart, hend, hprefix⟩
      simp only [Prod.fst, Prod.snd] at hstart hend hprefix ⊢
      unfold num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop1.body
      unfold core.iter.range.IteratorRange.next
      simp [core.iter.range.StepUsize, core.iter.range.UScalarStep,
        core.cmp.PartialOrdUsize, core.cmp.impls.PartialOrdUsize.lt,
        liftFun2]
      split
      · rename_i hlt
        have hmax : iter.start.val + 1 <= UScalar.max .Usize := by
          have hbits := Dec2Flt.configured_x86_64_numBits
          simp [UScalar.max, Usize.max, Usize.numBits, hbits]
          omega
        simp [core.iter.range.UScalarStep.forward_checked, hmax]
        have hidx : iter.start.val < 768 := by omega
        obtain ⟨a1, ha1, ha1post⟩ := Aeneas.Std.WP.spec_imp_exists
          (Array.update_spec arr iter.start 0#u8 (by
            simpa [Array.length] using hidx))
        rw [ha1]
        simp [WP.spec_ok]
        refine ⟨⟨?_, hend, ?_⟩, ?_⟩
        · change start.val <= iter.start.val + 1
          omega
        rw [ha1post]
        simp [Array.set, List.take_set_of_le hstart, hprefix]
        · change iter.end.val - (iter.start.val + 1) <
            iter.end.val - iter.start.val
          omega
      · simp [WP.spec_ok, hprefix]
    · simp [Inv,
        num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS_WITHOUT_OVERFLOW.eq_def]
  obtain ⟨a', ha', hprefix⟩ := Aeneas.Std.WP.spec_imp_exists hloop
  exact ⟨a', ha', hprefix⟩

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.num_imp_dec2flt_decimal_seq_parse_decimal_seq

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: DecimalSeqFillPrefixPreserved]
theorem DecimalSeqFillPrefixPreserved (start : Std.Usize)
    (a : Array Std.U8 768#usize) :
    exists a' : Array Std.U8 768#usize,
      num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop1
        { start := start,
          «end» :=
            num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS_WITHOUT_OVERFLOW }
        a = ok a' /\
      a'.val.take start.val = a.val.take start.val := by
-- BODY
  let Inv := fun p : core.ops.range.Range Std.Usize ×
      Array Std.U8 768#usize =>
    start.val <= p.1.start.val /\
    p.1.end.val = 19 /\
    p.2.val.take start.val = a.val.take start.val
  have hloop : Aeneas.Std.WP.spec
      (num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop1
        { start := start,
          «end» :=
            num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS_WITHOUT_OVERFLOW }
        a) (fun out => out.val.take start.val = a.val.take start.val) := by
    unfold num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop1
    apply Aeneas.Std.loop.spec_decr_nat
      (fun p : core.ops.range.Range Std.Usize × Array Std.U8 768#usize =>
        p.1.end.val - p.1.start.val)
      Inv (fun out => out.val.take start.val = a.val.take start.val)
      (fun p =>
        num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop1.body
          p.1 p.2)
      ({ start := start,
         «end» :=
           num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS_WITHOUT_OVERFLOW }, a)
    · intro p hp
      rcases p with ⟨iter, arr⟩
      rcases hp with ⟨hstart, hend, hprefix⟩
      simp only [Prod.fst, Prod.snd] at hstart hend hprefix ⊢
      unfold num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop1.body
      unfold core.iter.range.IteratorRange.next
      simp [core.iter.range.StepUsize, core.iter.range.UScalarStep,
        core.cmp.PartialOrdUsize, core.cmp.impls.PartialOrdUsize.lt,
        liftFun2]
      split
      · rename_i hlt
        have hmax : iter.start.val + 1 <= UScalar.max .Usize := by
          have hbits := Dec2Flt.configured_x86_64_numBits
          simp [UScalar.max, Usize.max, Usize.numBits, hbits]
          omega
        simp [core.iter.range.UScalarStep.forward_checked, hmax]
        have hidx : iter.start.val < 768 := by omega
        obtain ⟨a1, ha1, ha1post⟩ := Aeneas.Std.WP.spec_imp_exists
          (Array.update_spec arr iter.start 0#u8 (by
            simpa [Array.length] using hidx))
        rw [ha1]
        simp [WP.spec_ok]
        refine ⟨⟨?_, hend, ?_⟩, ?_⟩
        · change start.val <= iter.start.val + 1
          omega
        rw [ha1post]
        simp [Array.set, List.take_set_of_le hstart, hprefix]
        · change iter.end.val - (iter.start.val + 1) <
            iter.end.val - iter.start.val
          omega
      · simp [WP.spec_ok, hprefix]
    · simp [Inv,
        num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS_WITHOUT_OVERFLOW.eq_def]
  obtain ⟨a', ha', hprefix⟩ := Aeneas.Std.WP.spec_imp_exists hloop
  exact ⟨a', ha', hprefix⟩

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 13 entries
Technical checking records
Local closure summary
{
  "node": "DecimalSeqFillPrefixPreserved",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "258fc3808617fa476fe4cfb09eb2e3e5d6803d4a9c1620f76c70c5f43d6f3970",
  "active_statement_hash": "b3503ea26da28fa085bc985740ac35d11dfec7b4740e483e53bb7b78f6680f39",
  "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-167",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS_WITHOUT_OVERFLOW": "6886acab8f15b99e",
    "num_imp_dec2flt_decimal_seq_parse_decimal_seq": "cb99c951cfc3a86f"
  },
  "strict_definition_deps": {
    "num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS_WITHOUT_OVERFLOW": "65634ac95536dcca",
    "num_imp_dec2flt_decimal_seq_parse_decimal_seq": "4a6288a8320b70c5"
  }
}
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:62f6d280b8cc2bb1ab7b3dbe423196001d3f6a0b27feeb250751827c61b96b11",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}