Documentation

CslibFrontier.Algorithms.WordRAM.MatrixMultiplication.Strassen.Progress

Actual partial Strassen accumulations #

The native return stage updates at most two quarters. During those real coefficient loops, each output quarter contains either its previous partial sum or its next partial sum. The mask below is a proof invariant, not data supplied to the program. Both alternatives have the same four-contribution bound, so each actual signed addition admits its operands without assuming cancellation or a bound on a future machine result.

def Cslib.Algorithms.WordRAM.Strassen.progressValue (p k : ℕ) (phase : Fin 7) (done : Fin 4 → Bool) (u v : ℕ → ℤ) (s : Fin 4) (r : ℕ) :

A quarter has either received the current child or retains its previous partial sum.

theorem Cslib.Algorithms.WordRAM.Strassen.progressValue_eq_next (p k : ℕ) (phase : Fin 7) (done : Fin 4 → Bool) (u v : ℕ → ℤ) (s : Fin 4) (j : ℕ) (hzero : done s = false → MatrixMultiplication.Strassen.contribution phase s = 0) :
progressValue p k phase done u v s j = MatrixMultiplication.Strassen.partialValue p k (↑phase + 1) u v s j

Quarters with zero contribution need no native write to reach the next partial sum.

theorem Cslib.Algorithms.WordRAM.Strassen.progressValue_natAbs_le {p k A B j : ℕ} (phase : Fin 7) (done : Fin 4 → Bool) (u v : ℕ → ℤ) (s : Fin 4) (hu : ∀ i < 4 ^ (k + 1) * p, (u i).natAbs ≤ A) (hv : ∀ i < 4 ^ (k + 1) * p, (v i).natAbs ≤ B) (hj : j < 4 ^ k * p) :
(progressValue p k phase done u v s j).natAbs ≤ 4 * (p * (2 * A * (2 * B)) * 16 ^ k)

Both sides of the intra-stage invariant inherit the proved four-contribution bound.

theorem Cslib.Algorithms.WordRAM.Strassen.exec_accumulate_progress {w p k A B a b out scratch frames frame : ℕ} (phase : Fin 7) (done : Fin 4 → Bool) (t : Fin 4) (subtract : Bool) (x : WordRAM.Data 64) (u v : ℕ → ℤ) (hx : NodeHeader p (k + 1) a b out scratch frames frame x) (hc : ChildBuffers p k scratch x) (hl : NodeLayout p (k + 1) a b out scratch frames frame) (hu : ∀ i < 4 ^ (k + 1) * p, (u i).natAbs ≤ A) (hv : ∀ i < 4 ^ (k + 1) * p, (v i).natAbs ≤ B) (hnot : done t = false) (hsign : MatrixMultiplication.Strassen.contribution phase t = if subtract = true then -1 else 1) (hout : ∀ (s : Fin 4), ∀ j < 4 ^ k * p, x.mem (out + ↑s * (4 ^ k * p) + j) = WordRAM.Signed.encode (progressValue p k phase done u v s j)) (hprod : ∀ j < 4 ^ k * p, x.mem (scratch + 2 * (4 ^ k * p) + j) = WordRAM.Signed.encode (MatrixMultiplication.Strassen.childProduct p k u v phase j)) (hmag : GenericRAM.Signed.Fits w ↑(magnitudeBound p A B (k + 1))) (haddr : WordRAM.Fits (w + 2) (addressBound frames frame (k + 1))) :
∃ (y : WordRAM.Data 64), WordRAM.ExecWithin (w + 2) (accumulate (↑t) subtract) x y (26 * (4 ^ k * p) + 10) ∧ NodeHeader p (k + 1) a b out scratch frames frame y ∧ ChildBuffers p k scratch y ∧ (∀ (s : Fin 4), ∀ j < 4 ^ k * p, y.mem (out + ↑s * (4 ^ k * p) + j) = WordRAM.Signed.encode (progressValue p k phase (Function.update done t true) u v s j)) ∧ (∀ j < 4 ^ k * p, y.mem (scratch + 2 * (4 ^ k * p) + j) = WordRAM.Signed.encode (MatrixMultiplication.Strassen.childProduct p k u v phase j)) ∧ ∀ (d : ℕ), d < out + ↑t * (4 ^ k * p) ∨ out + ↑t * (4 ^ k * p) + 4 ^ k * p ≤ d → y.mem d = x.mem d

One actual returned-child update advances exactly one not-yet-updated output quarter. The child product and complete high-bank header survive the real in-place loop.