DecimalSeqDigitRunExact

Lean checked

Statement

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

Helper · Exact complete digit-run traversal

Let a slice render a list D of decimal digits followed either by no residual bytes or by an uppercase or lowercase exponent marker and its suffix. Assume every member of D is below ten and that the input logical count plus the lengths of D and the residual is Usize-representable. The extracted eight-byte loop returns an intermediate slice, count, and array; the extracted scalar parser then returns the original residual and a record d'. The record has logical count d.\mathtt{num\_digits}+|D|, unchanged point and truncation fields, preserves all cells below the old count, stores D[j-d.\mathtt{num\_digits}] in every cell between the old count and \min(d.\mathtt{num\_digits}+|D|,768), and preserves every cell from that minimum through cell 767.

Lean statement

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

import Tablet.DecimalSeqBulkLoopExact
import Tablet.DecimalSeqScalarScanExact

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: DecimalSeqDigitRunExact]
theorem DecimalSeqDigitRunExact (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)
    (htail : tail = [] \/ exists marker rest,
      tail = marker :: rest /\ (marker = 69 \/ marker = 101))
    (hbound : d.num_digits.val + digits.length + tail.length <=
      UScalar.max .Usize) :
    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 = 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

Apply DecimalSeqBulkLoopExact. It supplies a consumed length k, the actual intermediate return of the extracted bulk loop, a count equal to the old count plus k, a residual rendering drop k D followed by the same exponent residual, and the exact parent-array splice containing the first k digits. Since k\le |D|, the stated total Usize bound implies the scalar bound for the remaining |D|-k digits.
Apply DecimalSeqScalarScanExact to that residual and intermediate record. Its permitted stopping byte is precisely the supplied empty residual or exponent marker. It consumes drop k D, returns the unchanged residual, and advances the count by |D|-k; hence the final count is the old count plus |D|. Both component theorems preserve the point and truncation fields.
For a cell below the old count, scalar preservation reduces it to the bulk array, and the exact bulk splice reduces it to the original array prefix. At a cell in the asserted written interval, split at old-count-plus-k. Below that split, the bulk splice and its exact written-value list give the corresponding member of take k D. At or above it, the scalar write clause gives the corresponding member of drop k D; the subtraction identity k+(j-(d.\mathtt{num\_digits}+k))=j-d.\mathtt{num\_digits} aligns the index. Finally, a cell at or above the new capped count is first preserved by the scalar theorem and then, using the exact bulk suffix splice, is the matching cell of the original array. These three cases prove all cell claims while retaining the actual two extracted call equations in the conclusion.

