deterministic_checks.py

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

2110 bytes, as of the version from 2026-11-18 04:29 (current). Recorded here, not run.

"""Replay preserved native intervals through the existing deterministic checks.

No new quadrature is performed. Original generator import/ring checks are
run against generate.py; values are the checkpointed primary computation.
"""
import json,sys
from pathlib import Path
import numberdb.sage as numberdb
from sage.rings.real_mpfi import RealIntervalField
from mpmath import mp
import generate,dry_run
from check import exactness,exact_in_disguise,prose,measure,names_its_rings
W=Path(__file__).parent
checkpoint=json.loads((W/'compute-checkpoint.json').read_text())
saved={r['record']['params']['k']:r for r in checkpoint}
F=RealIntervalField(700)
def replay(n,sign,digits):
    return F(saved[generate.key(n,sign)]['agreement_interval'])
generate.computed=replay
g=generate.Boyd35B()
assert [p['k'] for p in g.enumerate()]==list(saved)
dry_run.load=lambda path:g
status=dry_run.main([str(W/'generate.py')]);assert status==0
values={p['k']:g.value(p,100) for p in g.enumerate()}
assert not exactness(values) and not exact_in_disguise(values) and not prose(values)
stored=json.loads((W/'entries.json').read_text())
assert not exactness({r['params']['k']:r['number'] for r in stored})
assert not names_its_rings(str(W/'generate.py'))
with mp.workdps(200):
    widths=[]
    for k,v in values.items():
        interval=v['number']
        assert mp.isfinite(mp.mpf(str(interval.lower()))) and mp.isfinite(mp.mpf(str(interval.upper()))) and interval.absolute_diameter()>0
        midpoint=mp.mpf(str(interval.center()))
        ulp=mp.power(10,mp.floor(mp.log10(abs(midpoint)))-99)
        ratio=mp.mpf(str(interval.absolute_diameter()))/ulp
        assert ratio<mp.mpf('0.01'), (k,str(ratio))
        widths.append(ratio)
        print("WIDTH "+json.dumps({"k":k,"ratio":mp.nstr(ratio,15)}),flush=True)
    maxratio=mp.nstr(max(widths),15)
print('DETERMINISTIC '+json.dumps({'entries':len(stored),'failures':[],'all_native_types':sorted({r['native_type'] for r in checkpoint}),'finite_nonzero_width':True,'max_checkpoint_width_in_stored_ulps':maxratio,'sizes':measure(values),'cache_replay':True}),flush=True)