Nonnegative selected coefficients for modular triangle counting #
These bridges justify the real counter's unsigned extraction and summation from the existing cyclic product specification. They do not assume a matrix multiplication or native execution.
theorem Cslib.Algorithms.ExactTriangle.CountPrime.pairCoefficient_cast {n p k : ℕ} (hp : p ≠ 0) (hn : n ≤ 2 ^ k) (wAB wBC wAC : Fin n → Fin n → ℤ) (a b : Fin n) :
↑(pairCoefficient p k wAB wBC wAC a b) = MatrixMultiplication.Strassen.multiply p k (pCoefficients p wAC) (qCoefficients p wBC)
(Nat.Morton.index ↑a ↑b * p + (-wAB a b % ↑p).toNat)
For p ≠ 0 and n ≤ 2 ^ k the selected product coefficient is nonnegative, so casting
pairCoefficient (its Int.natAbs) back to ℤ returns that coefficient.