back to table · edit · history · where entries came from · files · download
5347 bytes, as of the version from 2026-11-16 11:55 (current). Recorded here, not run.
"""Independent numerical checks for T725 (Sage Python, mpmath 1.4.1).
Run: sage -python checks.py
Reads entries.json beside this file; prints JSON evidence to stdout.
Independent mpmath Bessel functions, direct-t tanh-sinh integration and
Leibniz permutation determinant. The generator uses Sage/Arb, log-t
quadrature and matrix elimination. All 12 values are checked; these
numerical comparisons are heuristic and do not certify stored precision.
The certificate for stored precision is the generator's full Arb enclosure.
The Gamma control uses Zhou (4.37)--(4.38), not a sibling table's digits.
"""
import json,sys,time,itertools,math
from pathlib import Path
from functools import lru_cache
import numberdb.sage as numberdb
import mpmath as mp
mp.mp.dps=130
entries=json.loads(Path(__file__).with_name('entries.json').read_text())
failures=[]
def emit(kind,**data):
print(json.dumps({'kind':kind,**data}),flush=True)
@lru_cache(maxsize=60000)
def functions(t):
return mp.besseli(0,t),mp.besselk(0,t)
@lru_cache(maxsize=None)
def integral(a,b,r):
if not (a>=0 and b>a and r>=1):raise ValueError('ordinary convergent moment required')
def f(t):
if t==0:return mp.mpf(0)
I,K=functions(t)
return I**a*K**b*t**r
return mp.quad(f,[0,1,4,16,64,mp.inf],method='tanh-sinh')
def det(rows):
d=len(rows);out=mp.mpf(0)
for p in itertools.permutations(range(d)):
inversions=sum(p[i]>p[j] for i in range(d) for j in range(i+1,d))
out+=(-1)**inversions*mp.fprod(rows[i][p[i]] for i in range(d))
return out
def stored_interval(text):
# Decimal-last-place interpretation, including a possible exponent.
from decimal import Decimal
x=Decimal(text);power=x.as_tuple().exponent
return mp.mpf(text),mp.power(10,power)
def close(actual,expected,tolerance=mp.mpf('1e-110')):
return bool(mp.isfinite(actual) and mp.isfinite(expected) and
abs(actual-expected)<=tolerance*max(abs(expected),mp.mpf('1e-200')))
start=time.time()
mp.mp.dps=50
control1=integral(0,1,1);control2=integral(0,2,1)
known=close(control1,mp.mpf(1),mp.mpf('1e-45')) and close(control2,mp.mpf(1)/2,mp.mpf('1e-45'))
negative=not close(-control1,mp.mpf(1)) and not close(control1/mp.pi,mp.mpf(1)) and not close(mp.nan,mp.mpf(1)) and not close(mp.inf,mp.mpf(1))
assert known and negative
emit('controls',known_answer_control=known,negative_control_rejected=negative,
control_dps=50,first=mp.nstr(control1,52),second=mp.nstr(control2,52),seconds=time.time()-start)
mp.mp.dps=130
functions.cache_clear();integral.cache_clear()
expected_dimensions={5:1,6:1,7:1,8:1,9:2,10:2,11:2,12:2,13:3,14:3,15:3,16:3}
assert {int(k) for k in entries}==set(expected_dimensions)
values={}
for text_n,text in entries.items():
n=int(text_n);d=expected_dimensions[n];st=time.time()
rows=[[integral(2*i+2,n-2*i-2,2*j+1) for j in range(d)] for i in range(d)]
v=det(rows);values[n]=v
midpoint,ulp=stored_interval(text);error=abs(v-midpoint)/ulp
# Bound precision of the *comparison* before interpreting stored-interval containment.
assert mp.isfinite(v) and v>0 and all(mp.isfinite(x) for row in rows for x in row)
ok=bool(error<1)
if not ok:failures.append('n=%d: independent result outside stored decimal interval'%n)
emit('entry',n=n,dimension=d,value=mp.nstr(v,125),stored_ulp_error=mp.nstr(error,14),passed=ok,seconds=time.time()-st)
# Source-independent low scalar control and published Gamma identity.
controls={5:mp.sqrt(3)*mp.fprod(mp.gamma(mp.mpf(j)/15) for j in [1,2,4,8])/(480*mp.pi)}
for n,v in controls.items():
assert close(values[n],v)
mid,ulp=stored_interval(entries[str(n)])
assert abs(v-mid)<ulp
emit('closed-form',n=n,expected=mp.nstr(v,130),stored_ulp_error=mp.nstr(abs(v-mid)/ulp,14))
# Proved reflection formula (Zhou 1.21), additional independently integrated rows.
for n in [5,7,9,11,13,15]:
k=(n-1)//2;d=(k+1)//2
rows=[[integral(2*i+1,n-2*i-1,2*j+1) for j in range(d)] for i in range(d)]
odd=det(rows)
def df(m):return math.prod(range(m,0,-2))
factor=mp.sqrt(mp.mpf(df(2*k+1))**(2-(-1)**k))/(mp.pi**((k+1)//2)*2**(k//2)*df(k-1)*mp.mpf(df(k))**(1-(-1)**k))
assert close(values[n],factor*odd)
emit('reflection',n=n,odd_value=mp.nstr(odd,130),factor=mp.nstr(factor,130),relative_error=mp.nstr(abs(values[n]/(factor*odd)-1),14))
# Wrong reduced dimension and a divergent boundary must be rejected.
wrong9=integral(2,7,1)
assert not close(wrong9,values[9])
assert all(abs(v-stored_interval(entries[str(n)])[0])>stored_interval(entries[str(n)])[1] for n,v in [(5,-values[5]),(5,values[5]/mp.pi),(9,wrong9)])
try:
integral(4,4,3)
raise AssertionError('divergent boundary admitted')
except ValueError:
pass
emit('wrong-dimension-control',n=9,rejected=True,divergent_boundary_rejected=True)
emit('complete',checked_entries=len(values),total_entries=len(entries),failures=failures,
known_answer_control=known,negative_control_rejected=negative,
mpmath=mp.__version__,working_dps=mp.mp.dps,elapsed_seconds=time.time()-start,
independence='mpmath Bessel functions; direct-t tanh-sinh quadrature; permutation determinant; closed forms and reflection formula',
limitations='Numerical quadrature agreement is heuristic; it is separate from the Arb enclosures.')
assert not failures