stored_check.py

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

4048 bytes, as of the version from 2026-11-20 01:33 (current). Recorded here, not run.

"""T769 read-back checks, reproducibility and trace-orbit family controls.
Run with the bot key on stdin; no writes are performed. stored-rows.json and
trace-rows.json are authenticated exports of current website documents.
"""
import numberdb.sage as numberdb
from generate import IndividualHeegnerLogarithms
from builder_check import R,C,box,finite,serialized_contains,key,reduced_forms
from numbertext import decode_number
from sage.rings.rational_field import QQ
from pathlib import Path
from collections import defaultdict
import sys,json
numberdb.configure(api_key=sys.stdin.read().strip())

def narrow(z):return finite(z) and all(R(x.rad())<R(10)**-95 for x in [z.real(),z.imag()])
def agree(a,b):return narrow(a) and narrow(b) and (a-b).contains_zero()
def coords(z,w1,w2):
 v=z.imag()/w2.imag();u=(z.real()-v*w2.real())/w1.real();return u,v

def congruent(a,b,w1,w2):
 if not (narrow(a) and narrow(b)):return False
 u,v=coords(a-b,w1,w2)
 return all(R(x.rad())<R(10)**-92 and (x-int(x.center().round())).contains_zero() for x in [u,v])

if __name__=='__main__':
 root=Path(__file__).parent;stored=json.loads((root/'stored-rows.json').read_text());evidence=json.loads((root/'numerical-evidence.json').read_text());production=evidence['rows'];pp={p['N']:p for p in evidence['summary']['periods']};traces=json.loads((root/'trace-rows.json').read_text())
 assert [key(r['params']) for r in stored]==[key(r['params']) for r in production]
 lookup={key(r['params']):r for r in stored};orbits=defaultdict(list)
 for r,e in zip(stored,production):
  assert serialized_contains(r['number'],box(e['enclosure']))
  p=r['params'];N,D,beta,a,b,c=key(p);z=decode_number(r['number'],bits=500);assert narrow(z)
  w1,w2=box(pp[N]['omega1']),box(pp[N]['omega2']);u,v=coords(z,w1,w2)
  assert all(x.lower()>-QQ(1)/2 and x.upper()<QQ(1)/2 for x in [u,v])
  from sage.quadratic_forms.binary_qf import BinaryQF
  inv=tuple(map(int,BinaryQF([a,-b,c]).reduced_form()));other=lookup[(N,D,(-beta)%(2*N),*inv)]
  assert congruent(z.conjugate(),decode_number(other['number'],500),w1,w2)
  A,B,Cc=e['form'];frlabel=tuple(map(int,BinaryQF([N*Cc,-B,A//N]).reduced_form()));other=lookup[(N,D,(-beta)%(2*N),*frlabel)]
  assert congruent(QQ(pp[N]['kappa'])*w1-z,decode_number(other['number'],500),w1,w2)
  orbits[(N,D,beta)].append(z)
 trace_lookup={tuple(int(r['params'][k]) for k in ['N','D','beta']):r for r in traces};family=[]
 for arg,vals in orbits.items():
  N,D,beta=arg;target=decode_number(trace_lookup[arg]['number'],500);actual=sum(vals,C(0));w1,w2=box(pp[N]['omega1']),box(pp[N]['omega2'])
  assert len(vals)==len(reduced_forms(D));assert congruent(actual,target,w1,w2)
  family.append(dict(N=N,D=D,beta=beta,class_count=len(vals),trace_congruence=True))
 g=IndividualHeegnerLogarithms();report=g.verify(sample=None)
 print('VERIFY_REPORT '+str(report),flush=True)
 print('VERIFY_ATTRIBUTES '+json.dumps({n:getattr(report,n) for n in ['table','checked','agreed','mismatched','missing','failed'] if hasattr(report,n)},default=str),flush=True)
 assert report.ok
 z=decode_number(stored[0]['number'],500);w1,w2=box(pp[11]['omega1']),box(pp[11]['omega2'])
 controls=dict(period_congruence=congruent(z,z+w1+w2,w1,w2),wrong_representative_rejected=not agree(z,z+w1),wrong_sign_rejected=not congruent(z,-z,w1,w2),nan_rejected=not agree(z,C('nan')),wide_rejected=not agree(z,C(R(0,rad=R(100).upper()),R(0,rad=R(100).upper()))))
 assert all(controls.values())
 print('STORED_SUMMARY '+json.dumps(dict(table='T769',stored_entries=len(stored),generator_full_verify=True,serialized_containment_entries=len(stored),stored_representative_bounds_entries=len(stored),stored_conjugation_entries=len(stored),stored_fricke_entries=len(stored),class_orbits=len(family),trace_family_controls=family,controls=controls,limitations='Trace controls share the publicly attributed T732 primitive and homology component; they test family consistency and do not independently establish the summands. Stored interval containment and selected quadrature checks are separate.')),flush=True)