independent_check.py

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

4963 bytes, as of the version from 2026-11-20 00:19 (current). Recorded here, not run.

"""Builder's independent numerical checks, not a scientific-critic verdict.
Run via SageMath with entries.json alongside this program. No generator import.
mpmath Gauss quadrature checks every k>4 at two precisions. PARI modular
L-functions check the endpoint and all four CM cases against Rogers/Samart.
mpmath zeta independently checks the Fermat case. The stored decimal denotes
one last-place unit of uncertainty; comparisons test containment of that value.
The check calculations themselves are numerical, not error certification.
"""
import numberdb.sage as numberdb
from sage.libs.pari import pari
import mpmath as mp
import json,time
from pathlib import Path
w=Path(__file__).parent;rows=json.loads((w/'entries.json').read_text())['entries'];stored={r['params']['k']:r['number'] for r in rows}
mp.mp.dps=210
results={'checked_entries':17,'total_entries':17,'failures':[],'known_answer_control':False,'negative_control_rejected':False,'period':[],'arithmetic':[]}
def matches(k,v):
 s=stored[str(k)];rad=mp.power(10,-len(s.split('.')[1]));return mp.isfinite(v) and abs(v-mp.mpf(s))<rad
def period(k,dps):
 with mp.workdps(dps):
  u=mp.mpf({'648^(1/4)':648,'2304^(1/4)':2304}.get(k,1)) if '^' in k else mp.mpf(k)**4
  z=256/u
  def f(t):
   if not t:return 3*z/32
   g=mp.hyp2f1(mp.mpf(1)/8,mp.mpf(3)/8,1,z*t)
   return (g-1)*(g+1)/t
  return +(mp.log(u)/4-mp.quad(f,[0,mp.mpf('0.5'),1])/4)
# Integration and Gauss-function nonzero controls and deliberate wrong value.
a=mp.quad(lambda x:x**4,[0,1]);b=mp.hyp2f1(1,1,2,mp.mpf(1)/3)
results['known_answer_control']=bool(abs(a-mp.mpf(1)/5)<mp.mpf('1e-190') and abs(b+3*mp.log(mp.mpf(2)/3))<mp.mpf('1e-190'))
results['negative_control_rejected']=bool(not matches('5',mp.mpf(stored['5'])+1))
if (w/'period-results.json').exists():
 results['period']=json.loads((w/'period-results.json').read_text());assert len(results['period'])==15 and all(r['stored_match'] for r in results['period'])
else:
 for k in stored:
  if k in ['0','4']:continue
  start=time.time();a=period(k,135);b=period(k,175);ok=matches(k,a) and matches(k,b) and abs(a-b)<mp.mpf('1e-125')
  rec={'k':k,'dps':[135,175],'value':mp.nstr(b,165),'precision_difference':mp.nstr(abs(a-b),8),'stored_match':bool(ok),'seconds':round(time.time()-start,3)}
  results['period'].append(rec)
  if not ok:results['failures'].append({'period':k})
  print('PERIOD '+json.dumps(rec),flush=True)
# Degeneration checked by a different zeta implementation, not Arb.
z0=7*mp.zeta(3)/(2*mp.pi**2);assert matches('0',z0)
results['fermat']={'value':mp.nstr(z0,180),'stored_match':True}
for digits in [140,180]:
 pari.set_real_precision(digits);bits=int(digits*mp.log(10,2))+60
 def L(f):return mp.mpf(str(pari.lfun(f,3,precision=bits)))
 lf=L(pari('lfunetaquo([1,2;2,1;4,1;8,2])'))
 lh=L(pari('lfunetaquo([4,6])'))
 def form(N,expected):
  m=pari.mfinit([N,3,pari.znchar(-N)],0);fs=pari.mfeigenbasis(m)
  chosen=[f for f in fs if all(pari.mfcoefs(f,len(expected))[i+1]==v for i,v in enumerate(expected))]
  assert len(chosen)==1,(N,str(fs))
  f=chosen[0];return L(pari.lfunmf(m,f,precision=bits)),str(pari.mfcoefs(f,13))
 lg24,c24=form(24,[1,-2,3,4,2,-6,-10,-8,9,-4])
 lg40,c40=form(40,[1,-2,0,4,5,0,6,-8,9,-10,-18,0,-6])
 def dl(D):return mp.mpf(str(pari.lfun(pari.znchar(D),2,precision=bits)))
 lm3,lm4,lm8=dl(-3),dl(-4),dl(-8)
 z2=mp.mpf(str(pari.lfun(1,2,precision=bits)))
 assert abs(lm4-mp.catalan)<mp.power(10,-digits+8) and abs(z2-mp.pi**2/6)<mp.power(10,-digits+8)
 vals={'4':40*mp.sqrt(2)/mp.pi**3*lf,
       '648^(1/4)':40/mp.pi**3*lh+mp.mpf(5)/(4*mp.pi)*lm4,
       '2304^(1/4)':20*mp.sqrt(6)/mp.pi**3*lg24+5*mp.sqrt(3)/(4*mp.pi)*lm3,
       '12':20*mp.sqrt(10)/mp.pi**3*lg40+8*mp.sqrt(2)/(5*mp.pi)*lm8,
       '28':200*mp.sqrt(2)/(3*mp.pi**3)*lf+5*mp.sqrt(3)/(2*mp.pi)*lm3}
 for k,v in vals.items():
  ok=matches(k,v);rec={'k':k,'dps':digits,'value':mp.nstr(v,digits-5),'stored_match':bool(ok),'q_g24_2':c24,'q_g40':c40}
  results['arithmetic'].append(rec)
  if not ok:results['failures'].append({'arithmetic':k,'dps':digits})
  print('ARITHMETIC '+json.dumps(rec),flush=True)
 # Wrong normalization and wrong modular form are discriminating controls.
 assert not matches('4',4*vals['4'])
 m=pari.mfinit([24,3,pari.znchar(-24)],0);wrong=next(f for f in pari.mfeigenbasis(m) if pari.mfcoefs(f,2)[2]==2)
 wrongval=20*mp.sqrt(6)/mp.pi**3*L(pari.lfunmf(m,wrong,precision=bits))+5*mp.sqrt(3)/(4*mp.pi)*lm3
 assert not matches('2304^(1/4)',wrongval)
 results.setdefault('lvalues',[]).append({'dps':digits,'Lf3':mp.nstr(lf,digits-5),'Lh3':mp.nstr(lh,digits-5),'Lg24_2_3':mp.nstr(lg24,digits-5),'Lg40_3':mp.nstr(lg40,digits-5),'Lchi-3_2':mp.nstr(lm3,digits-5),'Lchi-4_2':mp.nstr(lm4,digits-5),'Lchi-8_2':mp.nstr(lm8,digits-5)})
results['versions']={'mpmath':mp.__version__,'pari':str(pari('version()'))}
print('RESULT_JSON '+json.dumps(results),flush=True)
assert not results['failures'] and results['known_answer_control'] and results['negative_control_rejected']