import json,hashlib
from pathlib import Path
import numberdb.sage as numberdb
from numberdb._write import to_text
from sage.rings.rational_field import QQ
from sage.rings.real_arb import RealBallField
import generate
p=Path(__file__).parent
old=json.loads((p/'numerical-evidence-original.json').read_text())
R=RealBallField(720)
values=generate.computation(30,100)[3]
def exact_endpoints(x):return [str(v.exact_rational()) for v in x.endpoints()]
for row in old['rows']:
    n=row['N'];v=R(values[n-1]);ind=R(row['integral'])
    assert ind.is_finite() and ind.rad_as_ball()<R(10)**-110
    assert v.overlaps(ind)
    row['generator_endpoints']=exact_endpoints(v)
    row['integral_endpoints']=exact_endpoints(ind)
    row['minimum_endpoints']=exact_endpoints(R(row['minimum']))
old['endpoint_serialization']='Generator endpoints recomputed cheaply; integral/minimum endpoints re-encoded from the original outward-rounded Arb ball strings. Original QQ(real) rational approximations are retained only in numerical-evidence-original.json and legacy kernel trace, not used as certified endpoints.'
old['executed_checker']='checks-executed.py; current checks.py corrects endpoint serialization and exact E_1 readback, with identical numerical methods.'
old['hashes']={name:hashlib.sha256((p/name).read_bytes()).hexdigest() for name in ['generate.py','integral_kernel.py','checks.py','checks-executed.py','skill-manifest.json','numerical-evidence-original.json']}
print('EVIDENCE_BEGIN')
print(json.dumps(old,indent=2))
print('NUMBERS_BEGIN')
print(json.dumps({str(n):to_text(v,digits=100) for n,v in enumerate(values,1)},indent=2))
