Complete native padded monomial matrix construction #
The actual cell loop visits row-major coordinates, derives each distinct Morton block from the computed spread table, and writes all p coefficients. The loop invariant protects prior blocks using injectivity of the existing Morton projections. Original source/table words are protected below the destination, which may start dirty. Every padding store is charged.
theorem Cslib.Algorithms.WordRAM.ExactTriangle.CountPrime.exec_matrix {w n p k source destination table : ℕ} (src dst : Fin 128) (transpose : Bool) (x : WordRAM.Data 128) (hdstReg : dst ≠ Reg.residueSource) (hn : x.regs Reg.side = n) (hp : x.regs Reg.modulus = p) (hN : x.regs Reg.paddedSide = 2 ^ k) (harea : x.regs Reg.paddedCells = 4 ^ k) (hsrc : x.regs src = source) (hdst : x.regs dst = destination) (ht : x.regs Reg.spread = table) (h0 : x.regs Reg.zero = 0) (h1 : x.regs Reg.one = 1) (h2 : x.regs Reg.two = 2) (hsourceBefore : source + n * n ≤ destination) (htableBefore : table + 2 ^ k ≤ destination) (htable : ∀ j < 2 ^ k, x.mem (table + j) = Nat.Morton.spread j) (hw : WordRAM.Fits w (destination + 4 ^ k * p + table + 4 ^ k + 2 ^ k + source + n * n + p + 16)) :
∃ (y : WordRAM.Data 128),
WordRAM.ExecWithin w (matrix src dst transpose) x y ((7 * p + 24) * 4 ^ k + 5) ∧ (∀ j < 4 ^ k,
∀ r < p,
y.mem (destination + Nat.Morton.index (j / 2 ^ k) (j % 2 ^ k) * p + r) = if r = if j / 2 ^ k < n ∧ j % 2 ^ k < n then
x.mem (source + if transpose = true then j % 2 ^ k * n + j / 2 ^ k else j / 2 ^ k * n + j % 2 ^ k)
else p then
2
else 0) ∧ (∀ (d : ℕ), d < destination ∨ destination + 4 ^ k * p ≤ d → y.mem d = x.mem d) ∧ ∀ (r : Fin 128), ¬MatrixLocal r → r ≠ Reg.residueSource → r ≠ Reg.destination → y.regs r = x.regs r
Build every padded matrix cell using the actual loop and computed Morton table. The raw source is read only at admitted original coordinates, with actual BC transposition. The numerical source/table separation is derived from the counter's real layout in composition.