back to table · edit · history · where entries came from · files · download
9489 bytes, as of the version from 2026-11-10 01:43 (current). Recorded here, not run.
"""Reproducible numerical checks for T702, independent of its q-average code.
Install dependencies: sage -pip install numberdb mpmath
Run: sage -python checks.py; use --stored to check the authenticated draft.
The Fourier calculation uses mpmath and analytically sums the q-direction;
unit-circle values use a finite Hurwitz-zeta sum, not a polylogarithm call.
The lattice check uses Samart (2.9) directly, with an explicit coarse tail.
No independent campaign critique verdict is asserted by this build check.
"""
import os,sys,json,math,time
from math import gcd
import numberdb.sage as numberdb
from sage.rings.rational_field import QQ
from sage.rings.real_arb import RealBallField
import mpmath as mp
from generate import Table, compute
from numberdb._write import to_text
FIELDS=('Delta','N','r','s')
DS=(-3,-4,-7,-8,-11,-12,-16,-19,-27,-28,-43,-67,-163)
def independent_selection():
result=[]
for D in DS:
for N in range(1,7):
for r in range(N):
for s in range(N):
order=math.lcm(N//gcd(N,r),N//gcd(N,s))
if order==N and (r,s)==min((r,s),((-r)%N,(-s)%N)):
result.append((D,N,r,s))
return result
def fourier(key, dps):
"""Sum the polylogarithm index after analytic geometric q-summation."""
D,N,r,s=key
with mp.workdps(dps):
a=mp.mpf(r)/N; A=mp.pi*mp.sqrt(-D); b=int(D%4!=0)
theta=mp.pi*(2*s-b*r)/N
target=mp.power(10,-dps+15)
if r==0:
base=sum(mp.cos(2*mp.pi*s*j/N)*mp.zeta(3,mp.mpf(j)/N)
for j in range(1,N+1))/N**3
else:
base=mp.mpf(0)
total=base
for k in range(1,10000):
sign=(-1)**(b*k); Q=sign*mp.exp(-A*k)
U0=1/(1-Q); U1=1/(1-Q)**2; U2=(1+Q)/(1-Q)**3
if r==0:
plus=Q*(U0/k**3+A*U1/k**2+A*A*U2/(3*k))
else:
plus=mp.exp(-A*a*k)*(U0/k**3+A*(a*U0+Q*U1)/k**2
+A*A*(a*a*U0+2*a*Q*U1+Q*U2)/(3*k))
minus=sign*mp.exp(-A*(1-a)*k)*(U0/k**3+A*(U1-a*U0)/k**2
+A*A*(U2-2*a*U1+a*a*U0)/(3*k))
total+=mp.cos(k*theta)*(plus+minus)
# Bound magnitude before the cosine so exact cosine zeros cannot
# falsely stop convergence. Used only for agreement checks.
if abs(plus)+abs(minus)<target:
return +total
raise ArithmeticError('Fourier sum did not converge')
def decimal_rational(text):
from decimal import Decimal
d=Decimal(str(text)); tup=d.as_tuple()
num=int(''.join(map(str,tup.digits))) * (-1 if tup.sign else 1)
return QQ(num)*QQ(10)**int(tup.exponent)
def written_ball(text, field):
from decimal import Decimal
# Generator stores ordinary decimals, +/- one unit in last place.
text=str(text); d=Decimal(text)
return field(decimal_rational(text)).add_error(field(QQ(10)**int(d.as_tuple().exponent)))
def reduced_key(D,N,r,s):
r%=N; s%=N; g=gcd(gcd(N,r),s)
N//=g; r//=g; s//=g
r,s=min((r,s),((-r)%N,(-s)%N))
return D,N,r,s
def finite_identities(values, field):
count=0
for D in DS:
origin=values[D,1,0,0]
for M in range(1,7):
total=sum((values[reduced_key(D,M,r,s)] for r in range(M) for s in range(M)),field(0))
residual=M*M*total-origin
assert residual.is_finite() and residual.contains_zero(), ('distribution',D,M,residual)
assert residual.rad_as_ball()<field(10)**-90
count+=1
if D%4==0:
residual=8*values[reduced_key(D,4,0,1)]+8*values[reduced_key(D,4,2,1)]-values[D,2,0,1]
assert residual.contains_zero() and residual.rad_as_ball()<field(10)**-90
count+=1
return count
def lattice(key, cutoff=100):
"""Independent float lattice sum; precision is explicitly coarse.
Equation (2.9) simplifies to 4*y^5/(3*pi) times
sum m^2*cos(2*pi*(n*r-m*s)/N)/((n-b*m/2)^2+y^2*m^2)^3.
The norm Q >= (m^2+n^2)/2 on all selected D. Shell j has 8j
integer points, so the omitted absolute tail is <=128*y^3/(3*pi*M^2).
Floating roundoff is negligible at this deliberately coarse tolerance;
this check is independent agreement evidence, not the digit certificate.
"""
D,N,r,s=key; y=math.sqrt(-D)/2; b=int(D%4!=0)
total=math.fsum(m*m*math.cos(2*math.pi*((n*r-m*s)%N)/N)
/((n-b*m/2)**2+(y*m)**2)**3
for m in range(-cutoff,cutoff+1) if m
for n in range(-cutoff,cutoff+1))
total*=4*y**5/(3*math.pi)
bound=128*y**3/(3*math.pi*cutoff**2)
return total,bound
def run(stored=False):
started=time.time(); B=RealBallField(650); g=Table()
keys=independent_selection(); assert len(keys)==494
assert keys==[tuple(int(p[k]) for k in FIELDS) for p in g.enumerate()]
# Nonzero control for Hurwitz-zeta grouping, before using that method.
with mp.workdps(180):
control=mp.zeta(3,mp.mpf(1)/2)/8+mp.zeta(3)/8
assert abs(control-mp.zeta(3))<mp.mpf('1e-175')
assert mp.mpf('1.2')<control<mp.mpf('1.21')
print('Hurwitz grouping nonzero control passed',flush=True)
values={}; records=[]; diag=[]; worst=mp.mpf(0); worst_repeat=mp.mpf(0)
if stored:
doc=numberdb.table('T702')
# table API may return nested Numbers or flat records.
nums=doc['Numbers']
if isinstance(nums,list):
stored_values={tuple(int(v['params'][k]) for k in FIELDS):v['number'] for v in nums}
else:
stored_values={}
for D,by_n in nums.items():
for N,by_r in by_n.items():
for r,by_s in by_r.items():
for s,v in by_s.items():
stored_values[int(D),int(N),int(r),int(s)]=v['number'] if isinstance(v,dict) else v
assert list(stored_values)==keys, 'Stored enumeration or order differs'
for index,key in enumerate(keys):
params=dict(zip(FIELDS,key))
v,d=compute(params,100,True); hi=compute(params,130)
assert v.is_finite() and hi.is_finite() and v.overlaps(hi)
text=stored_values[key] if stored else to_text(v,100)
wb=written_ball(text,B)
assert wb.contains_exact(hi), ('written interval',key)
f=fourier(key,150); h=fourier(key,190)
with mp.workdps(180):
midpoint=mp.mpf(str(hi.mid()))
error=abs(h-midpoint)/abs(h)
repeat=abs(f-h)/abs(h)
worst=max(worst,error); worst_repeat=max(worst_repeat,repeat)
assert error<mp.mpf('1e-120') and repeat<mp.mpf('1e-125'), (key,error,repeat)
values[key]=wb if stored else B(v)
diag.append(d)
records.append({'params':params,'number':text,'relative_accuracy_bits':d['relative_accuracy_bits']})
# Recompute both symmetries on every input, not just a relabeling.
D,N,r,s=key; b=int(D%4!=0)
for rr,ss in [(-r,-s),(r,b*r-s)]:
w=compute(dict(Delta=D,N=N,r=rr,s=ss),100)
assert w.is_finite() and v.overlaps(w), ('symmetry',key,rr,ss)
if (index+1)%50==0: print('checked',index+1,flush=True)
identities=finite_identities(values,B)
# Square lattice origin from independent Hurwitz zeta, plus known beta(1).
with mp.workdps(190):
beta2=(mp.zeta(2,mp.mpf(1)/4)-mp.zeta(2,mp.mpf(3)/4))/16
target=4*mp.pi*beta2/9
assert abs(fourier((-4,1,0,0),190)-target)<mp.mpf('1e-175')
R=RealBallField(650)
beta=(R(2).zeta(R(QQ(1)/4))-R(2).zeta(R(QQ(3)/4)))/16
square=4*R.pi()*beta/9
assert values[-4,1,0,0].overlaps(square)
lattice_results=[]
for key in [(-4,1,0,0),(-4,2,0,1),(-3,2,0,1),(-3,3,1,1),(-7,5,1,2),(-163,6,1,0)]:
v,bound=lattice(key)
true=float(values[key].mid())
assert abs(v-true)<bound
lattice_results.append({'params':list(key),'value':v,'absolute_bound':bound,'observed_error':abs(v-true)})
# Test the source's simplified 3-torsion relation in both markings.
source_relation=[]
for D in DS:
v=9*values[D,3,1,0]+9*values[D,3,0,1]+18*values[D,3,1,1]+4*values[D,1,0,0]
source_relation.append({'Delta':D,'contains_zero':bool(v.contains_zero()),'residual':str(v)})
evidence={'table':'T702','stored':stored,'entries':494,'minimum_relative_accuracy_bits':min(d['relative_accuracy_bits'] for d in diag),'terms_each_side':[min(d['terms_each_side'] for d in diag),max(d['terms_each_side'] for d in diag)],'fourier_max_relative_difference':mp.nstr(worst,8),'fourier_repeat_max_relative_difference':mp.nstr(worst_repeat,8),'symmetry_checks':988,'distribution_and_rectangular_four_torsion_checks':identities,'square_origin_beta_control':'passed','lattice_checks':lattice_results,'samart_2_13_diagnostic':source_relation,'versions':{'numberdb':numberdb.__version__,'mpmath':mp.__version__},'elapsed_seconds':time.time()-started,'skill_manifest':'agents/runs/20261110T013256Z-build-skills/manifest.json','skill_sha256':'886390324dd1971e381a43cf3b46b822ab0bc67d62f31d8481e29ec79556746b'}
print('EVIDENCE_JSON '+json.dumps(evidence),flush=True)
print('VALUES_JSON '+json.dumps(records),flush=True)
return evidence
if __name__=='__main__':
if os.environ.get('NUMBERDB_KEY_FROM_STDIN')=='1':
numberdb.configure(api_key=sys.stdin.read().strip())
run('--stored' in sys.argv or os.environ.get('NUMBERDB_STORED_CHECK')=='1')