companion_checks.py

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

2645 bytes, as of the version from 2026-10-31 21:28 (current). Recorded here, not run.

"""Check T629 conversions against fresh live T627/T628/T630 exports with SageMath.

Place the three API exports beside generate.py, checks.py and this file.
Recovered T627/T628 comparisons originate in run 20261030T194506Z.
The recovery adds T630 conversion and physical angular-momentum checks.
Stored decimal midpoints are never inputs to the defining root computation.
"""
import json,hashlib
from pathlib import Path
import numberdb.sage as numberdb
from sage.rings.real_arb import RealBallField
from sage.rings.rational_field import QQ
from generate import root_enclosure,enclose
from checks import written_interval,require_inside,physical_energy,F
p=Path(__file__).parent
policy=json.loads((p/'skill-evidence.json').read_text())
docs={tid:json.loads((p/(tid+'.json')).read_text()) for tid in ('T627','T628','T630')}
def text(doc,k):
 obj=doc['Numbers'][str(k)]
 return obj['number'] if isinstance(obj,dict) else obj
rows=[]
for k in range(1,11):
 x,lo,hi=root_enclosure(k,working_bits=700)
 e=1/(1+x*x).sqrt();theta=(1/x).arctan();beta=(1+3*x*x)/2-3*x/(2*theta)
 w=enclose(k,working_bits=700)[0]
 assert w.overlaps(x*theta*beta)
 s=x/(1+x*x).sqrt()
 j2=QQ(4)/25*(3/(4*x.parent().pi()))**(QQ(4)/3)*w/s**(QQ(4)/3)
 # Independently integrated surface potential yields Omega^2; assemble J^2=I^2 Omega^2.
 physical_omega2=physical_energy(F(x),uncertain=True)[1]
 mass=4*F.pi()*F(x)*(1+F(x)**2)/3
 inertia=2*mass*(1+F(x)**2)/5
 direct_j2=inertia**2*physical_omega2/(4*F.pi()*mass**(QQ(10)/3))
 assert j2.is_finite() and direct_j2.is_finite() and j2>0 and direct_j2>0
 assert F(j2.rad())<F(10)**(-110) and F(direct_j2.rad())<F(10)**(-110)
 assert j2.overlaps(direct_j2)
 for ball,tid in ((e,'T627'),(beta,'T628'),(j2,'T630'),(direct_j2,'T630')):
  center,ulp=written_interval(text(docs[tid],k));require_inside(ball,center,ulp)
 coarse=('0.021741','0.029152','0.034638','0.039037','0.042740','0.045957','0.048814','0.051395','0.053755','0.055935')[k-1]
 center,ulp=written_interval(coarse);assert abs(j2-F(center))<F(ulp/2)
 rows.append({'k':k,'eccentricity_enclosed_by_T627':True,'energy_ratio_enclosed_by_T628':True,'rotation_energy_identity':True,'angular_momentum_relation_enclosed_by_T630':True,'physical_angular_momentum_enclosed_by_T630':True,'coarse_angular_momentum_match':True,'j2_radius':str(j2.rad()),'physical_j2_radius':str(direct_j2.rad())})
 print('COMPANIONS PASS',k,flush=True)
print('COMPANION_EVIDENCE_JSON='+json.dumps({'table':'T629','run_id':policy['run_id'],'skill_manifest':policy['manifest'],'live_export_sha256':{tid:hashlib.sha256((p/(tid+'.json')).read_bytes()).hexdigest() for tid in docs},'companion_checks':rows}))