DecimalSeqDigitRunAccumulate

Lean checked

Statement

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

Helper · Accumulated exact digit-run traversal

Suppose a decimal-sequence record has logical digit list P: its count is |P| and its stored cells through \min(|P|,768) equal the corresponding prefix of P. Let a slice render a decimal digit list D followed by an empty or exponent residual, under the stated digit and Usize bounds. The extracted bulk loop and scalar digit parser return the residual and a record whose logical list is P\mathbin{++}D: its count is that list's length, its stored prefix through the 768-cell cap is exact, and its point and truncation fields are 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.DecimalSeqDigitRunExact

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

-- [TABLET NODE: DecimalSeqDigitRunAccumulate]
theorem DecimalSeqDigitRunAccumulate (s : Slice Std.U8)
    (d : num.imp.dec2flt.decimal_seq.DecimalSeq)
    (pref 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 = 69 \/ marker = 101))
    (hbound : d.num_digits.val + digits.length + tail.length <=
      UScalar.max .Usize)
    (hcount : d.num_digits.val = pref.length)
    (hprefix :
      (d.digits.val.take (min pref.length 768)).map (fun b => b.val) =
        pref.take (min pref.length 768)) :
    exists (bulkRest rest : Slice Std.U8) (bulkCount : Std.Usize)
      (bulkArray : Array Std.U8 768#usize)
      (d' : num.imp.dec2flt.decimal_seq.DecimalSeq),
      num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop3
          s d.num_digits d.digits = ok (bulkRest, bulkCount, bulkArray) /\
      num.imp.dec2flt.decimal_seq.parse_digits_into_seq bulkRest
          { d with num_digits := bulkCount, digits := bulkArray } =
        ok (rest, d') /\
      rest.val.map (fun b => b.val) = tail /\
      d'.num_digits.val = (pref ++ digits).length /\
      d'.decimal_point = d.decimal_point /\
      d'.truncated = d.truncated /\
      (d'.digits.val.take (min (pref ++ digits).length 768)).map
          (fun b => b.val) =
        (pref ++ digits).take (min (pref ++ digits).length 768) := 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 DecimalSeqDigitRunExact. It returns the actual intermediate bulk-loop state and the actual scalar-parser result. Its count equation, together with the old count |P|, is |P|+|D|=|P\mathbin{++}D|, and its point and truncation equations give the two unchanged fields.
For the stored prefix, fix an index j<\min(|P\mathbin{++}D|,768). If j<|P|, the preservation clause of DecimalSeqDigitRunExact reduces the returned cell to the old cell, and the assumed exact old prefix identifies that cell with P[j], which is also (P\mathbin{++}D)[j]. Otherwise |P|\leq j; the written-cell clause of that theorem identifies the returned cell with D[j-|P|], exactly the append-index formula for (P\mathbin{++}D)[j]. Extensionality over optional list lookup proves equality of the two capped prefixes. The call equations and exact residual supplied by the cited theorem are retained verbatim.

Lean proof


  obtain ⟨bulkRest, rest, bulkCount, bulkArray, d', hbulk, hscalar,
    hrest, hcount', hpoint, htrunc, hold, hwritten, houtside⟩ :=
    DecimalSeqDigitRunExact s d digits tail hs hdigits htail hbound
  refine ⟨bulkRest, rest, bulkCount, bulkArray, d', hbulk, hscalar,
    hrest, ?_, hpoint, htrunc, ?_⟩
  · simp [hcount']
    omega
  · apply List.ext_getElem?
    intro j
    by_cases hj : j < min (pref ++ digits).length 768
    · rw [List.getElem?_map, List.getElem?_take, List.getElem?_take]
      simp only [hj, if_true]
      by_cases hjp : j < pref.length
      · have hjold : j < min d.num_digits.val 768 := by
          rw [hcount]
          exact Nat.lt_min.mpr ⟨hjp, (Nat.lt_min.mp hj).2⟩
        have holdv := congrArg (Option.map (fun b : Std.U8 => b.val))
          (hold j hjold)
        rw [holdv]
        have hp := congrArg (fun xs : List Nat => xs[j]?) hprefix
        change (List.map (fun b : Std.U8 => b.val)
            (List.take (min pref.length 768) d.digits.val))[j]? =
          (List.take (min pref.length 768) pref)[j]? at hp
        rw [List.getElem?_map, List.getElem?_take,
          List.getElem?_take] at hp
        have hjmin : j < min pref.length 768 := by
          rw [← hcount]
          exact hjold
        rw [List.getElem?_append_left hjp]
        simpa [hjmin] using hp
      · have hjlo : d.num_digits.val <= j := by omega
        have hjhi : j < min (d.num_digits.val + digits.length) 768 := by
          rw [hcount]
          simpa using hj
        rw [hwritten j hjlo hjhi]
        have hjpLe : pref.length <= j := by omega
        rw [List.getElem?_append_right hjpLe]
        rw [hcount]
    · simp only [List.length_append] at hj
      simp [List.getElem?_map, List.getElem?_take, Nat.lt_min, hj]

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalSeqDigitRunExact

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

-- [TABLET NODE: DecimalSeqDigitRunAccumulate]
theorem DecimalSeqDigitRunAccumulate (s : Slice Std.U8)
    (d : num.imp.dec2flt.decimal_seq.DecimalSeq)
    (pref 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 = 69 \/ marker = 101))
    (hbound : d.num_digits.val + digits.length + tail.length <=
      UScalar.max .Usize)
    (hcount : d.num_digits.val = pref.length)
    (hprefix :
      (d.digits.val.take (min pref.length 768)).map (fun b => b.val) =
        pref.take (min pref.length 768)) :
    exists (bulkRest rest : Slice Std.U8) (bulkCount : Std.Usize)
      (bulkArray : Array Std.U8 768#usize)
      (d' : num.imp.dec2flt.decimal_seq.DecimalSeq),
      num.imp.dec2flt.decimal_seq.parse_decimal_seq_loop3
          s d.num_digits d.digits = ok (bulkRest, bulkCount, bulkArray) /\
      num.imp.dec2flt.decimal_seq.parse_digits_into_seq bulkRest
          { d with num_digits := bulkCount, digits := bulkArray } =
        ok (rest, d') /\
      rest.val.map (fun b => b.val) = tail /\
      d'.num_digits.val = (pref ++ digits).length /\
      d'.decimal_point = d.decimal_point /\
      d'.truncated = d.truncated /\
      (d'.digits.val.take (min (pref ++ digits).length 768)).map
          (fun b => b.val) =
        (pref ++ digits).take (min (pref ++ digits).length 768) := by
-- BODY
  obtain ⟨bulkRest, rest, bulkCount, bulkArray, d', hbulk, hscalar,
    hrest, hcount', hpoint, htrunc, hold, hwritten, houtside⟩ :=
    DecimalSeqDigitRunExact s d digits tail hs hdigits htail hbound
  refine ⟨bulkRest, rest, bulkCount, bulkArray, d', hbulk, hscalar,
    hrest, ?_, hpoint, htrunc, ?_⟩
  · simp [hcount']
    omega
  · apply List.ext_getElem?
    intro j
    by_cases hj : j < min (pref ++ digits).length 768
    · rw [List.getElem?_map, List.getElem?_take, List.getElem?_take]
      simp only [hj, if_true]
      by_cases hjp : j < pref.length
      · have hjold : j < min d.num_digits.val 768 := by
          rw [hcount]
          exact Nat.lt_min.mpr ⟨hjp, (Nat.lt_min.mp hj).2⟩
        have holdv := congrArg (Option.map (fun b : Std.U8 => b.val))
          (hold j hjold)
        rw [holdv]
        have hp := congrArg (fun xs : List Nat => xs[j]?) hprefix
        change (List.map (fun b : Std.U8 => b.val)
            (List.take (min pref.length 768) d.digits.val))[j]? =
          (List.take (min pref.length 768) pref)[j]? at hp
        rw [List.getElem?_map, List.getElem?_take,
          List.getElem?_take] at hp
        have hjmin : j < min pref.length 768 := by
          rw [← hcount]
          exact hjold
        rw [List.getElem?_append_left hjp]
        simpa [hjmin] using hp
      · have hjlo : d.num_digits.val <= j := by omega
        have hjhi : j < min (d.num_digits.val + digits.length) 768 := by
          rw [hcount]
          simpa using hj
        rw [hwritten j hjlo hjhi]
        have hjpLe : pref.length <= j := by omega
        rw [List.getElem?_append_right hjpLe]
        rw [hcount]
    · simp only [List.length_append] at hj
      simp [List.getElem?_map, List.getElem?_take, Nat.lt_min, hj]

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 25 entries
Technical checking records
Local closure summary
{
  "node": "DecimalSeqDigitRunAccumulate",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "57dc41da71a4ab55f0f9275b4efef72cc93c4df7b4ddbcbb6b813d066bde21b9",
  "active_statement_hash": "9dd4b6943e97256600b27fc2210cb4782a331837a67ba9d99a02f141cf08e9a5",
  "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": {
    "DecimalSeqDigitRunExact": "39e85ab433fb80a3"
  },
  "strict_definition_deps": {
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "59bf1ff9fe88fa8d",
    "num_imp_dec2flt_decimal_seq_parse_decimal_seq": "89c1cc8d6b6338d0",
    "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:3bc294e7faa9f2c94439df970804f25c31ff292dc9d9936fe460d40eabeef71c",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}