Documentation

CslibFrontier.Algorithms.WordRAM.MatrixMultiplication.Strassen.Receive

Native returned-child partial sums #

A returned Strassen child contributes to one or two real output quarters. These internal lemmas compose the actual in-place coefficient loops, derive the next partial sum and preserve the returned child product. Their footprints protect original inputs and frames. Every coefficient operation is charged; zero-contribution quarters require no write.

The literal accumulation prefix of each actual return stage, before its next push/pop. The stage composition theorem accounts for the source's right-associated sequencing.

Five children require two accumulations; the last two require one each.

The actual continuation after a returned child's contributions: next child or parent pop.

theorem Cslib.Algorithms.WordRAM.Strassen.exec_stage_return {w U T : ℕ} (phase : Fin 7) {x y z : WordRAM.Data 64} (hupdates : WordRAM.ExecWithin w (returnedUpdates phase) x y U) (hafter : WordRAM.ExecWithin w (afterReturn phase) y z T) :
WordRAM.ExecWithin w (stage ⟨↑phase + 1, ⋯⟩) x z (U + T)

Reassemble the exact right-associated source stage from its real returned-product updates and next push/pop. Sequencing changes no charged instruction count.

theorem Cslib.Algorithms.WordRAM.Strassen.exec_receive_one {w p k A B a b out scratch frames frame : ℕ} (phase : Fin 7) (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) (hsign : MatrixMultiplication.Strassen.contribution phase t = if subtract = true then -1 else 1) (hzero : ∀ (s : Fin 4), s ≠ t → MatrixMultiplication.Strassen.contribution phase s = 0) (hout : ∀ (s : Fin 4), ∀ j < 4 ^ k * p, x.mem (out + ↑s * (4 ^ k * p) + j) = WordRAM.Signed.encode (MatrixMultiplication.Strassen.partialValue p k (↑phase) 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 (MatrixMultiplication.Strassen.partialValue p k (↑phase + 1) 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 ∨ out + 4 ^ (k + 1) * p ≤ d → y.mem d = x.mem d

A child with one nonzero output contribution needs exactly one native coefficient loop.

theorem Cslib.Algorithms.WordRAM.Strassen.exec_receive_two {w p k A B a b out scratch frames frame : ℕ} (phase : Fin 7) (t₁ t₂ : Fin 4) (subtract₁ 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) (hne : t₂ ≠ t₁) (hsign₁ : MatrixMultiplication.Strassen.contribution phase t₁ = if subtract₁ = true then -1 else 1) (hsign₂ : MatrixMultiplication.Strassen.contribution phase t₂ = if subtract₂ = true then -1 else 1) (hzero : ∀ (s : Fin 4), s ≠ t₁ → s ≠ t₂ → MatrixMultiplication.Strassen.contribution phase s = 0) (hout : ∀ (s : Fin 4), ∀ j < 4 ^ k * p, x.mem (out + ↑s * (4 ^ k * p) + j) = WordRAM.Signed.encode (MatrixMultiplication.Strassen.partialValue p k (↑phase) 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₁).seq (accumulate (↑t₂) subtract₂)) x y (52 * (4 ^ k * p) + 20) ∧ 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 (MatrixMultiplication.Strassen.partialValue p k (↑phase + 1) 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 ∨ out + 4 ^ (k + 1) * p ≤ d → y.mem d = x.mem d

A child with two distinct nonzero output contributions executes both actual loops. The second loop uses the first loop's real final state, product and register frame.

theorem Cslib.Algorithms.WordRAM.Strassen.exec_returnedUpdates {w p k A B a b out scratch frames frame : ℕ} (phase : Fin 7) (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) (hout : ∀ (s : Fin 4), ∀ j < 4 ^ k * p, x.mem (out + ↑s * (4 ^ k * p) + j) = WordRAM.Signed.encode (MatrixMultiplication.Strassen.partialValue p k (↑phase) 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) (returnedUpdates phase) x y (receiveBudget phase (4 ^ k * p)) ∧ 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 (MatrixMultiplication.Strassen.partialValue p k (↑phase + 1) 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 ∨ out + 4 ^ (k + 1) * p ≤ d → y.mem d = x.mem d

All seven literal return prefixes advance the existing finite partial-sum invariant. The exact twelve coefficient loops, rather than fourteen uniform worst cases, are charged.