"""Compute axial inertia evidence for numberdb.org/T616, without API writes."""
import numberdb.sage as numberdb
from sage.rings.real_mpfr import RealField
from solver import inertia
import json,time
CONFIG={150:(160,12,'1/2'),210:(210,18,'2/3')}
INDICES=('0','1','1/2','3/2','2','5/2','3','7/2','4','9/2')
results={}
for n in INDICES:
    row={}
    for working,args in CONFIG.items():
        start=time.time();v,meta=inertia(n,working,*args,trace=True)
        meta['inertia']=str(v);meta['seconds']=time.time()-start;row[str(working)]=meta
        F=v.parent()
        if n in ['0','1']:
            anchor=F(2)/5 if n=='0' else F(2)/3-4/F.pi()**2
            err=abs(v-anchor)/anchor
            assert err<F(10)**(-working+30),(n,err)
            meta['control_error']=str(err)
            assert abs(v*(1+F(10)**-25)-anchor)/anchor>F(10)**-30
        print('RESULT',n,working,json.dumps(meta),flush=True)
    F=RealField(numberdb.bits(230));error=abs(F(row['150']['inertia'])-F(row['210']['inertia']))/abs(F(row['210']['inertia']))
    assert error<F(10)**-120,(n,error)
    row['relative_discrepancy']=str(error);results[n]=row
print('DATA '+json.dumps({'table':'T616','skill_manifest':'agents/runs/20261030T025528Z-build-skills/manifest.json','rigour':'heuristic (agreement-checked)','values':results}),flush=True)
