back to table · edit · history · where entries came from · files · download
9586 bytes, as of the version from 2026-11-26 13:45 (current). Recorded here, not run.
"""Build-stage independent checks for T821; no writes to NumberDB.
sage -python prepare_check.py > coefficient-data.json
sage -python check_values.py > check-results.json
Run beside generated.json, coefficient-data.json and the generator. If
stored-document.json exists, check its actual entries as well. Input generic
coefficients are exact cancellations of NRZ (22), a different formula from
the nested root-field construction. This checker reconstructs the exact
cyclotomic invariant, then independently encloses its real and imaginary
parts with MPFI cos/sin sums at 896 bits. It checks containment in the actual
stored decimal interval, with exact singleton components checked algebraically.
It also uses the figure-eight positive sine-product sum for every N.
The formulas share cyclotomic-expansion mathematics; no independent review
verdict is claimed by this build-stage check.
"""
import hashlib,json,re,sys,gzip,base64
from pathlib import Path
from functools import lru_cache
from fractions import Fraction
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.rings.real_mpfi import RealIntervalField
from sage.env import SAGE_VERSION
W=Path(__file__).resolve().parent
COEFFICIENT_BYTES=(W/'coefficient-data.json').read_bytes() if (W/'coefficient-data.json').exists() else gzip.decompress(base64.b64decode((W/'coefficient-data.json.gz.b64').read_bytes()))
C=json.loads(COEFFICIENT_BYTES)['coefficients']
R=RealIntervalField(896)
def f(x): return Fraction(str(x))
def endpoints(x):return tuple(QQ(t.exact_rational()) for t in (x.lower(),x.upper()))
def finite_narrow(x):
try:
lo,hi=endpoints(x)
return lo<=hi and hi-lo<max(QQ.one(),abs(lo),abs(hi))*QQ(10)**(-180)
except (ValueError,TypeError,OverflowError):return False
@lru_cache(maxsize=None)
def independent(p,N):
K=CyclotomicField(N);z=K.gen()
val=K.zero();product=K.one()
for k in range(N):
a=C[str(p)][k]['coefficients']
coefficient=sum((QQ(v)*z**int(e) for e,v in a.items()),K.zero())
val+=coefficient*product
product*=(1-z**(1-N+k))*(1-z**(1+N+k))
return val
def rectangle(v,N):
theta=2*R.pi()/N
real,imag=R.zero(),R.zero()
for e,c in enumerate(v.list()):
real+=R(c)*(e*theta).cos()
imag+=R(c)*(e*theta).sin()
return real,imag
def algebraic_parts(v,N):
K=v.parent();conj=v.conjugate()
real=(v+conj)/2
imaginary=K.zero() if v==conj else ((v-conj)/(2*K.gen()**(N//4)) if N%4==0 else None)
return real,imaginary
def parse_component(s):
s=s.strip()
if '.' not in s and 'e' not in s.lower():
a=QQ(s);return (a,a)
a=f(s);unit=Fraction(10)**(-len(s.split('.',1)[1]))
return (QQ(a-unit),QQ(a+unit))
def parse_number(s):
s=s.replace(' ','')
if 'i*' not in s:return parse_component(s),(QQ.zero(),QQ.zero())
a,b=s.split('i*');sgn=-1 if a.endswith('-') else 1
if a in ['','+','-']: real=(QQ.zero(),QQ.zero())
else:real=parse_component(a[:-1])
imag=parse_component(b)
if sgn<0:imag=(-imag[1],-imag[0])
return real,imag
def contains(actual,v,N):
# Exact components are never judged by a rounded numerical midpoint.
parts=algebraic_parts(v,N);box=rectangle(v,N)
for j,((lo,hi),exact,enclosure) in enumerate(zip(actual,parts,box)):
if not finite_narrow(enclosure):return False
if lo==hi:
if exact is None or exact!=lo:return False
else:
a,b=endpoints(enclosure)
if not lo<=a<=b<=hi:return False
if hi-lo>max(QQ.one(),abs(lo),abs(hi))*QQ(10)**(-97):return False
return True
def selection():
return [(p,h,N) for d in range(1,5) for p in (d,-d)
for h in (('source',) if p==-1 else ('source','mirror')) for N in range(2,33)]
def run():
generated=json.loads((W/'generated.json').read_text())
rows=generated['rows']
stored=W/'stored-document.json'
if stored.exists():
doc=json.loads(stored.read_text());numbers=doc['Numbers']
if isinstance(numbers,list):rows=numbers
else:rows=[{'params':{'p':p,'hand':h,'N':N},'number':a['number'] if isinstance(a,dict) else a} for p,b in numbers.items() for h,c in b.items() for N,a in c.items()]
failures=[];comparisons=[];exact_comparisons=[]
ids=[];minimum_digits=None
for row in rows:
a=row['params'];p,h,N=int(a['p']),str(a['hand']),int(a['N']);ids.append((p,h,N))
v=independent(p,N)
if h=='mirror':v=v.conjugate()
if 'cyclotomic_coefficients' in row:
saved=v.parent()([QQ(c) for c in row['cyclotomic_coefficients']]);ok=saved==v
if not ok:failures.append({'identity':(p,h,N),'kind':'exact formula disagreement'})
exact_comparisons.append({'identity':(p,h,N),'equal':bool(ok)})
actual=parse_number(row['number']);ok=contains(actual,v,N)
comparisons.append({'identity':(p,h,N),'stored_contains_independent_enclosure':bool(ok),'rational_real':bool(algebraic_parts(v,N)[0] in QQ),'exact_real':str(QQ(v)) if v in QQ else None})
if not ok:failures.append({'identity':(p,h,N),'kind':'stored enclosure'})
if ids!=selection():failures.append({'kind':'selection or order','entries':len(ids)})
figures=[]
for N in range(2,33):
prod=R.one();total=R.one()
for j in range(1,N):
prod*=4*(R.pi()*j/N).sin()**2;total+=prod
expected=rectangle(independent(-1,N),N)[0]
ok=finite_narrow(total) and total.overlaps(expected)
figures.append({'N':N,'sine_product_overlap':bool(ok)})
if not ok:failures.append({'kind':'figure-eight sine product','N':N})
known=all(independent(-1,N)==c for N,c in [(2,5),(3,13),(4,27)]) and independent(1,3)==1+6*CyclotomicField(3).gen()**2
# Color two at zeta_2=-1 equals the signed Jones evaluation: -determinant.
alexander=json.loads((W/'T138-controls.json').read_text());L=LaurentPolynomialRing(ZZ,'t');t=L.gen();color2=[];jones=json.loads((W/'T139-controls.json').read_text())
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():
delta=L(alexander['Numbers'][str(n)][str(k)]['number']);det=abs(delta(-1));got=independent(p,2)
ok=abs(got)==det;color2.append({'p':p,'signed_value':str(got),'determinant':str(det),'equal_magnitudes':bool(ok)})
if not ok:failures.append({'kind':'Alexander determinant','p':p})
# Construct the entire generic color-two polynomial from the alternate
# coefficient formula. This fixes variable/mirror transport, beyond
# merely matching its determinant at q=-1.
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')):
tested=polynomial if hand=='source' else polynomial(t**(-1))
matches=[]
for key,entry in jones['Numbers'][str(n)][str(k)].items():
shift=int(re.search(r'm=(-?\d+)',entry['comment']).group(1))
raw=t**(-shift)*L(entry['number'])(t**(-1))
if raw==tested:matches.append(key)
color2.append({'p':p,'hand':hand,'full_T139_polynomial_matches':matches})
if not matches:failures.append({'kind':'full color-two Jones transport','p':p,'hand':hand})
z=CyclotomicField(3).gen();target=independent(1,3);correct=parse_number(next(r['number'] for r in rows if (int(r['params']['p']),r['params']['hand'],int(r['params']['N']))==(1,'source',3)))
controls={
'coefficient_perturbation':not contains(correct,target+1,3),
'inverse_root':not contains(correct,target.conjugate(),3),
'missing_Laurent_shift':not contains(correct,target*z,3),
'extra_quantum_dimension':not contains(correct,target*0,3),
'NaN_rejected':not finite_narrow(R('NaN')),
'vacuous_interval_rejected':not finite_narrow(R(-10**100,10**100))}
if not known or not all(controls.values()):failures.append({'kind':'checker control','known':bool(known),'negative':controls})
# p=0 and N=1 are constants 1, as verified at coefficient k=0 in the source.
return {'table':'T821','stage':'build independent formulas and interval checks','input':'stored-document.json' if stored.exists() else 'generated.json','checked_entries':len(rows),'total_entries':len(rows),'failures':failures,'known_answer_control':bool(known),'negative_control_rejected':all(controls.values()),'controls':controls,'exact_formula_comparisons':exact_comparisons,'comparisons':comparisons,'figure_eight_checks':figures,'color_two_controls':color2,'working_bits':896,'method':'exact generic-q rational coefficients, then MPFI sine/cosine power-basis sum','independence':'Different coefficient formula and implementation; MPFI trigonometric component sums versus Arb exponential Horner evaluation. Shared cyclotomic expansion and signed diagram convention.','sage':SAGE_VERSION,'python':sys.version,'skill_manifest':'../20261126T132634Z-build-skills/manifest.json','skill_bundle_sha256':'b5c3c7985b7c9e178b4899d083a9e3bc4284989dff76f05e5b0e52835d47eed2','coefficient_data_sha256':hashlib.sha256(COEFFICIENT_BYTES).hexdigest()}
if __name__=='__main__':
result=run();print(json.dumps(result,indent=2));raise SystemExit(bool(result['failures']))