Documentation

CslibFrontier.Algorithms.ExactTriangle.CountPrime.Extraction

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.

def Cslib.Algorithms.ExactTriangle.CountPrime.pairCoefficient {n : ℕ} (p k : ℕ) (wAB wBC wAC : Fin n → Fin n → ℤ) (a b : Fin n) :

The unsigned value extracted from one actual original-coordinate product coefficient.

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.

theorem Cslib.Algorithms.ExactTriangle.CountPrime.pairCoefficient_le {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 ≤ n

Each selected coefficient counts at most the original side many middle vertices.

theorem Cslib.Algorithms.ExactTriangle.CountPrime.sum_pairCoefficient {n p k : ℕ} (hp : p ≠ 0) (hn : n ≤ 2 ^ k) (wAB wBC wAC : Fin n → Fin n → ℤ) :
∑ a : Fin n, ∑ b : Fin n, pairCoefficient p k wAB wBC wAC a b = countZeroMod wAB wBC wAC p

All selected original-coordinate coefficients sum to the existing modular triangle count.

def Cslib.Algorithms.ExactTriangle.CountPrime.rowMajorCoefficient {n : ℕ} (p k : ℕ) (wAB wBC wAC : Fin n → Fin n → ℤ) (i : ℕ) :

The selected counts in the exact original row-major order traversed by native code. Out-of-range entries are zero, so empty input requires no arbitrary coordinate witness.

theorem Cslib.Algorithms.ExactTriangle.CountPrime.rowMajorCoefficient_le {n p k i : ℕ} (hp : p ≠ 0) (hn : n ≤ 2 ^ k) (wAB wBC wAC : Fin n → Fin n → ℤ) :
rowMajorCoefficient p k wAB wBC wAC i ≤ n

The real row-major coefficient bound supplies the native prefix-accumulator admission.

theorem Cslib.Algorithms.ExactTriangle.CountPrime.sum_rowMajorCoefficient {n p k : ℕ} (hp : p ≠ 0) (hn : n ≤ 2 ^ k) (wAB wBC wAC : Fin n → Fin n → ℤ) :
∑ i ∈ Finset.range (n * n), rowMajorCoefficient p k wAB wBC wAC i = countZeroMod wAB wBC wAC p

Summation in the actual native scan order preserves the existing modular count.