"""Exact finite certificate by literal compositions and interpolation. Python 3.9 or later, standard library only. For formal inputs the interpolated reciprocal sextic is the definition. For curve inputs its identification uses the known degree and symmetry. """ from fractions import Fraction as F from functools import lru_cache from math import isqrt if not __debug__: raise RuntimeError("Run this verifier without Python's -O or -OO options.") def margins(Q, a, b, c): d, e = b - 3*Q, c - 2*Q*a return (a*a*d*d - 4*d**3 - 4*a**3*e - 27*e*e + 18*a*d*e, 36*Q - a*a, b + Q, (b + 9*Q)**2 - 16*Q*a*a, 4*Q*(b + Q)**2 - (c + 2*Q*a)**2) @lru_cache(None) def compositions(m): if m == 0: return ((),) return tuple((a,) + K for a in range(1, m + 1) for K in compositions(m - a)) def coefficients(q, u, v, w, last): P = (1, u, v, w, q*v, q*q*u, q**3) def Z(t): return sum(P[i]*t**i for i in range(7))/((1-t)*(1-q*t)) V = [F(1), F(sum(P), q-1)] assert V[1] > 0 for j in range(2, last): V.append(q**(2*j)*Z(F(1, q**j))*V[-1]) weights = [] for m in range(last): row = [] for K in compositions(m): W = F(1) for a in K: W *= V[a] for a, b in zip(K, K[1:]): W /= 1-q**(a+b) row.append((K, W)) weights.append(row) def B(m, t): if m == 0: return F(1) return sum(W/(1-q**K[-1]*t) for K, W in weights[m]) for n in range(3, last + 1): m, Q = n-1, q**n sigma = sum(W for K, W in weights[m]) assert sigma > 0, (q, u, v, w, n, "constant term") xs, ys = [], [] for T in (F(-1), F(-2), F(-3)): value = sum(F(1, q**(2*k))*B(k, F(1, q**k)/T) *Z(q**k*T)*B(m-k, q**(k+1)*T) for k in range(n)) value *= (1-T)*(1-Q*T)/sigma x = 1/T + Q*T xs.append(x) ys.append(value/T**3 - x**3) x1, x2, x3 = xs y1, y2, y3 = ys s12, s23 = (y2-y1)/(x2-x1), (y3-y2)/(x3-x2) a = (s23-s12)/(x3-x1) d = s12 - a*(x1+x2) e = y1 - a*x1*x1 - d*x1 yield n, a, d+3*Q, e+2*Q*a def verify(): q = 2 count = 0 total = 0 for u in range(-isqrt(36*q), isqrt(36*q) + 1): for v in range(-q, 15*q + 1): for w in range(-isqrt(400*q**3), isqrt(400*q**3) + 1): if min(margins(q, u, v, w)) < 0: continue count += 1 for n, a, b, c in coefficients(q, u, v, w, 6): Q = q**n lower = (2*Q**3, 26*Q, F(4,5)*Q, 47*Q**2, 2*Q**3) assert all(x > y for x, y in zip( margins(Q,a,b,c), lower)), (u,v,w,n) total += 1 assert (count, total) == (215, 860) print(count, "ordinary inputs and", total, "strict sextics") if __name__ == "__main__": verify()