A verified rule for sequential memory passes
ProvedLight.Ends.pass3sumalgorithmsfine-grained-complexitythree-sum-1962word-ram
Consider a Light state with locals , memory , and destination . Let overwrite exactly the first destination cells with , where , and set . Assume the expression is safe and evaluates to in for every .
Suppose locals , both distinct from , hold ; the destination satisfies ; and the desired postcondition holds at . Whenever
the pass writing to cell at round terminates within steps and establishes , in any program and depth context.
This provides a reusable execution rule for array-writing loops.
Preamble
/-
Copyright (c) 2026 Anthropic, PBC. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
SPDX-License-Identifier: Apache-2.0
-/
import Definitions.Def_APSPSource_RemainingDefinitions
import Definitions.Def_APSPSource_ThreeSumApsp_Lang_Logic
import Definitions.Def_APSPSource_ThreeSumApsp_Lang_Regions
import Definitions.Def_APSPSource_ThreeSumApsp_Lang_Syntax
import Definitions.Def_ThreeSum1962Source_Bundle01
import Mathlib.Algebra.BigOperators.Fin
import Mathlib.Algebra.BigOperators.Group.Finset.Basic
import Mathlib.Algebra.Group.Int.Defs
import Mathlib.Algebra.GroupWithZero.Nat
import Mathlib.Algebra.Order.BigOperators.Group.List
import Mathlib.Algebra.Order.BigOperators.Group.Multiset
import Mathlib.Algebra.Order.Field.Basic
import Mathlib.Algebra.Order.Group.Abs
import Mathlib.Algebra.Order.Group.Int
import Mathlib.Algebra.Order.Group.Nat
import Mathlib.Algebra.Order.Group.Unbundled.Abs
import Mathlib.Algebra.Order.Ring.Abs
import Mathlib.Algebra.Order.Ring.Int
import Mathlib.Data.Int.Cast.Lemmas
import Mathlib.Data.Int.Notation
import Mathlib.Data.List.GetD
import Mathlib.Data.Nat.Cast.Order.Ring
import Mathlib.Data.Nat.Count
import Mathlib.Data.Nat.Notation
import Mathlib.Data.Nat.SuccPred
import Mathlib.LinearAlgebra.Matrix.Defs
import Mathlib.Logic.Function.Basic
import Mathlib.Order.ConditionallyCompleteLattice.Basic
import Mathlib.Tactic.GCongr
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.Positivity
import Mathlib.Tactic.Ring
import Theorems.Thm_Light_Ends_for
import Theorems.Thm_Light_Ends_of_blockSafe
set_option autoImplicit false
set_option relaxedAutoImplicit false
set_option Elab.async false
open Light
variable {lim : Limits} {P : Program} {d : ℕ}
variable {μ : ℕ → ℤ} {dst j : ℕ} {f : ℕ → ℤ}
Formal statement
theorem Light.Ends.pass {c x y n T : ℕ} {e : Expr} {loc : ℕ → ℤ} {Q : State → Prop} (f : ℕ → ℤ)
(round : ∀ j < n, e.Safe lim ⟨Function.update loc c j, wrote μ dst f j⟩ ∧
e.val ⟨Function.update loc c j, wrote μ dst f j⟩ = f j)
(done : Q ⟨Function.update loc c n, wrote μ dst f n⟩)
(hw : (lim.space : ℤ) ≤ lim.word) (hdst : dst + n ≤ lim.space) (hlen : loc x = n)
(haddr : loc y = dst) (hx : x ≠ c := by decide) (hy : y ≠ c := by decide)
(hT : n * (e.cost + 12) + 6 ≤ T := by first
|
((simp only [Light.Stmt.blockCost, Light.Cond.cost, Light.Expr.cost,
List.map_cons, List.map_nil, List.sum_cons, List.sum_nil, ]);
(first
| omega
| ((ring_nf); (omega))))
| omega
|
(simp [] <;>
first
| omega
| ((ring_nf); (omega)))) :
Ends lim P d (pass c (v x) (v y) e) ⟨loc, μ⟩ T Q := by
sorry
Source