Documentation

CslibFrontier.Algorithms.WordRAM.ExactTriangle.CountPrime

Complete native cyclic-Strassen modular triangle counter #

One fixed 128-register standard WordRAM program counts the existing modular-zero triangles from raw (n,p) headers and three canonical signed matrices. It computes residues, the Morton table, padding and both cyclic-monomial matrices, executes the actual seven-product recursion with an explicit stack, then reads and sums the selected coefficients. Its raw count is register 70; caller arguments are registers 64 through 69. The callable variant takes runtime matrix/workspace pointers and preserves original arrays and outside memory.

Main results #

The n exponent is subcubic and the runtime p factor remains explicit. This is the concrete counter prerequisite for prime selection, not prime enumeration/argmin, an aggregate ExactTriangle solver or the ordinary 3SUM exponent 1.9992 endpoint.

References #

Selectively adapts the algorithm in Programs/Sec3/Theorem17/Hashing/{CountPrime,RingOps, Strassen,StrassenTime,ZOrder,Count}.lean and its finite specification at Anthropic formal-math revision 16a5ce41304fcdaea4e0be7c132e1c361dc26da5. Credit is retained in adapted source modules. Native implementation, frames, fits, execution and instruction constants are independently proved against existing standard WordRAM APIs; no Light semantics or assumed machine simulation is imported.

theorem Cslib.Algorithms.WordRAM.ExactTriangle.CountPrime.runs_input_subcubic {W n p A : ℕ} (values : List ℤ) (hlen : values.length = 3 * (n * n)) (hp : 0 < p) (hv : ∀ z ∈ values, z.natAbs ≤ A) (hW : admissionWidth n p A ≤ W) :
WordRAM.InputFits W (inputWords n p values) ∧ ∃ (y : WordRAM.Data 128) (t : ℕ), WordRAM.Runs W (entryProgram.program Reg.result) (WordRAM.State.init (inputWords n p values)) { pc := entryProgram.size, data := y } t ∧ WordRAM.Executes W (entryProgram.program Reg.result) (WordRAM.State.init (inputWords n p values)) (y.regs Reg.result) (t + 1) ∧ ↑(t + 1) ≤ 3704 * (↑p + 1) ^ 2 * (↑n + 1) ^ (281 / 100) ∧ y.regs Reg.result = ExactTriangle.countZeroMod (fun (α β : Fin n) => values.getD (↑α * n + ↑β) 0) (fun (α β : Fin n) => values.getD (n * n + ↑α * n + ↑β) 0) (fun (α β : Fin n) => values.getD (2 * (n * n) + ↑α * n + ↑β) 0) p ∧ WordRAM.Data.Bounded W y ∧ ∀ (d : ℕ), d < 3 + 3 * (n * n) ∨ memoryEnd n p (Nat.clog 2 n) (3 + 3 * (n * n)) ≤ d → y.mem d = (WordRAM.Data.init (inputWords n p values)).mem d

One actual initialized finite native program, exact modular count and charged execution within 3704*(p+1)^2*(n+1)^2.81 instructions: subcubic in n, with an explicit quadratic factor in the modulus p. The prefix and halting result belong to the same state. All setup, ring arithmetic, indexing, copying, recursion/control/return, scan and halt instructions are included. The modulus and original-weight bound determine admission; no intermediate certificate is input.