repair-20261101T132645Z-checks.py

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

3190 bytes, as of the version from 2026-11-02 11:02 (current). Recorded here, not run.

"""Read-only checks for T651's 20261101T132645Z presentation repair.
Run: sage -python repair_checks.py, with repair-20261101T132645Z-document.json, generate.py,
catalogue.py and analytic.py alongside. No table values are changed.
Instruction manifest: agents/runs/20261101T132645Z-repair-skills/manifest.json.
Both local/live skill SHA-256: a2b28d9953264d7b0ca62663785c2952190c5be6d6d3597fd695d9a54d606278.
"""
import json, re
from pathlib import Path
from decimal import Decimal
import numberdb.sage as numberdb
from sage.rings.rational_field import QQ
from sage.rings.qqbar import AA
from sage.libs.pari import pari
from sage.rings.real_mpfr import RealField
from generate import HessianDeterminants
folder=Path(__file__).resolve().parent
doc=json.loads((folder/'repair-20261101T132645Z-document.json').read_text())
from sage.env import SAGE_VERSION
import mpmath
print(json.dumps({'kind':'environment','sage':SAGE_VERSION,'pari':str(pari.version()),'mpmath':mpmath.__version__}),flush=True)
entries=doc['Numbers']
assert list(HessianDeterminants().enumerate())==[{'t':key} for key in entries]
assert HessianDeterminants.digits==100
for key, row in entries.items():
    assert len(Decimal(row['number']).as_tuple().digits)==100
    def algebraic(s):
        a,b,d=re.fullmatch(r'(-?\d+(?:/\d+)?)([+-]\d+(?:/\d+)?)\*sqrt\((\d+)\)',s).groups()
        return AA(QQ(a))+AA(QQ(b.lstrip("+")))*AA(QQ(d)).sqrt()
    label=row['param-latex'].strip('$')
    label=re.sub(r'\\frac\{(-?\d+)\}\{(\d+)\}',r'\1/\2',label)
    label=re.sub(r'\\sqrt\{(\d+)\}',r'*sqrt(\1)',label)
    assert algebraic(label)==algebraic(key)
    assert algebraic(key).minpoly().degree()==2
print(json.dumps({'kind':'structure','entries':len(entries),'significant_digits':100,'generator_digits':100,'ordered_enumeration_equal':True,'radical_labels_exact':True}),flush=True)
# A fresh independent arithmetic check of the already stated row-16 identity.
# No analytic evaluator is called. L-functions are computed by PARI.
values=[]
for bits in (550,650):
    R=RealField(bits)
    zeta=R(pari.lfun(1,2,precision=bits))
    zeta_error=abs(zeta-R.pi()**2/6)
    assert zeta_error<R(2)**(-bits+20)
    curves=[pari.ellinit([0,0,0,0,sign]) for sign in (1,-1)]
    conductors=[int(curve.ellglobalred()[0]) for curve in curves]
    assert conductors==[36,144]
    L=[R(pari.lfun(curve,2,precision=bits)) for curve in curves]
    value=R(2187)*L[0]*L[1]/R.pi()**4
    stored=Decimal(entries['729+405*sqrt(3)']['number'])
    exact_mid=QQ(int(''.join(map(str,stored.as_tuple().digits))))*QQ(10)**int(stored.as_tuple().exponent)
    ulp=QQ(10)**int(stored.as_tuple().exponent)
    error=abs(value-R(exact_mid))/R(ulp)
    assert error<1
    print(json.dumps({'kind':'independent_lvalue','bits':bits,'conductors':conductors,'zeta_control_absolute_error':str(zeta_error),'value':str(value),'stored_midpoint_error_ulp':str(error),'rigour':'heuristic comparison, not a certified enclosure'}),flush=True)
    values.append(value)
R=RealField(650)
agreement=-(abs((R(values[0])-values[1])/values[1])).log10()
assert agreement>150
print(json.dumps({'kind':'agreement','relative_digits':str(agreement),'new_values_written':0}),flush=True)