check_T460_repair.py

back to table · edit · history · where entries came from · files · download

3376 bytes, as of the version from 2026-10-16 09:47 (current). Recorded here, not run.

"""Check T460's formal-p convention against T459 and exact polynomial structure.
Run with Sage: sage -python check_T460_repair.py
Place T460-before.json and T459-live.json beside this script.
This read-only check generates no replacement values and makes no API calls.
"""
import json
from pathlib import Path
import numberdb.sage as numberdb
from sage.rings.rational_field import QQ
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.real_mpfi import RealIntervalField

root = Path(__file__).resolve().parent
doc = json.loads((root / 'T460-before.json').read_text())
cusps = json.loads((root / 'T459-live.json').read_text())
R = PolynomialRing(QQ, names=('L1', 'L2', 'L3', 'L4', 'L5', 'p'))
x = R.gens(); p = x[-1]
IF = RealIntervalField(512)

def number(entry):
    return entry['number'] if isinstance(entry, dict) else entry

def decimal_interval(value):
    if '.' not in value and 'e' not in value.lower():
        return IF(QQ(value))
    from decimal import Decimal
    dec = Decimal(value)
    tup = dec.as_tuple()
    mantissa = int(''.join(str(d) for d in tup.digits)) * (-1 if tup.sign else 1)
    ulp = QQ(10)**tup.exponent
    mid = mantissa * ulp
    return IF(mid - ulp, mid + ulp)

rows = []
polys = {}
for gs, group in doc['Numbers'].items():
    for ns, entry in group.items():
        g, n = int(gs), int(ns)
        v = R(number(entry))
        polys[g,n] = v
        assert set(v.variables()) <= set(x[:n]) | {p}
        assert all(sum(e) == 6*g-6+2*n for e in v.exponents())
        assert all(all(k % 2 == 0 for k in e) for e in v.exponents())
        assert all(c > 0 and c.parent() is QQ for c in v.coefficients())
        for j in range(n-1):
            assert v == v.subs({x[j]: x[j+1], x[j+1]: x[j]})
        coefficient = QQ(v(*([0]*5+[1])))
        computed = IF(coefficient) * IF.pi()**(6*g-6+2*n)
        stored = decimal_interval(number(cusps['Numbers'][gs][ns]))
        assert computed.is_NaN() is False
        assert computed.lower() >= stored.lower() and computed.upper() <= stored.upper()
        if (g,n) != (0,3):
            assert computed.absolute_diameter() < (IF(10)**(-140)).lower()
        rows.append({'g':g,'n':n,'monomials':len(v.monomials()),
                     'cusp_coefficient':str(coefficient),
                     'pi_exponent':6*g-6+2*n,
                     '512_bit_enclosure_inside_T459_interval':True})
assert set(polys) == {(0,3),(0,4),(0,5),(1,1),(1,2),(1,3),(2,0),(2,1)}
# Independent low-complexity normalization checks: Do, Appendix B.
assert polys[0,3] == 1
assert polys[1,1] == (x[0]**2 + 4*p**2)/48
assert polys[2,0] == QQ(43)/2160*p**6
# A wrong p=2*pi interpretation must fail for the positive-degree control.
wrong = IF(QQ(1)/12) * (2*IF.pi())**2
assert not wrong.overlaps(decimal_interval(number(cusps['Numbers']['1']['1'])))
print(json.dumps({'table':'T460','ok':True,'rows':rows,
 'monomials':sum(r['monomials'] for r in rows),
 'checks':['exact rational coefficients','allowed formal variables',
 'degree','evenness','symmetry','positive coefficients',
 'all eight p=pi cusp specializations within T459 stored intervals',
 'pair-of-pants, torus and closed genus-two normalization',
 'negative control p=2*pi rejected'],
 'limits':'No rerun of the DVV or kappa generator; no claim to verify every coefficient against an independent source.'},indent=2))