P616_T1_CutoffFoldComparison

Lean checked

Statement

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

Lemma · Pre-update cutoff fold comparison

For any natural cutoff H and list D of natural numbers, start both folds at zero. In the first fold update a to 10a+d if the previous a<H, and otherwise keep a; in the second always update b to 10b+d. Their final values satisfy a\leq b and (a=b\text{ or }H\leq a). There is no digit bound in this claim.

Lean statement

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

import Tablet.Preamble

set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P616_T1_CutoffFoldComparison]
theorem P616_T1_CutoffFoldComparison (H : Nat) (ds : List Nat) :
    let a := ds.foldl (fun n d => if n < H then 10 * n + d else n) 0
    let b := ds.foldl (fun n d => 10 * n + d) 0
    a <= b ∧ (a = b ∨ H <= a) := 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

Induct on the remaining list, with arbitrary current values satisfying a\leq b and (a=b\text{ or }H\leq a). The empty list preserves both assertions. For a next entry d, if a<H, the second assertion forces a=b, since its other alternative contradicts a<H. Both updates are therefore 10a+d, so their order and equality are preserved. If H\leq a, the first update is a, while the second is 10b+d\geq b\geq a because b,d are natural. Thus the order persists and the first value remains at least H. Apply the induction hypothesis to these updated values. Initially a=b=0, proving the claim. This argument permits an update from below H to any value above it, and still processes every later entry; it does not replace the update rule by a clamp at H.

Lean proof


  have comparison (ds : List Nat) (a b : Nat)
      (hab : a <= b) (hcase : a = b ∨ H <= a) :
      ds.foldl (fun n d => if n < H then 10 * n + d else n) a <=
          ds.foldl (fun n d => 10 * n + d) b ∧
      (ds.foldl (fun n d => if n < H then 10 * n + d else n) a =
          ds.foldl (fun n d => 10 * n + d) b ∨
        H <= ds.foldl (fun n d => if n < H then 10 * n + d else n) a) := by
    induction ds generalizing a b with
    | nil => exact ⟨hab, hcase⟩
    | cons d ds ih =>
      simp only [List.foldl_cons]
      apply ih
      · split <;> omega
      · split
        next hlt =>
          rcases hcase with heq | hcap
          · left; omega
          · omega
        next hge => right; omega
  exact comparison ds 0 0 (by omega) (Or.inl rfl)
end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.Preamble

set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P616_T1_CutoffFoldComparison]
theorem P616_T1_CutoffFoldComparison (H : Nat) (ds : List Nat) :
    let a := ds.foldl (fun n d => if n < H then 10 * n + d else n) 0
    let b := ds.foldl (fun n d => 10 * n + d) 0
    a <= b ∧ (a = b ∨ H <= a) := by
-- BODY
  have comparison (ds : List Nat) (a b : Nat)
      (hab : a <= b) (hcase : a = b ∨ H <= a) :
      ds.foldl (fun n d => if n < H then 10 * n + d else n) a <=
          ds.foldl (fun n d => 10 * n + d) b ∧
      (ds.foldl (fun n d => if n < H then 10 * n + d else n) a =
          ds.foldl (fun n d => 10 * n + d) b ∨
        H <= ds.foldl (fun n d => if n < H then 10 * n + d else n) a) := by
    induction ds generalizing a b with
    | nil => exact ⟨hab, hcase⟩
    | cons d ds ih =>
      simp only [List.foldl_cons]
      apply ih
      · split <;> omega
      · split
        next hlt =>
          rcases hcase with heq | hcap
          · left; omega
          · omega
        next hge => right; omega
  exact comparison ds 0 0 (by omega) (Or.inl rfl)
end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (44)
More program dependencies (11)
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
Technical checking records
Local closure summary
{
  "node": "P616_T1_CutoffFoldComparison",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "b7261e043303e84d41a3295993d7ea69d119572bfa9efbfd8f9fb02adb3469db",
  "active_statement_hash": "0c4d225e6b17d77113afe3b11ccc44b10d93804b908adfb3949443793f2b66d7",
  "kernel_axioms": [
    "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-138",
  "boundary_theorems": {},
  "strict_theorem_deps": {},
  "strict_definition_deps": {}
}
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:9aa4ed79296839186db4cd5024188c3991833e002df4c4557f151f17f0b819e9",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}