stored_check.py

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

3501 bytes, as of the version from 2026-11-18 23:06 (current). Recorded here, not run.

"""Read-back verification of T762 using independent BCM trace checkpoints.

With full SageMath and numberdb, place generate.py, character_check.py and
character-checkpoints.json beside this file, then run:
    sage -python stored_check.py
Set NUMBERDB_API_KEY for the private draft. An export may instead be supplied
as stored-document.json. This check exports flat stored-entries.json, suitable
as input to character_check.py for a fresh full finite-field computation.
This script does not certify itself as a separate scientific-review actor.
"""
import os,sys,json,pathlib,hashlib
import numberdb.sage as numberdb
from sage.rings.integer_ring import ZZ
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from generate import K3Frobenius
from character_check import cubics_agree,independent_arguments,GAMMA
base=pathlib.Path(__file__).resolve().parent
key=sys.stdin.read().strip() if os.environ.get('NUMBERDB_KEY_FROM_STDIN')=='1' else os.environ.get('NUMBERDB_API_KEY','')
client=numberdb.Client(api_key=key) if key else None
if pathlib.Path('/work/stored-document.json').exists():
 doc=json.loads(pathlib.Path('/work/stored-document.json').read_text())
elif (base/'stored-document.json').exists():doc=json.loads((base/'stored-document.json').read_text())
else:doc=numberdb.table('T762',client=client)
block=doc['Numbers'];rows=[]
if isinstance(block,list):rows=block
else:
 for a,zblock in block.items():
  for z,pblock in zblock.items():
   for p,value in pblock.items():
    rows.append({'params':{'template':a,'z':z,'p':int(p)},'number':value['number'] if isinstance(value,dict) else value})
assert len(rows)==336
expected={(a,str(z),p) for a in GAMMA for z in independent_arguments() for p in (5,7,11,13)}
identities={(str(r['params']['template']),str(r['params']['z']),int(r['params']['p'])) for r in rows}
assert identities==expected
cp=json.loads((base/'character-checkpoints.json').read_text());checker_hash=hashlib.sha256((base/'character_check.py').read_bytes()).hexdigest()
assert all(x['checker_sha256']==checker_hash for x in cp)
traces={}
for x in cp:
 for k,v in x['traces'].items():
  a,z=k.split(',',1);traces[a,z,x['p'],x['e']]=v['trace']
R=PolynomialRing(ZZ,'T');failures=[]
for row in rows:
 a,z,p=str(row['params']['template']),str(row['params']['z']),int(row['params']['p'])
 coefficients=list(R(row['number']));s=[traces[a,z,p,e] for e in (1,2,3)]
 if not cubics_agree(coefficients,s):failures.append({'params':row['params'],'traces':s})
control_coeff=[1,4,20,125];control_s=[-4,-24,-199]
known=cubics_agree(control_coeff,control_s)
negative=not cubics_agree([1,5,20,125],control_s) and not cubics_agree([1,4,-20,-125],control_s)
assert known and negative and not failures
report=K3Frobenius().verify(sample=None,client=client)
assert report.checked==336 and report.matched==336 and not report.differing
print('STORED_ENTRIES '+json.dumps(rows),flush=True)
result={'checked_entries':336,'total_entries':336,'failures':failures,'known_answer_control':known,'negative_control_rejected':negative,'generator_verified':report.checked,'generator_matched':report.matched,'method':'Compare live stored coefficients with independently computed p,p^2,p^3 BCM trace checkpoints; check exact argument enumeration; full generator.verify', 'checkpoint_sha256':hashlib.sha256((base/'character-checkpoints.json').read_bytes()).hexdigest(),'checker_sha256':checker_hash,'skill_manifest':'skill-manifest.json'}
print('STORED_RESULTS '+json.dumps(result),flush=True)