# Verifier for "Wilson primes for an elliptic coordinate ring of class number one" # David Niedbala Giraudin (ORCID 0009-0009-1526-1178), with Claude (Anthropic). # Requires: python-flint. No arguments. Runtime: under one minute. # A = F_3[x,y]/(y^2 - x^3 + x + 1), deg x = 2, deg y = 3. Elements are pairs (a,b) = a(x) + b(x) y. import itertools, time from flint import nmod_poly p = 3 X = nmod_poly([0, 1], p); ONE = nmod_poly([1], p); ZERO = nmod_poly([], p) f = X**3 - X - 1 DMAX_EXACT = 9 # criterion vs definition (exact W_d in A), all primes of degree 2..DMAX_EXACT DMAX_LOCAL = 7 # second, independent computation (W_d modulo pi^2 by Hensel lifting) def polys(n): if n < 0: yield ZERO; return for c in itertools.product(range(p), repeat=n + 1): yield nmod_poly(list(c), p) def L(n): for a in polys(n // 2): for b in polys((n - 3) // 2 if n >= 3 else -1): yield (a, b) def deg(a, b): return max(2 * a.degree() if not a.is_zero() else -9, 2 * b.degree() + 3 if not b.is_zero() else -9) def norm(a, b): return a * a - b * b * f def mul(u, v): return (u[0] * v[0] + u[1] * v[1] * f, u[0] * v[1] + u[1] * v[0]) def coef(u, k): q, i = (u[0], k // 2) if k % 2 == 0 else (u[1], (k - 3) // 2) return int(q.coeffs()[i]) if (i >= 0 and q.degree() >= i) else 0 def powmod(b, e, m): r = ONE % m; b = b % m while e: if e & 1: r = (r * b) % m b = (b * b) % m; e >>= 1 return r def inv_mod(u, m): g, s, t = u.xgcd(m); assert g.degree() == 0 return (s * nmod_poly([pow(int(g.coeffs()[0]), p - 2, p)], p)) % m def irreducible(P): fac = P.factor()[1]; return len(fac) == 1 and fac[0][1] == 1 def primes(d): """one generator (leading coefficient 1) for each prime of degree d""" out = [] for a, b in L(d): if deg(a, b) != d or coef((a, b), d) != 1: continue N = norm(a, b) if b.is_zero(): k = a.degree() if irreducible(a) and powmod(f, (p**k - 1) // 2, a) == nmod_poly([p - 1], p): out.append((a, b)) elif irreducible(N): out.append((a, b)) return out def residues(d): """nonzero elements of V_d: degree <= d+1, no monomial of degree d""" for a, b in L(d + 1): if coef((a, b), d) == 0 and not (a.is_zero() and b.is_zero()): yield (a, b) def D(u): a, b = u # D x = -y, D y = -1 return (-(b.derivative()) * f - b, -(a.derivative())) def is_zero(u): return u[0].is_zero() and u[1].is_zero() def W_exact(d): lst = list(residues(d)) while len(lst) > 1: nxt = [mul(lst[i], lst[i + 1]) for i in range(0, len(lst) - 1, 2)] if len(lst) % 2: nxt.append(lst[-1]) lst = nxt return lst[0] def pi2_divides(Z, u): N = norm(*u); cb = (u[0], -u[1]); T = mul(Z, mul(cb, cb)); N2 = N * N return (T[0] % N2).is_zero() and (T[1] % N2).is_zero() def wilson_local(u, d): a, b = u if b.is_zero(): P2 = a * a; r = (ONE, ZERO); fm = f % P2 for v in residues(d): r = ((r[0] * v[0] + r[1] * v[1] * fm) % P2, (r[0] * v[1] + r[1] * v[0]) % P2) return ((r[0] + 1) % P2).is_zero() and r[1].is_zero() if a.is_zero(): r = (ONE, ZERO) for v in residues(d): r = ((r[0] * v[0]) % f, (r[0] * v[1] + r[1] * v[0]) % f) return ((r[0] + 1) % f).is_zero() and r[1].is_zero() P = norm(a, b); P = P * nmod_poly([pow(int(P.coeffs()[-1]), p - 2, p)], p); P2 = P * P s = (-(a % P) * inv_mod(b % P, P)) % P s = (s - ((s * s - f) % P2) * inv_mod((2 * s) % P2, P2)) % P2 r = ONE for v in residues(d): r = (r * ((v[0] + v[1] * s) % P2)) % P2 return ((r + 1) % P2).is_zero() def criterion(u, d): return is_zero(D(D(u))) and coef(u, d - 1) == 0 t0 = time.time(); ok = True; total = 0 print("degree primes Wilson criterion agrees", flush=True) for d in range(2, DMAX_EXACT + 1): Wd = W_exact(d); Z = (Wd[0] + 1, Wd[1]); pr = primes(d) w = [pi2_divides(Z, u) for u in pr]; c = [criterion(u, d) for u in pr] good = (w == c); ok &= good; total += len(pr) if d % 3 == 1: ok &= (sum(w) == 0) print(f"{d:6d} {len(pr):7d} {sum(w):7d} {good}", flush=True) if d <= DMAX_LOCAL: w2 = [wilson_local(u, d) for u in pr] ok &= (w2 == w) print(f" second computation (local, Hensel) agrees: {w2 == w}", flush=True) # base of the infinite family: pi = y^4 + y - 1, degree 12 u = (f * f - 1, ONE) base = irreducible(norm(*u)) and criterion(u, 12) and wilson_local(u, 12) ok &= base print("y^4 + y - 1 is a Wilson prime of degree 12 (definition and criterion):", base, flush=True) for k in (1, 2): s = 25**k; co = [0] * (4 * s + 1); co[0] = 2; co[s] = 1; co[4 * s] = 1 irr = irreducible(nmod_poly(co, p)); ok &= irr print(f"y^(4*{s}) + y^{s} - 1 irreducible over F_3: {irr}", flush=True) print(f"\n{total} primes tested in {time.time() - t0:.0f} s. VERDICT:", "ALL CHECKS PASSED" if ok else "FAILURE", flush=True) input("Press Enter to close...")