Range fill/copy routines, memory-readiness framing, and adjacency-matrix predicate #
This module certifies the low-level fillRange and copyRange Memory.Prog routines along with
their frame, admissibility (MemReady), cost, and functional specs, plus the MatrixLoaded
predicate linking encodeInput G k to linear memory.
Main definitions #
Cslib.Algorithms.WordRAM.OddCycleTransversal.fillRange,Cslib.Algorithms.WordRAM.OddCycleTransversal.copyRange: contiguous slice fill and copy.Cslib.Algorithms.WordRAM.OddCycleTransversal.MemReady: well-formed memory frontier invariant.Cslib.Algorithms.WordRAM.OddCycleTransversal.MatrixLoaded: adjacency-matrix memory invariant.
Main results #
Cslib.Algorithms.WordRAM.OddCycleTransversal.fillRange_realizes,Cslib.Algorithms.WordRAM.OddCycleTransversal.copyRange_realizes: exact-basis realization.Cslib.Algorithms.WordRAM.OddCycleTransversal.fillRange_spec,Cslib.Algorithms.WordRAM.OddCycleTransversal.copyRange_spec: functional specifications.Cslib.Algorithms.WordRAM.OddCycleTransversal.matrixLoaded_init: initial-memory invariant.
Client reduction and frame helpers for Memory.Prog #
theorem Cslib.Algorithms.WordRAM.OddCycleTransversal.preservesAt_iterate_fst {a : ℕ} {δ β : Type} {body : δ × ℕ × β → DataStructure.Memory.Prog (ℕ × β)} {d : δ} {m : ℕ} (b₀ : β) (hstep :
∀ i < m,
∀ (b : β),
WordRAM.Realization.PreservesAt a (body (d, i, b)) ∧ ∀ (s : (DataStructure.Memory.spec 0).State),
((DataStructure.Memory.spec 0).clientResult s (body (d, i, b))).1 = i + 1) :
Frame lemma along an indexed iteration preserving the first state coordinate.
Array fill and copy helpers #
theorem Cslib.Algorithms.WordRAM.OddCycleTransversal.fillRange_realizes :
WordRAM.Realization.Realizes WordRAM.Basis.exact fillRange WordRAM.Realization.WordEncoding.encode
WordRAM.Realization.WordEncoding.encode
(fun (w : ℕ) (d : (ℕ × ℕ) × ℕ) (x : DataStructure.Memory.State) =>
match d with
| ((base, snd), len) => WordRAM.Fits w (base + len))
fun (x : (ℕ × ℕ) × ℕ) (x_1 : DataStructure.Memory.State) => 0
Exact-basis realization certificate for fillRange.
theorem Cslib.Algorithms.WordRAM.OddCycleTransversal.copyRange_realizes :
WordRAM.Realization.Realizes WordRAM.Basis.exact copyRange WordRAM.Realization.WordEncoding.encode
WordRAM.Realization.WordEncoding.encode
(fun (w : ℕ) (d : (ℕ × ℕ) × ℕ) (x : DataStructure.Memory.State) =>
match d with
| ((src, dst), len) => WordRAM.Fits w (src + len) ∧ WordRAM.Fits w (dst + len))
fun (x : (ℕ × ℕ) × ℕ) (x_1 : DataStructure.Memory.State) => 0
Exact-basis realization certificate for copyRange.
Admissibility (ValidHistory) and memoryCost bounds #
@[reducible, inline]
abbrev Cslib.Algorithms.WordRAM.OddCycleTransversal.MemReady (w n : ℕ) (s : DataStructure.Memory.State) :
Well-formed memory state with allocated workspace octWorkspace n.
theorem Cslib.Algorithms.WordRAM.OddCycleTransversal.validHistory_bind_ready {α β : Type} {w n : ℕ} {s : DataStructure.Memory.State} (hs : MemReady w n s) {p : DataStructure.Memory.Prog α} {q : α → DataStructure.Memory.Prog β} (hp : (DataStructure.Memory.spec w).ValidHistory s ((DataStructure.Memory.spec w).clientHistory s p)) (hq :
∀ (x : α) (t : DataStructure.Memory.State),
MemReady w n t → (DataStructure.Memory.spec w).ValidHistory t ((DataStructure.Memory.spec w).clientHistory t (q x))) :
(DataStructure.Memory.spec w).ValidHistory s ((DataStructure.Memory.spec w).clientHistory s (p >>= q))
theorem Cslib.Algorithms.WordRAM.OddCycleTransversal.memReady_write {w n : ℕ} {s : DataStructure.Memory.State} (hs : MemReady w n s) (a v : ℕ) (hv : WordRAM.Fits w v) :
theorem Cslib.Algorithms.WordRAM.OddCycleTransversal.memoryCost_boundedWhile_le_of {δ σ : Type} (guard : δ → σ → Prop) [(d : δ) → (a : σ) → Decidable (guard d a)] (body : δ × σ → DataStructure.Memory.Prog σ) (c : ℕ) (d : δ) (hstep : ∀ (a : σ) (s : DataStructure.Memory.State), guard d a → WordRAM.Realization.memoryCost (body (d, a)) s ≤ c) (m : ℕ) (a : σ) (s : DataStructure.Memory.State) :
theorem Cslib.Algorithms.WordRAM.OddCycleTransversal.validHistory_fillRange {w n : ℕ} {d : (ℕ × ℕ) × ℕ} {s : DataStructure.Memory.State} (hs : MemReady w n s) (hend :
match d with
| ((base, snd), len) => base + len ≤ octWorkspace n) (hval :
match d, hend with
| ((fst, val), snd), hend => WordRAM.Fits w val) :
(DataStructure.Memory.spec w).ValidHistory s ((DataStructure.Memory.spec w).clientHistory s (fillRange d))
theorem Cslib.Algorithms.WordRAM.OddCycleTransversal.validHistory_copyRange {w n : ℕ} {d : (ℕ × ℕ) × ℕ} {s : DataStructure.Memory.State} (hs : MemReady w n s) (hsrc :
match d with
| ((src, snd), len) => src + len ≤ octWorkspace n) (hdst :
match d, hsrc with
| ((fst, dst), len), hsrc => dst + len ≤ octWorkspace n) :
(DataStructure.Memory.spec w).ValidHistory s ((DataStructure.Memory.spec w).clientHistory s (copyRange d))
theorem Cslib.Algorithms.WordRAM.OddCycleTransversal.memoryCost_fillRange_le (d : (ℕ × ℕ) × ℕ) (s : DataStructure.Memory.State) :
theorem Cslib.Algorithms.WordRAM.OddCycleTransversal.memoryCost_copyRange_le (d : (ℕ × ℕ) × ℕ) (s : DataStructure.Memory.State) :
theorem Cslib.Algorithms.WordRAM.OddCycleTransversal.fillRange_spec (base val len : ℕ) (s : DataStructure.Memory.State) :
theorem Cslib.Algorithms.WordRAM.OddCycleTransversal.copyRange_spec {srcB dstB len : ℕ} (hdisj : srcB + len ≤ dstB) (s : DataStructure.Memory.State) :
def Cslib.Algorithms.WordRAM.OddCycleTransversal.MatrixLoaded {n : ℕ} (G : SimpleGraph (Fin n)) [DecidableRel G.Adj] (s : DataStructure.Memory.State) :
Invariant asserting that row-major adjacency matrix of G resides at memory offset 3.
theorem Cslib.Algorithms.WordRAM.OddCycleTransversal.matrixLoaded_init {n : ℕ} (G : SimpleGraph (Fin n)) [DecidableRel G.Adj] (k : ℕ) :