stored_check.py

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

3372 bytes, as of the version from 2026-11-18 12:45 (current). Recorded here, not run.

"""Check the ACTUAL stored decimal intervals and their full harmonicity.

Usage: sage -python stored_check.py with readback.json, generate.py, derive.py,
quadrature-result.json alongside. No network write and no credential required.
"""
import numberdb.sage
from sage.rings.rational_field import QQ
from sage.rings.real_arb import RealBallField
from fractions import Fraction
from decimal import Decimal
from pathlib import Path
import json
from generate import CubicResistance
from derive import canon,steps
from flatten import to_records
R=RealBallField(700);p=Path(__file__).resolve().parent;doc=json.loads((p/'readback.json').read_text());g=CubicResistance()
# Final upload uses the official flat-record format.
records=to_records(doc)
vals={};widths=[];exact=0
for record in records:
 params=record['params'];key=(str(params['lattice']),*(int(params[k]) for k in ('l','m','n')));text=str(record['number']);center=QQ(Fraction(text))
 if '/' in text or ('.' not in text and 'e' not in text.lower()):
  lo=hi=center;v=R(center);exact+=1
 else:
  exponent=Decimal(text).as_tuple().exponent;radius=QQ(10)**exponent;lo=center-radius;hi=center+radius;v=R(lo).union(R(hi));assert len(Decimal(text).as_tuple().digits)==100
 assert v.is_finite();assert hi-lo<QQ(10)**(-98)
 vals[key]=(v,lo,hi);widths.append(hi-lo)
assert len(vals)==87 and exact==3
expected_keys={(str(z['lattice']),*(z[k] for k in ('l','m','n'))) for z in g.enumerate()};assert set(vals)==expected_keys
controls=[(('sc',1,0,0),3),(('bcc',1,1,1),4),(('fcc',1,1,0),6)]
for key,q in controls:assert vals[key][1]==vals[key][2]==QQ(1)/q
checks=json.loads((p/'quadrature-result.json').read_text());high_count=0;low_count=0;failures=[]
for check in checks['comparisons']:
 key=(check['key'].split(',')[0],*(int(k) for k in check['key'].split(',')[1:]));v,lo,hi=vals[key]
 assert abs(R(str(check['low96']))-v)<R('3e-12');low_count+=1
 if 'high352' in check:
  q=R(check['high352']);assert q.is_finite() and q.rad().exact_rational()<QQ(10)**(-150)
  if lo==hi:assert abs(q-R(lo))<R('1e-150')
  else:assert q.lower().exact_rational()>=lo and q.upper().exact_rational()<=hi,key
  high_count+=1
# Harmonicity on stored balls, with individually computed helpers outside them.
for key,(v,lo,hi) in vals.items():
 L,*t=key;S=steps(L);res=len(S)*v
 for s in S:
  u=canon(tuple(t[i]+s[i] for i in range(3)))
  if u==(0,0,0):neighbor=R(0)
  elif (L,*u) in vals:neighbor=vals[(L,*u)][0]
  else:neighbor=R(g.value(dict(zip(g.parameters,(L,*u))),100))
  res-=neighbor
 assert res.is_finite() and res.contains_zero(),key
# Perturb a stored nonexact value: both direct interval containment and the
# harmonic equation at that row must cease to agree.
key=('sc',1,1,0);v,lo,hi=vals[key];perturbed=v+R(QQ(10)**(-50));assert not perturbed.overlaps(v)
assert not (6*(perturbed-v)).contains_zero()
print('STORED_RESULT',json.dumps({'table':'T751','checked_entries':87,'total_entries':87,'exact_entries':exact,'stored_high_precision_containment_checks':high_count,'stored_ordinary_integral_checks':low_count,'stored_harmonicity_checks':87,'maximum_stored_width':str(R(max(widths))),'known_answer_control':True,'negative_control_rejected':True,'failures':failures,'note':'Stored decimal intervals, not just midpoints, were checked. Exact rational controls are compared with the quadrature to its stated heuristic tolerance.'}),flush=True)