Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
5909d1b
feat(DataStructure/Memory): word-addressed memory oracle and named fi…
SamuelSchlesinger Nov 1, 2026
412f614
doc(bib): add Guéneau, Charguéraud and Pottier (ESOP 2018)
SamuelSchlesinger Nov 1, 2026
16a647f
feat(DataStructure/StateTransition): refinements by abstraction funct…
SamuelSchlesinger Nov 1, 2026
2f12c49
feat(DataStructure/StateTransition): weaken and rescale amortized ref…
SamuelSchlesinger Nov 1, 2026
fba5208
Merge the memory-oracle branch (#2211) into the queue slice
SamuelSchlesinger Nov 1, 2026
98e3290
fix(DataStructure/StateTransition): place productCharge beside produc…
SamuelSchlesinger Nov 1, 2026
02ba9f7
Merge the refinement branch (#2212) into the queue slice
SamuelSchlesinger Nov 1, 2026
56232f9
refactor(DataStructure/StateTransition): make Refinement.Amortized a …
SamuelSchlesinger Nov 1, 2026
1b4e2ea
Merge the refinement branch (#2212) into the queue slice
SamuelSchlesinger Nov 1, 2026
fe7d60d
wip: array stack over memory and queue method lemmas
SamuelSchlesinger Nov 1, 2026
aad5f3e
feat(Foundations): affine cost bounds are O(size)
SamuelSchlesinger Nov 1, 2026
78cf872
Merge the refinement branch (#2212) into the queue slice
SamuelSchlesinger Nov 1, 2026
6698e86
wip: queue over memory
SamuelSchlesinger Nov 1, 2026
7dda248
refactor(DataStructure/StateTransition): product answer types via Sum…
SamuelSchlesinger Nov 1, 2026
93adf90
Merge the refinement branch (#2212) into the queue slice
SamuelSchlesinger Nov 1, 2026
412ad37
feat(DataStructure): queue over two array stacks over the memory oracle
SamuelSchlesinger Nov 1, 2026
4283b8f
feat(WordRAM): certify compositional register-word glue
SamuelSchlesinger Nov 1, 2026
cb0adff
Merge commit '4283b8fb714450e78ba170865bcb54ce8563bce3' into codex/ra…
SamuelSchlesinger Nov 1, 2026
45dd184
feat(WordRAM): realize memory queries with uniform bind and glue
SamuelSchlesinger Nov 1, 2026
d8f6bea
fix(WordRAM): normalize the memory return simp rule
SamuelSchlesinger Nov 1, 2026
4977e9b
feat(WordRAM): realize bounded loops and initialized client programs
SamuelSchlesinger Nov 1, 2026
04a06b5
feat(WordRAM): derive global and framed implementation certificates
SamuelSchlesinger Nov 2, 2026
e768e0a
chore(WordRAM): combine published realization and queue prerequisites
SamuelSchlesinger Nov 2, 2026
5917ae4
feat(WordRAM): realize runtime-layout memory-stack methods
SamuelSchlesinger Nov 2, 2026
a929a76
refactor(WordRAM): centralize realization history and word encodings
SamuelSchlesinger Nov 2, 2026
5b9f10e
Merge commit 'a929a76f23194a8e94428973bca2a317f9f23755' into codex/ra…
SamuelSchlesinger Nov 2, 2026
383a520
refactor(WordRAM): expose shared glue rules and infer stack push
SamuelSchlesinger Nov 2, 2026
a91fb0a
feat(WordRAM): realize tactic for memory-client realizations
SamuelSchlesinger Nov 2, 2026
141d112
feat(WordRAM): loops whose body issues a query in realize
SamuelSchlesinger Nov 2, 2026
de22695
test(WordRAM): a whole stack client to a flat program via realize
SamuelSchlesinger Nov 2, 2026
5fd685c
Merge remote-tracking branch 'pr/2246' into feat/ram-realization-adapter
SamuelSchlesinger Nov 2, 2026
0a8975c
fix(WordRAM): destructure the loop argument in Realizes.iterate₀
SamuelSchlesinger Nov 2, 2026
4d7e97c
feat(WordRAM): native backends for memory refinements, one realized b…
SamuelSchlesinger Nov 2, 2026
f51bcd8
style(tests): wrap long lines in the backend test
SamuelSchlesinger Nov 2, 2026
7d6ef37
feat(WordRAM): Backend.data, rep_data and fits_appendWords
SamuelSchlesinger Nov 2, 2026
fb0bf09
test(WordRAM): backend test uses fits_appendWords and Backend.data
SamuelSchlesinger Nov 2, 2026
309306a
Merge origin/main into feat/ram-realization-adapter
SamuelSchlesinger Nov 2, 2026
cac0b0e
chore: drop imports the merge duplicated in Complexity.lean
SamuelSchlesinger Nov 2, 2026
9087b25
feat(WordRAM/Realization): randomized realization of memory clients w…
SamuelSchlesinger Nov 2, 2026
4d5b80c
test(WordRAM): check joint randomized result and memory outcomes
SamuelSchlesinger Nov 2, 2026
aaf79a2
chore(WordRAM): preserve approved K1 on fixed actual main
SamuelSchlesinger Nov 2, 2026
1d90356
doc(WordRAM): explain joint randomized memory realizations
SamuelSchlesinger Nov 2, 2026
76a1dbe
chore(realize): preserve K1 after Standard integration
codex Nov 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Complexity.lean
Original file line number Diff line number Diff line change
Expand Up @@ -2655,6 +2655,8 @@ public import Complexity.Computability.WordRAM.Realization.Module
public import Complexity.Computability.WordRAM.Realization.Primitive
public import Complexity.Computability.WordRAM.Realization.Program
public import Complexity.Computability.WordRAM.Realization.Program.Standard
public import Complexity.Computability.WordRAM.Realization.Random
public import Complexity.Computability.WordRAM.Realization.RandomLoop
public import Complexity.Computability.WordRAM.Realization.Reindex
public import Complexity.Computability.WordRAM.Realization.Result
public import Complexity.Computability.WordRAM.Realization.While
Expand Down
25 changes: 25 additions & 0 deletions Complexity/Computability/WordRAM/Randomized/Law.lean
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ with `f` (`Cslib.WordRAM.ExecRandLaw.program`).
`Cslib.WordRAM.ExecRandLaw.loop_iter`: composition rules.
* `Cslib.WordRAM.ExecRandLaw.rename`: renaming registers.
* `Cslib.WordRAM.ExecRandLaw.execRandWithin`: forgetting the law.
* `Cslib.WordRAM.ExecRandLaw.map`, `Cslib.WordRAM.ExecRandLaw.withBounded`,
`Cslib.WordRAM.ExecRandLaw.withSupport`: mapping the observation, and the boundedness and the
support of every final observation.
* `Cslib.WordRAM.ExecRandLaw.program`: the compiled program halts within the bound, respects the
call budget and the postcondition, and has the law `μ`.
-/
Expand Down Expand Up @@ -83,6 +86,28 @@ theorem congr_law {μ' : PMF α} (h : ExecRandLaw w c x P T R f μ) (hμ : μ =
ExecRandLaw w c x P T R f μ' :=
hμ ▸ h

/-- Post-composing the observation with `g` maps the law by `g`. -/
theorem map (h : ExecRandLaw w c x P T R f μ) (g : α → β) :
ExecRandLaw w c x P T R (fun y => g (f y)) (μ.map g) := by
obtain ⟨m, hm, hq, hsup, hlaw⟩ := h
refine ⟨m, hm, hq, hsup, ?_⟩
rw [← hlaw, ProbComp.eval_map, ProbComp.eval_map, PMF.map_comp]
rfl

/-- Strengthening the postcondition with word-boundedness, from bounded initial data. -/
theorem withBounded (h : ExecRandLaw w c x P T R f μ) (hx : x.Bounded w) :
ExecRandLaw w c x (fun y => P y ∧ y.Bounded w) T R f μ := by
obtain ⟨m, hm, hq, hsup, hlaw⟩ := h
exact ⟨m, hm, hq, fun z hz => ⟨⟨(hsup z hz).1, hm.bounded hx hz⟩, (hsup z hz).2⟩, hlaw⟩

/-- Strengthening the postcondition: every final observation lies in the support of the law. -/
theorem withSupport (h : ExecRandLaw w c x P T R f μ) :
ExecRandLaw w c x (fun y => P y ∧ f y ∈ μ.support) T R f μ := by
obtain ⟨m, hm, hq, hsup, hlaw⟩ := h
refine ⟨m, hm, hq, fun z hz => ⟨⟨(hsup z hz).1, ?_⟩, (hsup z hz).2⟩, hlaw⟩
rw [← hlaw, ProbComp.eval_map, PMF.support_map, ProbComp.support_eval]
exact ⟨z, hz, rfl⟩

/-- Strengthening the postcondition with a register that `c` never writes. -/
theorem withPreserves {i : Fin r} (h : ExecRandLaw w c x P T R f μ) (hi : c.Preserves i) :
ExecRandLaw w c x (fun y => P y ∧ y.regs i = x.regs i) T R f μ := by
Expand Down
12 changes: 10 additions & 2 deletions Complexity/Computability/WordRAM/Realization/Bind.lean
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Its source registers append the first computation's answer slots to the original
Two disjoint static scratch banks preserve that environment without client-written intermediate
assertions. The continuation's bank already contains the final output slots, so no copy is needed.

## Main definitions

* `bindLeft`, `bindRight`: the two scratch banks inside a sequential composition's bank.

## Main results

* `Realizes.bind`: sequential realization with additive memory and local-work charges.
Expand All @@ -29,10 +33,14 @@ namespace Cslib.WordRAM.Realization

open Cslib.DataStructure

private def bindLeft {m n₂ l n₁ : ℕ} (i : Fin (m + n₂ + 1)) :
/-- The continuation's scratch bank inside a sequential composition's bank: its first slots, so
its result slots are the composition's. -/
def bindLeft {m n₂ l n₁ : ℕ} (i : Fin (m + n₂ + 1)) :
Fin (m + (n₂ + l + n₁ + 1) + 1) := ⟨i.val, by omega⟩

private def bindRight {m n₂ l n₁ : ℕ} (i : Fin (l + n₁ + 1)) :
/-- The first computation's scratch bank inside a sequential composition's bank, after the
continuation's. -/
def bindRight {m n₂ l n₁ : ℕ} (i : Fin (l + n₁ + 1)) :
Fin (m + (n₂ + l + n₁ + 1) + 1) := ⟨m + n₂ + 1 + i.val, by omega⟩

namespace Realizes
Expand Down
5 changes: 4 additions & 1 deletion Complexity/Computability/WordRAM/Realization/Branch.lean
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The two-instruction allowance includes the jump on the negative path.

## Main results

* `test_rename`: a renamed native condition tests the words in its source registers.
* `Realizes.branch`: compose two realizations using an actual native conditional.
-/

Expand All @@ -40,7 +41,9 @@ instance (c : Cond k) (v : Fin k → ℕ) : Decidable (test c v) := by
unfold test
infer_instance

private theorem test_rename {r : ℕ} (c : Cond k) (src : Fin k → Fin r)
/-- A renamed condition holds of native data exactly when it holds of the words in its source
registers. -/
theorem test_rename {r : ℕ} (c : Cond k) (src : Fin k → Fin r)
(x : Data r) (v : Fin k → ℕ) (h : x.regs ∘ src = v) :
(c.rename src).Holds x ↔ test c v := by
cases c <;> simp only [Cond.rename, Cond.Holds, test] <;>
Expand Down
25 changes: 18 additions & 7 deletions Complexity/Computability/WordRAM/Realization/Loop.lean
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ uses one fixed body emitter and static registers for the mutable state and count

* `iterate`: bounded iteration in the existing memory-client monad.
* `iterationWork`, `iterationSafe`: local work and domains along the actual semantic states.
* `loopEmit`, `loopBody`: the native loop with a fixed body emitter, and one native iteration,
over the register bank `stateSlot`, `counterSlot`, `zeroSlot`, `oneSlot`, `bodySlot`.

## Main results

Expand Down Expand Up @@ -192,17 +194,24 @@ theorem iterationSum_eq (body : δ × σ → Memory.Prog σ)
dsimp only [iterationStep] at *
omega

private def stateSlot {l n : ℕ} (i : Fin l) : Fin (l + (l + n + 3) + 1) :=
/-- The loop's state words, which are also its result slots. -/
def stateSlot {l n : ℕ} (i : Fin l) : Fin (l + (l + n + 3) + 1) :=
⟨i.val, by omega⟩

private def counterSlot (l n : ℕ) : Fin (l + (l + n + 3) + 1) := ⟨l, by omega⟩
private def zeroSlot (l n : ℕ) : Fin (l + (l + n + 3) + 1) := ⟨l + 1, by omega⟩
private def oneSlot (l n : ℕ) : Fin (l + (l + n + 3) + 1) := ⟨l + 2, by omega⟩
/-- The loop's countdown register. -/
def counterSlot (l n : ℕ) : Fin (l + (l + n + 3) + 1) := ⟨l, by omega⟩
/-- A register holding zero, for the loop test. -/
def zeroSlot (l n : ℕ) : Fin (l + (l + n + 3) + 1) := ⟨l + 1, by omega⟩
/-- A register holding one, for the countdown. -/
def oneSlot (l n : ℕ) : Fin (l + (l + n + 3) + 1) := ⟨l + 2, by omega⟩

private def bodySlot {l n : ℕ} (i : Fin (l + n + 1)) : Fin (l + (l + n + 3) + 1) :=
/-- The body's scratch bank inside the loop's bank. -/
def bodySlot {l n : ℕ} (i : Fin (l + n + 1)) : Fin (l + (l + n + 3) + 1) :=
⟨l + 3 + i.val, by omega⟩

private def loopBody {n : ℕ} (emit : ∀ {r : ℕ}, Fin r → (Fin (k + l) → Fin r) →
/-- One native iteration: run the body on the environment and state words, copy its result into
the state words and count down. -/
def loopBody {n : ℕ} (emit : ∀ {r : ℕ}, Fin r → (Fin (k + l) → Fin r) →
(Fin (l + n + 1) → Fin r) → Code .exact r)
(frontier : Fin r) (src : Fin (k + l + 1) → Fin r)
(tmp : Fin (l + (l + n + 3) + 1) → Fin r) : Code .exact r :=
Expand All @@ -214,7 +223,9 @@ private def loopBody {n : ℕ} (emit : ∀ {r : ℕ}, Fin r → (Fin (k + l) →
(.op (.exactBin .sub (tmp (counterSlot l n))
(tmp (counterSlot l n)) (tmp (oneSlot l n))))

private def loopEmit {n : ℕ} (emit : ∀ {r : ℕ}, Fin r → (Fin (k + l) → Fin r) →
/-- The native loop: install the state words and the counter, then iterate `loopBody` while the
counter is positive. -/
def loopEmit {n : ℕ} (emit : ∀ {r : ℕ}, Fin r → (Fin (k + l) → Fin r) →
(Fin (l + n + 1) → Fin r) → Code .exact r)
(frontier : Fin r) (src : Fin (k + l + 1) → Fin r)
(tmp : Fin (l + (l + n + 3) + 1) → Fin r) : Code .exact r :=
Expand Down
Loading
Loading