Documentation

CslibFrontier.Algorithms.WordRAM.ThreeSum.Memory

Memory layout of the Convolution-3SUM graph builder #

The three matrices occupy disjoint row-major blocks following the input. This directly adapts the memory invariant of Anthropic's ConvFill.Args.filled at formal-math@16a5ce4. Values use the native signed encoding; addresses are natural numbers.

Main definitions #

Main results #

References #

Input length, matrix side and instance number, input base and three matrix bases, input values, and the filler. The bounds and disjointness assumptions belong to the execution theorem.

  • N : ℕ

    Input length.

  • t : ℕ

    Side length of each matrix.

  • s : ℕ

    Instance number.

  • base : ℕ

    Input base address.

  • ab : ℕ

    AB matrix base address.

  • bc : ℕ

    BC matrix base address.

  • ac : ℕ

    AC matrix base address.

  • values : ℕ → ℤ

    Mathematical input values.

  • filler : ℤ

    Invalid-index filler.

The encoded AB weight in row-major cell q.

The encoded BC weight; a negative index is rejected before reading the input.

The encoded AC weight; invalid entries retain the positive filler.

The memory after writing the first q cells of all three matrices.

@[simp]

A zero-length prefix leaves all memory unchanged.

theorem Cslib.Algorithms.WordRAM.ThreeSum.Fill.Args.filled_ab (A : Args) (mem : ℕ → ℕ) (q : ℕ) {p : ℕ} (hp : p < q) :
A.filled mem q (A.ab + p) = A.valueAB p

Reading cell p < q of the AB prefix returns A.valueAB p.

theorem Cslib.Algorithms.WordRAM.ThreeSum.Fill.Args.filled_bc (A : Args) (mem : ℕ → ℕ) (q : ℕ) {p : ℕ} (hb : A.ab + q ≤ A.bc) (hp : p < q) :
A.filled mem q (A.bc + p) = A.valueBC p

Reading cell p < q of the BC prefix returns A.valueBC p.

theorem Cslib.Algorithms.WordRAM.ThreeSum.Fill.Args.filled_ac (A : Args) (mem : ℕ → ℕ) (q : ℕ) {p : ℕ} (hb : A.ab + q ≤ A.bc) (hc : A.bc + q ≤ A.ac) (hp : p < q) :
A.filled mem q (A.ac + p) = A.valueAC p

Reading cell p < q of the AC prefix returns A.valueAC p.

theorem Cslib.Algorithms.WordRAM.ThreeSum.Fill.Args.filled_succ (A : Args) (mem : ℕ → ℕ) {q : ℕ} (hbc : A.ab + A.t * A.t ≤ A.bc) (hac : A.bc + A.t * A.t ≤ A.ac) (hq : q < A.t * A.t) :
A.filled mem (q + 1) = Function.update (Function.update (Function.update (A.filled mem q) (A.ab + q) (A.valueAB q)) (A.bc + q) (A.valueBC q)) (A.ac + q) (A.valueAC q)

One round writes one cell of each matrix, in AB, BC, AC order.

theorem Cslib.Algorithms.WordRAM.ThreeSum.Fill.Args.outside_filled (A : Args) (mem : ℕ → ℕ) (q a : ℕ) (hab : ¬(A.ab ≤ a ∧ a < A.ab + q)) (hbc : ¬(A.bc ≤ a ∧ a < A.bc + q)) (hac : ¬(A.ac ≤ a ∧ a < A.ac + q)) :
A.filled mem q a = mem a

Cells outside the three written prefixes retain their old contents.

theorem Cslib.Algorithms.WordRAM.ThreeSum.Fill.Args.input_filled (A : Args) (mem : ℕ → ℕ) (q : ℕ) (hinput : A.base + A.N ≤ A.ab) (hbc : A.ab ≤ A.bc) (hac : A.bc ≤ A.ac) {i : ℕ} (hi : i < A.N) :
A.filled mem q (A.base + i) = mem (A.base + i)

Disjoint matrix prefixes preserve all input cells.

theorem Cslib.Algorithms.WordRAM.ThreeSum.Fill.Args.matrices_filled (A : Args) (mem : ℕ → ℕ) (hbc : A.ab + A.t * A.t ≤ A.bc) (hac : A.bc + A.t * A.t ≤ A.ac) (a b c : Fin A.t) :
A.filled mem (A.t * A.t) (A.ab + ↑a * A.t + ↑b) = WordRAM.Signed.encode (ThreeSum.weightAB A.N A.values A.filler a b) ∧ A.filled mem (A.t * A.t) (A.bc + ↑b * A.t + ↑c) = WordRAM.Signed.encode (ThreeSum.weightBC A.N A.s A.values A.filler b c) ∧ A.filled mem (A.t * A.t) (A.ac + ↑a * A.t + ↑c) = WordRAM.Signed.encode (ThreeSum.weightAC A.N A.s A.values A.filler a c)

The fully written blocks contain the three matrices of the mathematical reduction.