Lean proof


  obtain ⟨k, bulkRest, bulkCount, bulkArray, written, hbulk, hk, hkmod,
    hbulkRest, hbulkCount, hwrittenLen, hwrittenVals, hbulkArray⟩ :=
    DecimalSeqBulkLoopExact s d.num_digits d.digits digits tail hs hdigits
      htail hbound
  let dbulk : num.imp.dec2flt.decimal_seq.DecimalSeq :=
    { d with num_digits := bulkCount, digits := bulkArray }
  have hscalarBound : dbulk.num_digits.val + (digits.drop k).length <=
      UScalar.max .Usize := by
    simp [dbulk, hbulkCount]
    omega
  have hstop : tail = [] \/ tail[0]? = some 46 \/ tail[0]? = some 69 \/
      tail[0]? = some 101 := by
    rcases htail with rfl | ⟨marker, rest, rfl, hmarker⟩
    · simp
    · rcases hmarker with rfl | rfl <;> simp
  obtain ⟨rest, d', hscalar, hrest, hd'count, hd'point, hd'trunc,
    hscalarOld, hscalarWritten, hscalarOutside⟩ :=
    DecimalSeqScalarScanExact bulkRest dbulk (digits.drop k) tail
      hbulkRest (fun z hz => hdigits z (List.mem_of_mem_drop hz)) hstop
      hscalarBound
  refine ⟨bulkRest, rest, bulkCount, bulkArray, d', hbulk, hscalar,
    hrest, ?_, ?_, ?_, ?_, ?_, ?_⟩
  · simp [dbulk] at hd'count
    rw [hbulkCount] at hd'count
    simpa [Nat.add_assoc, Nat.add_sub_of_le hk] using hd'count
  · simpa [dbulk] using hd'point
  · simpa [dbulk] using hd'trunc
  · intro j hj
    have hjbulk : j < min bulkCount.val 768 := by
      rw [hbulkCount]
      apply Nat.lt_min.mpr
      exact ⟨by omega, (Nat.lt_min.mp hj).2⟩
    rw [hscalarOld j hjbulk]
    simp [dbulk]
    rw [hbulkArray]
    have hpreidx : j < (d.digits.val.take d.num_digits.val).length := by
      simp [d.digits.property]
      exact Nat.lt_min.mp hj
    rw [show d.digits.val.take d.num_digits.val ++ written ++
        d.digits.val.drop (d.num_digits.val + k) =
        d.digits.val.take d.num_digits.val ++
          (written ++ d.digits.val.drop (d.num_digits.val + k)) by
      simp [List.append_assoc]]
    rw [List.getElem?_append_left hpreidx, List.getElem?_take]
    simp [(Nat.lt_min.mp hj).1]
  · intro j hjlo hjhi
    by_cases hjbulk : j < d.num_digits.val + k
    · have hjbulkMin : j < min bulkCount.val 768 := by
        rw [hbulkCount]
        omega
      rw [hscalarOld j hjbulkMin]
      simp [dbulk]
      rw [hbulkArray]
      have hiLe : d.num_digits.val <= 768 := by omega
      have hprelen : (d.digits.val.take d.num_digits.val).length =
          d.num_digits.val := by simp [hiLe]
      have hwidx : j - d.num_digits.val < written.length := by
        rw [hwrittenLen]
        omega
      have hpreLe : (d.digits.val.take d.num_digits.val).length <= j := by
        rw [hprelen]
        exact hjlo
      rw [show d.digits.val.take d.num_digits.val ++ written ++
          d.digits.val.drop (d.num_digits.val + k) =
          d.digits.val.take d.num_digits.val ++
            (written ++ d.digits.val.drop (d.num_digits.val + k)) by
        simp [List.append_assoc]]
      rw [List.getElem?_append_right hpreLe, hprelen,
        List.getElem?_append_left hwidx]
      have hidxk : j - d.num_digits.val < k := by
        simpa [hwrittenLen] using hwidx
      have hsub : j - d.num_digits.val < digits.length := by omega
      rw [← List.getElem?_map]
      rw [hwrittenVals]
      simp [hidxk, hsub]
    · have hjbulkLo : dbulk.num_digits.val <= j := by
        simp [dbulk, hbulkCount]
        omega
      have hjbulkHi : j <
          min (dbulk.num_digits.val + (digits.drop k).length) 768 := by
        simp [dbulk, hbulkCount]
        omega
      have hs := hscalarWritten j hjbulkLo hjbulkHi
      simp [dbulk, hbulkCount] at hs
      rw [hs]
      have heq : k + (j - (d.num_digits.val + k)) =
          j - d.num_digits.val := by omega
      rw [heq]
  · intro j hjlo hj768
    have hjscalar :
        min (dbulk.num_digits.val + (digits.drop k).length) 768 <= j := by
      simp [dbulk, hbulkCount]
      omega
    rw [hscalarOutside j hjscalar hj768]
    simp [dbulk]
    rw [hbulkArray]
    have hiLe : d.num_digits.val <= 768 := by
      by_contra h
      have hmin : min (d.num_digits.val + digits.length) 768 = 768 :=
        Nat.min_eq_right (by omega)
      rw [hmin] at hjlo
      omega
    have hprelen : (d.digits.val.take d.num_digits.val).length =
        d.num_digits.val := by simp [hiLe]
    have hbefore : d.num_digits.val + k <= j := by omega
    have hprefixlen :
        (d.digits.val.take d.num_digits.val ++ written).length =
          d.num_digits.val + k := by simp [hprelen, hwrittenLen]
    rw [show d.digits.val.take d.num_digits.val ++ written ++
        d.digits.val.drop (d.num_digits.val + k) =
        (d.digits.val.take d.num_digits.val ++ written) ++
          d.digits.val.drop (d.num_digits.val + k) by
      simp [List.append_assoc]]
    have hpLe :
        (d.digits.val.take d.num_digits.val ++ written).length <= j := by
      rw [hprefixlen]
      exact hbefore
    rw [List.getElem?_append_right hpLe, List.getElem?_drop]
    congr 2
    omega

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalSeqBulkLoopExact
import Tablet.DecimalSeqScalarScanExact

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: DecimalSeqDigitRunExact]
theorem DecimalSeqDigitRunExact (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)
    (htail : tail = [] \/ exists marker rest,
      tail = marker :: rest /\ (marker = 69 \/ marker = 101))
    (hbound : d.num_digits.val + digits.length + tail.length <=
      UScalar.max .Usize) :
    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 = 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
  obtain ⟨k, bulkRest, bulkCount, bulkArray, written, hbulk, hk, hkmod,
    hbulkRest, hbulkCount, hwrittenLen, hwrittenVals, hbulkArray⟩ :=
    DecimalSeqBulkLoopExact s d.num_digits d.digits digits tail hs hdigits
      htail hbound
  let dbulk : num.imp.dec2flt.decimal_seq.DecimalSeq :=
    { d with num_digits := bulkCount, digits := bulkArray }
  have hscalarBound : dbulk.num_digits.val + (digits.drop k).length <=
      UScalar.max .Usize := by
    simp [dbulk, hbulkCount]
    omega
  have hstop : tail = [] \/ tail[0]? = some 46 \/ tail[0]? = some 69 \/
      tail[0]? = some 101 := by
    rcases htail with rfl | ⟨marker, rest, rfl, hmarker⟩
    · simp
    · rcases hmarker with rfl | rfl <;> simp
  obtain ⟨rest, d', hscalar, hrest, hd'count, hd'point, hd'trunc,
    hscalarOld, hscalarWritten, hscalarOutside⟩ :=
    DecimalSeqScalarScanExact bulkRest dbulk (digits.drop k) tail
      hbulkRest (fun z hz => hdigits z (List.mem_of_mem_drop hz)) hstop
      hscalarBound
  refine ⟨bulkRest, rest, bulkCount, bulkArray, d', hbulk, hscalar,
    hrest, ?_, ?_, ?_, ?_, ?_, ?_⟩
  · simp [dbulk] at hd'count
    rw [hbulkCount] at hd'count
    simpa [Nat.add_assoc, Nat.add_sub_of_le hk] using hd'count
  · simpa [dbulk] using hd'point
  · simpa [dbulk] using hd'trunc
  · intro j hj
    have hjbulk : j < min bulkCount.val 768 := by
      rw [hbulkCount]
      apply Nat.lt_min.mpr
      exact ⟨by omega, (Nat.lt_min.mp hj).2⟩
    rw [hscalarOld j hjbulk]
    simp [dbulk]
    rw [hbulkArray]
    have hpreidx : j < (d.digits.val.take d.num_digits.val).length := by
      simp [d.digits.property]
      exact Nat.lt_min.mp hj
    rw [show d.digits.val.take d.num_digits.val ++ written ++
        d.digits.val.drop (d.num_digits.val + k) =
        d.digits.val.take d.num_digits.val ++
          (written ++ d.digits.val.drop (d.num_digits.val + k)) by
      simp [List.append_assoc]]
    rw [List.getElem?_append_left hpreidx, List.getElem?_take]
    simp [(Nat.lt_min.mp hj).1]
  · intro j hjlo hjhi
    by_cases hjbulk : j < d.num_digits.val + k
    · have hjbulkMin : j < min bulkCount.val 768 := by
        rw [hbulkCount]
        omega
      rw [hscalarOld j hjbulkMin]
      simp [dbulk]
      rw [hbulkArray]
      have hiLe : d.num_digits.val <= 768 := by omega
      have hprelen : (d.digits.val.take d.num_digits.val).length =
          d.num_digits.val := by simp [hiLe]
      have hwidx : j - d.num_digits.val < written.length := by
        rw [hwrittenLen]
        omega
      have hpreLe : (d.digits.val.take d.num_digits.val).length <= j := by
        rw [hprelen]
        exact hjlo
      rw [show d.digits.val.take d.num_digits.val ++ written ++
          d.digits.val.drop (d.num_digits.val + k) =
          d.digits.val.take d.num_digits.val ++
            (written ++ d.digits.val.drop (d.num_digits.val + k)) by
        simp [List.append_assoc]]
      rw [List.getElem?_append_right hpreLe, hprelen,
        List.getElem?_append_left hwidx]
      have hidxk : j - d.num_digits.val < k := by
        simpa [hwrittenLen] using hwidx
      have hsub : j - d.num_digits.val < digits.length := by omega
      rw [← List.getElem?_map]
      rw [hwrittenVals]
      simp [hidxk, hsub]
    · have hjbulkLo : dbulk.num_digits.val <= j := by
        simp [dbulk, hbulkCount]
        omega
      have hjbulkHi : j <
          min (dbulk.num_digits.val + (digits.drop k).length) 768 := by
        simp [dbulk, hbulkCount]
        omega
      have hs := hscalarWritten j hjbulkLo hjbulkHi
      simp [dbulk, hbulkCount] at hs
      rw [hs]
      have heq : k + (j - (d.num_digits.val + k)) =
          j - d.num_digits.val := by omega
      rw [heq]
  · intro j hjlo hj768
    have hjscalar :
        min (dbulk.num_digits.val + (digits.drop k).length) 768 <= j := by
      simp [dbulk, hbulkCount]
      omega
    rw [hscalarOutside j hjscalar hj768]
    simp [dbulk]
    rw [hbulkArray]
    have hiLe : d.num_digits.val <= 768 := by
      by_contra h
      have hmin : min (d.num_digits.val + digits.length) 768 = 768 :=
        Nat.min_eq_right (by omega)
      rw [hmin] at hjlo
      omega
    have hprelen : (d.digits.val.take d.num_digits.val).length =
        d.num_digits.val := by simp [hiLe]
    have hbefore : d.num_digits.val + k <= j := by omega
    have hprefixlen :
        (d.digits.val.take d.num_digits.val ++ written).length =
          d.num_digits.val + k := by simp [hprelen, hwrittenLen]
    rw [show d.digits.val.take d.num_digits.val ++ written ++
        d.digits.val.drop (d.num_digits.val + k) =
        (d.digits.val.take d.num_digits.val ++ written) ++
          d.digits.val.drop (d.num_digits.val + k) by
      simp [List.append_assoc]]
    have hpLe :
        (d.digits.val.take d.num_digits.val ++ written).length <= j := by
      rw [hprefixlen]
      exact hbefore
    rw [List.getElem?_append_right hpLe, List.getElem?_drop]
    congr 2
    omega

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 24 entries
Technical checking records
Local closure summary
{
  "node": "DecimalSeqDigitRunExact",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "48fa84ccb8b00d3c70ad7b877277b1180115c7132ca7b7711682cfdcadc06d8f",
  "active_statement_hash": "851bd20c9d1482f49068481851d8511650c9b7b827315927452f28adb1f56bd0",
  "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": {
    "DecimalSeqBulkLoopExact": "d4ddf7825a34f415",
    "DecimalSeqScalarScanExact": "a9ff88a04accf0ed"
  },
  "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:8d6f815785f1e4f222d33c10c5155ab1338f94c98606af800360877e6fad2054",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}