"""Compare the binary Euler formulas and all four coefficient transforms with Gleason polynomials. Run with: uv run --with python-flint==0.9.0 verify_binary.py All polynomial comparisons take place over Q or Q(i). """ from math import comb, factorial, prod from flint import fmpq, fmpq_mpoly_ctx, fmpq_poly from verify import zeta_polynomial def exceptional_factor(nu, m, x): """H_nu(x), written in the centered variable w.""" w = x + (m + 2 * nu) * fmpq(1, 2) if nu == 0: return 1 if nu == 1: return 16*w**2 - 3*m**2 - 13*m - 14 if nu == 2: return (256*w**4 - (96*m**2 + 672*m + 1216)*w**2 + 9*m**4 + 114*m**3 + 531*m**2 + 1074*m + 792) raise ValueError("unexpected Type II residue") def check_exceptional_factors(): ctx = fmpq_mpoly_ctx.get(["m", "x"]) m, x = ctx.gens() for nu in (1, 2): coefficients = (fmpq_poly([1, 14, 1])**nu).coeffs() expression = sum( b * prod(x + k for k in range(ell)) * prod(x + m + 1 + ell + k for k in range(2*nu - ell)) for ell, b in enumerate(coefficients) ) assert expression == exceptional_factor(nu, m, x) linear = 96*m**2 + 672*m + 1216 constant = 9*m**4 + 114*m**3 + 531*m**2 + 1074*m + 792 assert linear**2 - 4*256*constant == 2048*(6*m**3 + 69*m**2 + 261*m + 326) # Exact signs at the three test points in the shift-coordinate proof. vertex = 3*m**2 + 21*m + 38 endpoint = 4*(m+4)**2 assert endpoint - vertex == m**2 + 11*m + 26 assert constant - vertex**2 == -2*(6*m**3 + 69*m**2 + 261*m + 326) assert endpoint**2 - 2*vertex*endpoint + constant == prod(m+j for j in range(1, 5)) assert 4*(m+2)**2 - (3*m**2 + 13*m + 14) == (m+1)*(m+2) def euler_numerator(m, nu, is_type_ii, degree): """Return (1-u)^p sum c(j) u^j for the factorial moment polynomial c.""" p = m + degree + 1 last_shift = 2*m + degree + 1 if is_type_ii: holes = {m + 1 + 4*r for r in range(m + 2*nu + 1)} else: holes = {1 + 4*r for r in range(m + 1)} shifts = [h for h in range(1, last_shift + 1) if h not in holes] samples = [] for j in range(p): value = prod(j + h for h in shifts) if is_type_ii: value *= exceptional_factor(nu, m, fmpq(j + m + 1, 4)) samples.append(value) # c has degree p-1, so finite differences of order p vanish. assert len(shifts) + (2*nu if is_type_ii else 0) == p - 1 return [ sum((-1)**h * comb(p, h) * samples[j-h] for h in range(j+1)) for j in range(p) ] def compare_edge_identity(kind, k, nu): is_type_ii = kind == "II" length = 24*k + 8*nu if is_type_ii else 8*k m = 4*k - 1 if is_type_ii else 2*k - 1 q = zeta_polynomial(kind, length) if is_type_ii: q *= fmpq_poly([1, -2, 2]) degree = q.degree() assert degree == (4*m + 8*nu if is_type_ii else 2*m) p = m + degree + 1 coefficients = euler_numerator(m, nu, is_type_ii, degree) ctx = fmpq_mpoly_ctx.get(["i", "u"], ordering="lex") i, u = ctx.gens() relation = i**2 + 1 # Use u=1/W before rotating to the real axis. Then # T=((1+i)/2)(1-u)/(1-iu), so both sides are defined over Q(i). denominator = 1 - i*u numerator = fmpq(1, 2) * (1+i) * (1-u) lhs = ctx.constant(q[degree]) power = ctx.constant(1) for j in range(degree-1, -1, -1): power = power * denominator % relation lhs = (numerator * lhs + q[j] * power) % relation # The two edge integrals have generating series at iu and u. rotation = [1, i, -1, -i] at_u = ctx.from_dict({(0, j): a for j, a in enumerate(coefficients)}) at_iu = sum(a * rotation[j % 4] * u**j for j, a in enumerate(coefficients)) phase = rotation[(m+1) % 4] if is_type_ii else i rhs = (phase * (1-u)**p * at_iu - (denominator**p % relation) * at_u) % relation # The ray orientation and normalization contribute an overall scalar. # u=-1 corresponds to T=1, where the zeta polynomial is nonzero. lhs_value = lhs.subs({"u": -1}) rhs_value = rhs.subs({"u": -1}) assert lhs_value and rhs_value if (rhs_value*lhs - lhs_value*rhs) % relation: raise ArithmeticError(f"Euler identity failed for {kind}, n={length}") def check_coefficient_transforms(): """Compare Section 3 and Okuda's reduction with the defining zeta identity.""" w = fmpq_poly([0, 1]) x = 1 + w u = x * (1 + 2*w) # Period, first generator degree, slope of m+1, A(1+w,w)/w, phi, and E. families = { "I": (8, 2, 2, u, x**2 + w**2, 1), "II": (24, 8, 4, u * (1 + 2*w + 2*w**2), x**8 + 14*x**4*w**4 + w**8, 1 - 2*w + 2*w**2), "III": (12, 4, 3, 1 + 3*w + 3*w**2, x**4 + 8*x*w**3, 1 + 3*w**2), "IV": (6, 2, 2, 1 + 2*w, x**2 + 3*w**2, 1 + 2*w), } count = 0 for kind, (period, step, slope, base, first, auxiliary) in families.items(): for k in range(1, 7): m = slope*k - 1 for nu in range(period // step): length = period*k + step*nu f = base**m * first**nu degree = f.degree() transformed = fmpq_poly([ factorial(m+j) * factorial(m+degree-j) * f[j] for j in range(degree+1) ]) direct = auxiliary * zeta_polynomial(kind, length) assert direct[0]*transformed == transformed[0]*direct, (kind, length) count += 1 for k in range(1, 7): assert zeta_polynomial("III", 12*k-4) == (1 - 3*w + 3*w**2) * zeta_polynomial("III", 12*k) print(f"Verified {count} coefficient transforms and 6 normalized Okuda identities.") def main(): check_coefficient_transforms() check_exceptional_factors() count = 0 for k in range(1, 7): compare_edge_identity("I", k, 0) for nu in (0, 1, 2): compare_edge_identity("II", k, nu) count += 4 print("Verified both exceptional multiplier identities and the quartic discriminant.") print(f"Verified {count} full polynomial identities over Q(i), for k=1 through 6.") if __name__ == "__main__": main()