back to table · edit · history · where entries came from · files · download
5160 bytes, as of the version from 2026-11-18 14:47 (current). Recorded here, not run.
"""Independent build checks for T752. Run with SageMath, alongside
independent_xi.c and computed-values.json (or stored-values.json).
No generator module or secondary-zeta C implementation is imported.
The even checker expands the completed xi product in Arb power series.
The separate mpmath A-P+E-S implementation checks all positive orders.
The latter shares the Arias decomposition theorem with the generator;
it supplies heuristic agreement, not another rigorous error certificate.
Euler recurrence and exact off-line-divisor controls check conventions.
"""
import numberdb.sage as numberdb
from sage.rings.rational_field import QQ
from sage.rings.real_arb import RealBallField
from sage.env import SAGE_LOCAL
import ctypes,json,math,os,subprocess,time,sys
from pathlib import Path
import mpmath as mp
ROOT=Path(__file__).resolve().parent
p=ROOT/('stored-values.json' if (ROOT/'stored-values.json').exists() else 'computed-values.json')
rows=json.loads(p.read_text()); rows={str(r['s']):r['written'] for r in rows}
field=RealBallField(1600)
# Exact decimal endpoints from the client parser, without treating a midpoint as exact.
def limits(written):
from fractions import Fraction
from decimal import Decimal
text=written.strip()
if '/' in text or ('.' not in text and 'e' not in text.lower()):
q=Fraction(text);v=QQ(q.numerator)/q.denominator;return v,v
dec=Decimal(text);q=Fraction(dec);v=QQ(q.numerator)/q.denominator
exponent=dec.as_tuple().exponent
ulp=QQ(10)**exponent
return v-ulp,v+ulp
def close_ball(written,ball):
lo,hi=limits(written)
if not ball.is_finite() or ball.rad()>=abs(ball).lower()*(QQ(1)/10**105):return False
return bool(ball.lower()>=lo and ball.upper()<=hi)
report={'total_entries':len(rows),'checked_entries':0,'failures':[],
'known_answer_control':False,'negative_control_rejected':False,
'input':p.name,'checks':[],'versions':{'python':sys.version,'mpmath':mp.__version__}}
def record(kind,s,ok,**kw):
r={'method':kind,'s':s,'passed':bool(ok),**kw};report['checks'].append(r)
if not ok:report['failures'].append(r)
print('CHECK',json.dumps(r),flush=True)
# Euler numbers generated from cosh(x)*sech(x)=1, independent of Sage euler_number.
from math import comb
E=[1]
for n in range(1,21):E.append(-sum(comb(n,k)*E[k] for k in range(n) if (n-k)%2==0))
for s in [0]+list(range(-2,-21,-2)):
n=-s//2;expected=QQ((-1)**n*(8-E[2*n]))/2**(2*n+3)
lo,hi=limits(rows[str(s)]);record('Euler recurrence exact',s,lo==hi==expected,expected=str(expected))
# Nonzero control detects forbidden real-part and magnitude substitutions.
from fractions import Fraction as F
# (1+i/4)^(-2)+(1-i/4)^(-2) = 2*(1-(1/4)^2)/(1+(1/4)^2)^2.
pair=2*(1-F(1,16))/(1+F(1,16))**2
report['known_answer_control']=(pair==F(480,289) and limits(rows['0'])==(QQ(7)/8,QQ(7)/8) and limits(rows['-2'])==(QQ(-9)/32,QQ(-9)/32) and limits(rows['-4'])==(QQ(3)/128,QQ(3)/128))
assert report['known_answer_control']
prefix=Path(SAGE_LOCAL);libpath='/tmp/numberdb-independent-xi.so'
cmd=['cc','-shared','-fPIC','-O2','-I'+str(prefix/'include/flint'),'-I'+str(prefix/'include'),str(ROOT/'independent_xi.c'),'-L'+str(prefix/'lib'),'-Wl,-rpath,'+str(prefix/'lib'),'-lflint','-lm','-o',libpath]
r=subprocess.run(cmd,capture_output=True,text=True)
if r.returncode:print(r.stderr);raise SystemExit(r.returncode)
lib=ctypes.CDLL(libpath);lib.numberdb_xi_even.argtypes=[ctypes.c_long]*3;lib.numberdb_xi_even.restype=ctypes.c_void_p;lib.numberdb_xi_free.argtypes=[ctypes.c_void_p]
for s in range(2,51,2):
pointer=lib.numberdb_xi_even(s,1600,450)
try:text=ctypes.string_at(pointer).decode()
finally:lib.numberdb_xi_free(pointer)
acc,balltext=text.split('\n',1);ball=field(balltext);ok=close_ball(rows[str(s)],ball)
record('Arb central-xi log series',s,ok,relative_accuracy_bits=int(acc),enclosure=balltext)
if s==2:
invalid=[2*ball,-ball,field('nan'),field('1 +/- 1000'),field('0.023095708966121033814310247906495291621932127940315480019005'),ball*4*field.pi()]
rejected=[not close_ball(rows['2'],b) for b in invalid]
report['negative_control_rejected']=all(rejected) and pair!=2 and pair!=F(32,17)
print('CONTROLS',json.dumps({'wrong_factor_sign_nan_huge_T36_heat_scale_rejected':rejected,'ordinate_and_modulus_rejected':pair!=2 and pair!=F(32,17)}),flush=True)
# Independent implementation, all 49 positive integer orders, alternate split.
mp.mp.dps=170
for s in range(2,51):
start=time.time();value,error=mp.secondzeta(s,a=mp.mpf(1)/200,error=True)
lo,hi=limits(rows[str(s)]);lo_mp=mp.mpf(str(lo.numerator()))/mp.mpf(str(lo.denominator()));hi_mp=mp.mpf(str(hi.numerator()))/mp.mpf(str(hi.denominator()))
ok=mp.isfinite(value) and lo_mp<=value<=hi_mp
# Error here is the routine's heuristic estimate and is labelled accordingly.
record('mpmath secondzeta independent implementation',s,ok,value=mp.nstr(value,145),heuristic_error=mp.nstr(error,8),seconds=time.time()-start)
report['checked_entries']=len(set(str(r['s']) for r in report['checks'] if r['passed']))
print('RESULT',json.dumps(report),flush=True)
if report['failures'] or not report['known_answer_control'] or not report['negative_control_rejected']:raise SystemExit(1)