#!/usr/bin/env python3 """Exact supplemental checks for the single-chain theorem's formal calculations. These finite rational computations supplement, not replace, the general proof. The six formal powers are certified by a Vandermonde trace test without choosing algebraic eigenvectors. """ from pathlib import Path import importlib.util import sys import sympy as sp ROOT = Path(__file__).resolve().parents[1] candidate = ROOT / "notes/candidates/2026-10-06-single-chain/frozen/check_generic_example_audited.py" spec = importlib.util.spec_from_file_location("example_check", candidate) if spec is None or spec.loader is None: raise RuntimeError(f"Cannot import certificate: {candidate}") m = importlib.util.module_from_spec(spec) sys.modules[spec.name] = m spec.loader.exec_module(m) def require(test, message): if not bool(test): raise RuntimeError(message) def diag(a): return sp.diag(*a.diagonal()) basis = [1, m.x, m.x**2, m.y, m.x*m.y, m.x**2*m.y] a = sp.zeros(6) for i, amplitude in enumerate(basis): r, p, q = m.normal_form(m.q*amplitude) require(sp.expand(m.q*amplitude-r-m.lx(p)-m.ly(q)) == 0, "Polynomial certificate failed") rpoly = sp.Poly(r, m.x, m.y) for j, b in enumerate(basis): a[i, j] = rpoly.coeff_monomial(b) a0 = a.applyfunc(lambda e: sp.limit(e, m.z, sp.oo)) a1 = (a-a0).applyfunc(lambda e: sp.limit(m.z*e, m.z, sp.oo)) require((a-a0-a1/m.z).applyfunc(sp.simplify) == sp.zeros(6), "Connection has extra terms") chi = sp.Poly(a0.charpoly(m.t).as_expr(), m.t) require(sp.gcd(chi, chi.diff()).degree() == 0, "A0 has repeated eigenvalues") traces = [sp.trace(a0**k * (a1+sp.eye(6))) for k in range(6)] require(all(t == 0 for t in traces), "Formal-power trace test failed") print("PASS: A0 has simple spectrum.") print("PASS: tr(A0^k (A1+I))=0 for k=0,...,5:", traces) print("By the invertible Vandermonde matrix in the six distinct eigenvalues,") print("the diagonal of A1 in an eigenbasis of A0 is (-1,-1,-1,-1,-1,-1).") print("Thus all six formal powers lambda_i equal -1 exactly.") # At zero the residue in the actual monomial basis differs from the formal # exponents at infinity above. Its spectrum decides the meromorphic germ test. residue = sp.diag(*[-sp.Rational(k, 12) for k in (7, 10, 13, 11, 14, 17)]) residue[5, 0] = sp.Rational(5, 144) require(a1 == residue, "Unexpected residue in the rank-six basis") rat = sp.Rational xmin, xmax = -rat(29, 50), -rat(11, 20) ymin, ymax = rat(71, 100), rat(37, 50) lo, hi = rat(722, 1000), rat(723, 1000) critical = sp.Poly(4*(1 - 3*m.y**2)**3 + m.y, m.y) require(critical.count_roots(lo, hi) == 1, "Minimum not isolated") require(ymin < lo < hi < ymax and xmin < 1-3*hi**2 < 1-3*lo**2 < xmax, "Critical point outside the rectangle") require(72*xmax**2*ymin - 1 > 0, "Hessian bound") require(xmin**4 + ymax**3 + xmax*ymin - ymin < -rat(1, 2), "Rectangle phase separation") require(6**3 < 4**4, "Triangle minimum lower bound") print("PASS: nonintegral residue and rank-six minimum on the second polygon.") # Straight-edge degrees and the leading Stokes forcing on both actual domains. s, u, v = sp.symbols("s u v") triangle = [(0, -1), (1, -1), (rat(1, 2), 0)] rectangle = [(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax)] for vertices, degrees in ((triangle, [4, 4, 4]), (rectangle, [4, 3, 4, 3])): edges = list(zip(vertices, vertices[1:] + vertices[:1])) for (start, end), degree in zip(edges, degrees): dx, dy = end[0]-start[0], end[1]-start[1] edge = {m.x: start[0]+s*dx, m.y: start[1]+s*dy} require(sp.Poly(m.q.subs(edge), s).degree() == degree, "Edge degree") if vertices == triangle: chart = {m.x: (1-v)*u+v/2, m.y: v-1} jacobian = 1-v else: chart = {m.x: xmin+(xmax-xmin)*u, m.y: ymin+(ymax-ymin)*v} jacobian = (xmax-xmin)*(ymax-ymin) def unit_integral(expr, *variables): poly = sp.Poly(expr, *variables) return sum(coeff / sp.prod(i+1 for i in powers) for powers, coeff in poly.terms()) initial = sp.Matrix([unit_integral(sp.sympify(b).subs(chart)*jacobian, u, v) for b in basis]) forcing = [] for amplitude in basis: _, p, q = m.normal_form(m.q*amplitude) row = 0 for start, end in edges: dx, dy = end[0]-start[0], end[1]-start[1] edge = {m.x: start[0]+s*dx, m.y: start[1]+s*dy} residue_form = sp.expand(m.z*(p*dy-q*dx)).subs(m.z, 0) row += unit_integral(residue_form.subs(edge), s) forcing.append(row) require(a1*initial + sp.Matrix(forcing) == sp.zeros(6, 1), "Oriented Stokes forcing fails at order z^(-1)") print("PASS: seven edge degrees and twelve oriented Stokes initial identities.") # Rational simple-spectrum instance with several nonzero higher A_j. n, order = 3, 8 c = sp.diag(-2, 1, 4) a_coeff = [c, sp.Matrix([[1, 2, -1], [3, -2, 4], [2, 1, 5]]), sp.Matrix([[2, 0, 3], [-1, 1, 2], [4, -2, 0]]), sp.Matrix([[0, -3, 1], [2, 2, -1], [1, 5, -2]])] lam = diag(a_coeff[1]) h = [sp.eye(n)] + [sp.zeros(n) for _ in range(order+2)] for k in range(1, order+2): if k >= 2: rest = (a_coeff[1]-diag(a_coeff[1]))*(h[k-1]-diag(h[k-1])) rest += sum((a_coeff[j]*h[k-j] for j in range(2, min(k, len(a_coeff)-1)+1)), sp.zeros(n)) for i in range(n): h[k-1][i, i] = -rest[i, i]/(k-1) rest = sum((a_coeff[j]*h[k-j] for j in range(1, min(k, len(a_coeff)-1)+1)), sp.zeros(n)) rhs = -(k-1)*h[k-1]-rest+h[k-1]*lam require(all(rhs[i, i] == 0 for i in range(n)), "Diagonal recursion inconsistency") for i in range(n): for j in range(n): if i != j: h[k][i, j] = rhs[i, j]/(c[i, i]-c[j, j]) for k in range(1, order+1): residual = -(k-1)*h[k-1]-(c*h[k]-h[k]*c) residual -= sum((a_coeff[j]*h[k-j] for j in range(1, min(k, len(a_coeff)-1)+1)), sp.zeros(n)) residual += h[k-1]*lam require(residual == sp.zeros(n), f"Formal residual nonzero at w^{k}") print("PASS: exact rational 3x3 recursion, residual coefficients w^1,...,w^8 all zero.") print("These finite checks supplement, and do not replace, the general induction.")