check_stored.py

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

5308 bytes, as of the version from 2026-11-26 13:45 (current). Recorded here, not run.

"""Read-back containment using the already independently verified exact vectors.

sage -python check_stored.py > check-results-stored.json
Uses generated-raw-serialization.json, whose every exact vector was compared
with the alternate rational formula in check-results-offline.json. Those same
vectors in generated.json must remain unchanged. This avoids recomputing a
long exact calculation after an environment termination, not any independent
check. Every stored decimal is freshly checked by MPFI component sums. The
full generic-q formula checker remains check_values.py for fresh reproduction.
"""
import hashlib,json,re,sys
from pathlib import Path
import numberdb.sage as numberdb
from sage.rings.integer_ring import ZZ
from sage.rings.rational_field import QQ
from sage.rings.number_field.number_field import CyclotomicField
from sage.rings.polynomial.laurent_polynomial_ring import LaurentPolynomialRing
from sage.env import SAGE_VERSION
from check_values import contains,parse_number,selection,COEFFICIENT_BYTES,C
W=Path(__file__).resolve().parent
report=json.loads((W/'check-results-offline.json').read_text())
raw=json.loads((W/'generated-raw-serialization.json').read_text())['rows']
current=json.loads((W/'generated.json').read_text())['rows']
assert report['checked_entries']==465 and report['total_entries']==465
assert not report['failures'] and report['known_answer_control'] and report['negative_control_rejected']
assert report['coefficient_data_sha256']==hashlib.sha256(COEFFICIENT_BYTES).hexdigest()
assert len(report['exact_formula_comparisons'])==465
assert all(c['equal'] for c in report['exact_formula_comparisons'])
fields={N:CyclotomicField(N) for N in range(2,33)}
def identity(r):
 a=r['params'];return int(a['p']),str(a['hand']),int(a['N'])
assert [identity(r) for r in raw]==selection()
assert [c['identity'] for c in report['exact_formula_comparisons']]==[list(identity(r)) for r in raw]
assert [(r['params'],r['cyclotomic_coefficients']) for r in raw]==[(r['params'],r['cyclotomic_coefficients']) for r in current]
values={identity(r):fields[int(r['params']['N'])]([QQ(c) for c in r['cyclotomic_coefficients']]) for r in raw}
d=json.loads((W/'stored-document.json').read_text());ns=d['Numbers']
rows=ns if isinstance(ns,list) else [{'params':{'p':p,'hand':h,'N':N},'number':e.get('number') if isinstance(e,dict) else e} for p,a in ns.items() for h,b in a.items() for N,e in b.items()]
assert [identity(r) for r in rows]==selection()
comparisons=[];failures=[]
for row in rows:
 ident=identity(row);v=values[ident];ok=contains(parse_number(row['number']),v,ident[2])
 comparisons.append({'identity':ident,'stored_contains_independent_enclosure':bool(ok)})
 if not ok:failures.append({'identity':ident,'kind':'stored enclosure'})
print('All stored containment checks finished',file=sys.stderr,flush=True)
# Entire color-two polynomial transport, independent of its root value.
jones=json.loads((W/'T139-controls.json').read_text());L=LaurentPolynomialRing(ZZ,'t');t=L.gen();color2=[]
for p,(n,k) in {1:(3,1),-1:(4,1),2:(5,2),-2:(6,1),3:(7,2),-3:(8,1),4:(9,2),-4:(10,1)}.items():
 polynomial=sum((L({int(e):ZZ(v) for e,v in C[str(p)][j]['coefficients'].items()})*(L.one() if j==0 else (1-t**(-1))*(1-t**3)) for j in [0,1]),L.zero())
 for hand in (('source',) if p==-1 else ('source','mirror')):
  target=polynomial if hand=='source' else polynomial(t**(-1));matches=[]
  for key,e in jones['Numbers'][str(n)][str(k)].items():
   m=int(re.search(r'm=(-?\d+)',e['comment']).group(1))
   if t**(-m)*L(e['number'])(t**(-1))==target:matches.append(key)
  color2.append({'p':p,'hand':hand,'T139_full_polynomial_matches':matches})
  if not matches:failures.append({'kind':'color-two polynomial transport','p':p,'hand':hand})
# Fresh negative checks of actual stored intervals.
target=next(r for r in rows if identity(r)==(1,'source',3));box=parse_number(target['number']);v=values[(1,'source',3)]
negative=all([not contains(box,v+1,3),not contains(box,v.conjugate(),3),not contains(box,v*fields[3].gen(),3),not contains(box,v*0,3)])
if not negative:failures.append({'kind':'fresh negative containment control'})
result={'table':'T821','checked_entries':len(rows),'total_entries':len(rows),'failures':failures,'known_answer_control':bool(report['known_answer_control']),'negative_control_rejected':negative,'method':'Fresh 896-bit MPFI component containment of stored intervals using exact vectors already checked independently by generic-q rational formula. Full color-two polynomial transport freshly checked.','reuse':'Every vector and ordered identity matches the checkpoint with 465 successful exact-formula comparisons; coefficient checkpoint SHA-256 unchanged. No unchecked vector is reused.','comparisons':comparisons,'color_two_polynomial_controls':color2,'skill_manifest':'../20261126T132634Z-build-skills/manifest.json','skill_bundle_sha256':'b5c3c7985b7c9e178b4899d083a9e3bc4284989dff76f05e5b0e52835d47eed2','sage':SAGE_VERSION,'input_sha256':hashlib.sha256((W/'stored-document.json').read_bytes()).hexdigest(),'evidence_sha256':{n:hashlib.sha256((W/n).read_bytes()).hexdigest() for n in ['generated-raw-serialization.json','generated.json','check-results-offline.json','coefficient-data.json.gz.b64']}}
print(json.dumps(result,indent=2));raise SystemExit(bool(failures))