checks.py

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

5409 bytes, as of the version from 2026-10-29 08:32 (current). Recorded here, not run.

"""Numerical build checks for numberdb.org/T604.

Run: sage -python checks.py > numerical-evidence.jsonl
Requires generate.py, finite_formulas.py, independent.py and check.py.
This algorithmic verification is distinct from the controller's later
independent critique. Each comparison checks finite, narrow balls first.
"""
import json
import math
import os
import platform
import time
import numberdb.sage as numberdb
from sage.rings.rational_field import QQ
from sage.rings.real_arb import RealBallField
from sage.rings.complex_arb import ComplexBallField
from sage.env import SAGE_VERSION
from generate import HemisphereNeumann, logdet
from finite_formulas import sphere_logdet, dirichlet_logdet, stirling_row, even_correction
from independent import continuation
from check import exactness, measure, names_its_rings, agrees_with


def emit(x):
    print(json.dumps(x), flush=True)


def agreement(x, y, threshold=130):
    assert x.is_finite() and y.is_finite()
    assert x.rad_as_ball() < x.parent()(10)**(-threshold)
    assert y.rad_as_ball() < y.parent()(10)**(-threshold)
    assert x.overlaps(y), (x, y)


if __name__ == '__main__':
    emit({'table':'T604','skill_manifest':'agents/runs/20261029T075206Z-build-skills/manifest.json',
          'local_skill_sha256':'28ecbeeccb0c5e5d6eb541b5a5b0f88aec47b154374d909085116d34f5629199',
          'live_skill_sha256':'28ecbeeccb0c5e5d6eb541b5a5b0f88aec47b154374d909085116d34f5629199',
          'versions':{'sage':SAGE_VERSION,'numberdb':numberdb.__version__,'python':platform.python_version()},
          'working_decimal_digits':[150,200],'independent_working_decimal_digits':240})
    C = ComplexBallField(numberdb.bits(240)); R = RealBallField(numberdb.bits(240))
    # Nonzero control: zeta(2s) is the positive Neumann spectrum on [0,pi].
    control, info = continuation(1)
    agreement(control, (2*R.pi()).log())
    assert control > 1 and control < 2
    emit({'control':'interval log determinant log(2*pi)','passed':True,'info':info})
    for n in range(1,10):
        rhs = QQ((-1)**n*math.factorial(2*n))/2 * C(2*n+1).zeta()/(2*C.pi())**(2*n)
        agreement(C(-2*n).zetaderiv(1).real(),rhs.real())
    emit({'control':'negative-even zeta derivatives via functional equation','passed':True})
    coeff = {str(d):list(stirling_row(d)) for d in range(22)}
    coeff.update({'correction-'+str(n):even_correction(n) for n in range(1,11)})
    assert not exactness(coeff)
    for filename in ('generate.py','finite_formulas.py','independent.py'):
        assert not names_its_rings(os.path.join(os.path.dirname(__file__),filename))
    g = HemisphereNeumann(); values={}; reference={}; min_bits=10000; ind_min=10000
    for d in range(1,21):
        start=time.monotonic()
        lo=logdet(d,150); hi=logdet(d,200)
        agreement(lo,hi)
        independent,info=continuation(d)
        agreement(hi,independent)
        for convention, x, y in [('det',lo.exp(),independent.exp()),('logdet',lo,independent)]:
            agreement(x,y)
            values[(d,convention)]=x;reference[(d,convention)]=y
            min_bits=min(min_bits,int(x.accuracy()))
            ind_min=min(ind_min,int(y.accuracy()))
            # A 90th-place corruption must fail the comparison.
            delta=abs(x)*x.parent()(10)**(-90)
            assert not (x+delta).overlaps(y)
        # Polynomial identity proves the split for every spectral index k.
        # Testing d+1 indices is sufficient for these degree d-1 polynomials.
        for k in range(1,d+2):
            n=math.comb(d+k-1,d-1); dr=math.comb(d+k-2,d-1)
            sphere=math.comb(k+d,d)-math.comb(k+d-2,d) if k>=2 else d+1
            assert n+dr==sphere
        agreement(independent+dirichlet_logdet(d,200),sphere_logdet(d,200))
        agreement(independent.exp()*dirichlet_logdet(d,200).exp(),sphere_logdet(d,200).exp())
        if d==2:
            expected=(-C(0).zetaderiv(1)-2*C(-1).zetaderiv(1)+QQ(1)/4).real()
            agreement(hi,expected)
        if d==3:
            expected=(R.pi()/2).log()/2-C(-1).zetaderiv(1).real()-C(-2).zetaderiv(1).real()+QQ(1)/2
            agreement(hi,expected)
            actual_difference=dirichlet_logdet(3,200)-independent
            corrected=2*C(-1).zetaderiv(1).real()+R(2).log()-1
            printed=2*C(-1).zetaderiv(1).real()+R(2).log()+QQ(1)/2
            agreement(actual_difference,corrected)
            assert not actual_difference.overlaps(printed)
            emit({'source_discrepancy_d3':'printed +1/2 must be -1 for the stated spectra',
                  'error_in_printed_constant':'3/2','corrected_difference':str(corrected)})
        emit({'d':d,'logdet_150':str(lo),'det_150':str(lo.exp()),'logdet_200':str(hi),
              'independent_logdet':str(independent),'independent':info,'overlap':True,
              'seconds':round(time.monotonic()-start,3)})
    for d in (2,20):
        changed,info=continuation(d,K=50)
        agreement(changed,reference[(d,'logdet')])
        emit({'changed_split_control':d,'K':50,'passed':True,'info':info})
    assert len(values)==40 and not exactness(values)
    assert not agrees_with(values,lambda k:reference[k])
    emit({'status':'PASS','entries':40,'dimensions':20,'minimum_accuracy_bits_150':min_bits,
          'minimum_independent_accuracy_bits':ind_min,'measure':measure(values),
          'exactness':[],'independent_agrees_with':[],'perturbations_rejected':40})