check_family.py

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

2088 bytes, as of the version from 2026-12-02 03:42 (current). Recorded here, not run.

"""Family consistency check, not independent evidence for sibling correctness.

Uses the live companion documents cached in this planning pass, their exact
stored uncertainty, and fresh production balls from this run. No sibling
value is trusted as an input to the expectation computation.
"""
import json,hashlib
from pathlib import Path
from decimal import Decimal
import numberdb.sage as numberdb
from sage.rings.rational_field import QQ
from sage.rings.real_arb import RealBallField
from sage.rings.real_mpfi import RealIntervalField
from generate import mean_components
w=Path(__file__).parent;R=RealBallField(512);I=RealIntervalField(512)

def interval(text):
 if isinstance(text,dict):text=text['number']
 if '/' in text or ('.' not in text and 'e' not in text.lower()):return R(QQ(text))
 d=Decimal(text);e=d.as_tuple().exponent;c=QQ(int(''.join(map(str,d.as_tuple().digits))))*QQ(10)**e
 if d.as_tuple().sign:c=-c
 u=QQ(10)**e
 return R(I(c-u,c+u))

c=json.loads((w/'T855.json').read_text());ww=json.loads((w/'T856.json').read_text());rows=json.loads((w/'offline-results.json').read_text())['entries']
out=[];failures=[]
for row in rows:
 r=QQ(row['params']['r']);n,y,_,_,_=mean_components(str(r))
 cc=interval(c['Numbers'][str(r)]);ws=interval(ww['Numbers'][str(max(r,1/r))])
 logone=(-y).log1p() if r>=1 else y.log()
 residual=2*R(n)-cc-ws+R(3).sqrt()/(2*R.pi())*R(logone)
 ok=residual.is_finite() and residual.contains_zero() and R(residual.rad().exact_rational())<R(10)**(-95)
 if not ok:failures.append(str(r))
 out.append({'r':str(r),'companion_identity_contains_zero':bool(ok),'residual':str(residual)})
assert list(c['Numbers'])==[r['params']['r'] for r in rows]
print(json.dumps({'table':'T857','checked_entries':len(out),'total_entries':len(rows),'failures':failures,'method':'Stored C and W intervals versus fresh N and exact-argument logarithmic term; consistency only, not independent sibling evidence','companion_sha256':{p:hashlib.sha256((w/p).read_bytes()).hexdigest() for p in ['T855.json','T856.json']},'entries':out},indent=2))
if failures:raise SystemExit(1)