back to table · edit · history · where entries came from · files · download
8890 bytes, as of the version from 2026-10-30 22:06 (current). Recorded here, not run.
"""Independent numerical and structural checks for numberdb.org/T633.
Run: sage -python checks.py beside generate.py, independent.py and check.py.
The checker uses independent trigonometric traces at 175 decimal digits and
Ray-Singer torsion to obtain the full one-form determinant by two routes.
These checks corroborate the production Arb enclosures, not replace them.
Set NUMBERDB_CHECK_STORED=1 to test the actual stored decimal intervals.
"""
import os
import sys
import json
from decimal import Decimal
from pathlib import Path
from math import gcd
import numberdb.sage as numberdb
from numberdb._write import to_text
from sage.rings.real_arb import RealBallField
from sage.rings.rational_field import QQ
import mpmath as mp
import generate as gen
import independent as ind
from check import exactness, measure, names_its_rings
HERE = Path(__file__).resolve().parent
mp.mp.dps = 175
def text_number(entry):
return entry['number'] if isinstance(entry,dict) else entry
def read_companion(tid):
path = HERE/(tid+'.json')
return json.loads(path.read_text()) if path.exists() else numberdb.table(tid)
def decimal_agrees(text,value):
ulp = mp.power(10,Decimal(text).as_tuple().exponent)
assert mp.isfinite(value)
assert abs(mp.mpf(text)-value) < ulp/2, (text,mp.nstr(value,110))
assert abs(mp.mpf(text)+10*ulp-value) > ulp
def rational_decimal(text):
d=Decimal(text); sign,digits,exp=d.as_tuple()
n=int(''.join(map(str,digits)))*(-1 if sign else 1)
return QQ(n)*QQ(10)**exp
def ball_within_decimal(x,text):
center=rational_decimal(text)
ulp=QQ(10)**Decimal(text).as_tuple().exponent
R=x.parent()
assert x-R(center-ulp) > 0 and R(center+ulp)-x > 0
def main():
if os.environ.get('NUMBERDB_KEY_FROM_STDIN') == '1':
key=sys.stdin.read().strip()
if '=' in key and key.split('=',1)[0].replace('_','').isalnum():
key=key.split('=',1)[1].strip().strip("\"'")
numberdb.configure(api_key=key)
g=gen.OneFormLensDeterminants(); R=RealBallField(700)
assert not names_its_rings(str(HERE/'generate.py'))
assert len(list(gen.presentations()))==46 and len(list(gen.cases()))==332
# Controls must be nonzero, and precede broad comparisons.
scalar_control=mp.log(2)-3*mp.zeta(3)/(2*mp.pi**2)
coexact_control=-2*mp.log(2)-3*mp.zeta(3)/mp.pi**2
full_control=-mp.log(2)-9*mp.zeta(3)/(2*mp.pi**2)
assert abs(ind.scalar_logdet(2,1,1)-scalar_control)<mp.mpf('1e-165')
assert abs(ind.coexact_logdet(2,1,1)-coexact_control)<mp.mpf('1e-165')
assert abs(3*ind.scalar_logdet(2,1,1)-2*ind.torsion_log(2,1,1)-full_control)<mp.mpf('1e-165')
assert gen.logdet(2,1,1).overlaps(-R(2).log()-9*R(3).zeta()/(2*R.pi()**2))
sphere=-mp.log(4*mp.pi)+3*mp.zeta(3)/(2*mp.pi**2)
sphere_ball=-(4*R.pi()).log()+3*R(3).zeta()/(2*R.pi()**2)
print('Nonzero scalar, coexact and full one-form controls pass.',flush=True)
n_sym=n_cover=n_modes=0
for p in range(2,21):
for q in range(1,p):
if gcd(p,q)!=1:continue
r=pow(q,-1,p)
for coeff in [gen.scalar_coefficients,gen.coexact_coefficients]:
for u in range(p):
c=coeff(p,q,u)
assert c==coeff(p,q,(-u)%p)
assert c==coeff(p,p-q,u)
assert c==coeff(p,r,u*r%p)
n_sym+=1
allc=[coeff(p,q,u) for u in range(p)]
for i in range(2*p):
m=i+2
expected=(m*m,4*p*m,4*p*p) if coeff is gen.scalar_coefficients else (2*(m*m-1),8*p*m,8*p*p)
assert tuple(sum(c[i][j] for c in allc) for j in (1,2,3))==expected
n_cover+=1
print('Exact symmetries and covering coefficients pass for both spectra.',flush=True)
for p,q,u in gen.cases():
for m in range(1,11):
assert gen.scalar_multiplicity(p,q,u,m)==ind.scalar_multiplicity_direct(p,q,u,m)
n_modes+=1
print('Independent harmonic-monomial scalar counts pass.',flush=True)
values={};results={};maxdiff=mp.mpf(0);maxcross=mp.mpf(0)
minacc=minhigh=100000
for p,q,u in gen.cases():
L=gen.logdet(p,q,u,100); H=gen.logdet(p,q,u,150)
a=ind.scalar_logdet(p,q,u); b=ind.coexact_logdet(p,q,u); t=ind.torsion_log(p,q,u)
other=3*a-2*t; alt=3*b/2+t
cross=abs(other-alt);assert cross<mp.mpf('1e-155')
diff=abs(mp.mpf(to_text(H,160))-other)
assert diff<mp.mpf('1e-145'),(p,q,u,mp.nstr(diff))
maxdiff=max(maxdiff,diff);maxcross=max(maxcross,cross)
key=f'{p},{q},{u}'
results[key]={'independent_logdet':mp.nstr(other,160),
'scalar_logdet':mp.nstr(a,160),'coexact_logdet':mp.nstr(b,160),
'absolute_logdet_discrepancy':mp.nstr(diff,10)}
for convention,x,y in [('det',L.exp(),H.exp()),('logdet',L,H)]:
assert x.is_finite() and y.is_finite() and x.overlaps(y)
assert x.accuracy()>=400 and y.accuracy()>=550
minacc=min(minacc,int(x.accuracy()));minhigh=min(minhigh,int(y.accuracy()))
text=to_text(x,100);ball_within_decimal(x,text)
decimal_agrees(text,mp.exp(other) if convention=='det' else other)
values[key+','+convention]=x
if u==0:print('checked',p,q,flush=True)
assert not exactness(values)
for p,q in gen.presentations():
assert sum(gen.logdet(p,q,min(u,p-u)) for u in range(p)).overlaps(sphere_ball)
companion={tid:read_companion(tid) for tid in ['T631','T632','T599']}
ncomp=ntorsion=0
for p,q,u in gen.cases():
for tid,ref in [('T631',ind.coexact_logdet(p,q,u)),('T632',ind.scalar_logdet(p,q,u))]:
row=companion[tid]['Numbers'][str(p)][str(q)][str(u)]
for convention,x in [('det',mp.exp(ref)),('logdet',ref)]:
decimal_agrees(text_number(row[convention]),x);ncomp+=1
if u:
t=text_number(companion['T599']['Numbers'][str(p)][str(q)][str(u)])
assert abs(ind.rational_text(t)-mp.exp(ind.torsion_log(p,q,u)))<mp.mpf('1e-95')
ntorsion+=1
evidence={'table':'T633','skill_manifest':'../20261030T215605Z-build-skills/manifest.json',
'skill_sha256':'10c1d8bd62d6ddfa2c016375ad82879151f0ab7a9516c2f371432108a85be009',
'entries':len(values),'presentations':46,'space_character_pairs':332,
'working_bits':numberdb.bits(100,losing=180),'minimum_accuracy_bits':minacc,
'higher_precision_minimum_accuracy_bits':minhigh,'independent_mpmath_dps':mp.mp.dps,
'maximum_logdet_discrepancy':mp.nstr(maxdiff,15),
'maximum_independent_route_discrepancy':mp.nstr(maxcross,15),
'sector_symmetry_cases':n_sym,'covering_polynomial_checks':n_cover,
'harmonic_monomial_checks':n_modes,'companion_entries_checked':ncomp,
'published_torsions_checked':ntorsion,
'decimal_enclosure_checks':len(values),'perturbation_controls':len(values),
'size':measure({k:to_text(v,100) for k,v in values.items()}),
'versions':g.environment(),'mpmath_version':mp.__version__,'stored_checked':False,
'results':results}
if os.environ.get('NUMBERDB_CHECK_STORED')=='1':
report=g.verify(sample=None);print(report);assert report.ok
document=numberdb.table('T633');n=nhodge=0
for p,q,u in gen.cases():
row=document['Numbers'][str(p)][str(q)][str(u)]
other=3*ind.scalar_logdet(p,q,u)-2*ind.torsion_log(p,q,u)
for convention,x in [('det',mp.exp(other)),('logdet',other)]:
decimal_agrees(text_number(row[convention]),x);n+=1
# Test Hodge and torsion on read-back logarithm intervals.
texts=[text_number(d['Numbers'][str(p)][str(q)][str(u)]['logdet'])
for d in (document,companion['T632'],companion['T631'])]
a,b,c=map(mp.mpf,texts)
ulps=[mp.power(10,Decimal(v).as_tuple().exponent) for v in texts]
assert abs(a-b-c)<sum(ulps)
assert abs((3*b-a)/2-ind.torsion_log(p,q,u))<(3*ulps[1]+ulps[0])/2
nhodge+=1
for p,q in gen.presentations():
texts=[text_number(document['Numbers'][str(p)][str(q)][str(min(u,p-u))]['logdet']) for u in range(p)]
total=mp.fsum(map(mp.mpf,texts));tol=mp.fsum(mp.power(10,Decimal(v).as_tuple().exponent) for v in texts)
assert abs(total-sphere)<tol
evidence.update(stored_checked=True,stored_entries_checked=n,
stored_hodge_and_torsion_checks=nhodge,stored_covering_checks=46)
print('EVIDENCE_JSON_START',flush=True)
print(json.dumps(evidence,indent=2),flush=True)
print('EVIDENCE_JSON_END',flush=True)
if __name__=='__main__':main()