# Example for the coefficient triple (1,1,2) at p=5; vary a and p.
import numberdb.sage as numberdb
from sage.rings.integer_ring import ZZ
from sage.rings.finite_rings.finite_field_constructor import GF
from sage.rings.number_field.number_field import CyclotomicField
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
a, p = (1, 1, 2), ZZ(5)
assert p.is_prime() and p > 2 and (a[0]*a[1]*a[2]) % p
r = 1 if p % 4 == 1 else 2
F, K = GF(p**r, 'u'), CyclotomicField(4)
i, g = K.gen(), F.multiplicative_generator()
chi, z = {F(0): K(0)}, F(1)
for e in range(int(p**r-1)):
chi[z] = i**(e % 4)
z *= g
J = chi[F(-1)]**3 * sum(chi[x]*chi[1-x] for x in F) * sum(chi[x]**2*chi[1-x] for x in F)
beta = J / chi[F(a[0]*a[1]*a[2])]
R = PolynomialRing(ZZ, 'T')
P = R([1, ZZ(-beta-beta.conjugate()), ZZ(beta*beta.conjugate())]) if r == 1 else R([1, 0, -ZZ(beta)])
print(P)Exact binary Jacobi sums in $\mathbb Q(i)$ assemble the four-character zero-sum normalization and its coefficient twist over $\mathbb F_p$ or $\mathbb F_{p^2}$. Each coefficient is coerced exactly into $\mathbb Z$; no numerical reconstruction or rounding is used.
All 612 polynomials agree coefficient by coefficient with a separately implemented Gaussian-prime and modular quartic-residue-symbol formula using integer arithmetic. Both conjugate Gaussian-prime choices agree. Direct zero-sum calculations over fields of orders 5, 9, 13 and 49 check the binary-sum reduction. The known factors $1+6T+25T^2$ for $(1,1,1)$ and $1-8T+25T^2$ for $(1,1,2)$ at $p=5$ pass, as do direct projective point-count controls 0, 12 and 64 for $(1,1,1)$, $(1,1,-1)$ and $(1,1,2)$ over $\mathbb F_5$. The point counts test the surface convention, not the isolated transcendental factor by themselves. Altered traces, a wrong Tate scale, determinant reversal, the inert sign error and omitted nontrivial coefficient twists are rejected. Native exact types, constant terms, degree, signed reciprocal symmetry and weight-two coefficient bounds are checked. The methods share the source-defined summand and conventions; their arithmetic implementations differ. Executable checks and actual results are attached.