back to table · edit · history · where entries came from · files · download
7153 bytes, as of the version from 2026-11-01 21:05 (current). Recorded here, not run.
"""Independent numerical checks for numberdb.org/T660.
Run: sage -python checks.py
Requires generate.py. Reads entries.json beside this file if present;
otherwise reads the table API (an authorized key is needed while it is a draft).
The independent theta integral shares no numerical evaluation code with the
completed-zeta Taylor-series generator. See certification.md for tail bounds.
"""
import json
import math
import os
import sys
import time
from decimal import Decimal
from pathlib import Path
import numberdb.sage as numberdb
from sage.rings.complex_arb import ComplexBallField
from sage.rings.real_arb import RealBallField
from sage.rings.rational_field import QQ
from generate import jet, sign, finite, XiDerivativeZeros, interval
INTEGRATION_BITS=576
THETA_TERMS=10
UPPER_LIMIT=128
C=ComplexBallField(INTEGRATION_BITS)
R=RealBallField(INTEGRATION_BITS)
TOL=R(2)**-520
def zero_ball(radius):
return R(R(0).mid(),R(radius).upper())
def decimal_interval(text):
d=Decimal(text)
n,den=d.as_integer_ratio()
centre=QQ(n)/QQ(den)
ulp=QQ(10)**d.as_tuple().exponent
return centre-ulp,centre+ulp,ulp
def exponential_moment(j,a,U):
"""Exact formula for integral_U^infinity u^j exp(-a u) du, in balls."""
a,U=R(a),R(U)
return (-a*U).exp()*sum(R(math.factorial(j)//math.factorial(j-r))*U**(j-r)/a**(r+1) for r in range(j+1))
def moment_tail(j):
# theta_{ell>10}(u) <= 2 exp(-pi*121*u), u>=1.
# theta(u) <= 2 exp(-pi*u), and (log u/2)^j*u^-3/4 <= u^j.
return 2*(exponential_moment(j,R.pi()*(THETA_TERMS+1)**2,1)
+exponential_moment(j,R.pi(),UPPER_LIMIT))
def theta_derivative(t,m):
"""Rigorous Xi^(m)(t) by differentiated Mellin integral, for exact real t."""
t=C(t); pi=C.pi()
def integrand(u,analytic):
L=u.log(analytic=analytic)/2
q=(-pi*u).exp()
theta=sum(q**(ell*ell) for ell in range(1,THETA_TERMS+1))
co=(t*L).cos(); si=(t*L).sin()
trig=(co,-si,-co,si)
val=(t*t+C(QQ(1)/4))*L**m*trig[m%4]
if m: val+=2*m*t*L**(m-1)*trig[(m-1)%4]
if m>1: val+=m*(m-1)*L**(m-2)*trig[(m-2)%4]
return -(-3*L/2).exp()*theta*val
total=C(0)
for a,b in zip([1,2,4,8,16,32,64],[2,4,8,16,32,64,128]):
total+=C.integral(integrand,a,b,abs_tol=TOL,rel_tol=TOL)
if m==0: total+=C(QQ(1)/2)
assert not total.is_NaN() and finite(total.real()) and finite(total.imag())
assert total.imag().contains_zero()
tr=t.real()
tail=(tr*tr+R(1)/4)*moment_tail(m)
if m: tail+=2*m*abs(tr)*moment_tail(m-1)
if m>1: tail+=m*(m-1)*moment_tail(m-2)
result=total.real()+zero_ball(tail)
assert finite(result) and R(result.rad()) < R(10)**-145
return result
def controls():
known=C.integral(lambda u,analytic:u,1,2,abs_tol=TOL,rel_tol=TOL)
assert not known.is_NaN() and finite(known.real())
assert (known.real()-R(3)/2).contains_zero() and R(known.real().rad())<R(2)**-500
assert not (known.real()-R(5)/2).contains_zero()
exponential=C.integral(lambda u,analytic:(-C.pi()*u).exp(),1,2,abs_tol=TOL,rel_tol=TOL)
answer=((-C.pi()).exp()-(-2*C.pi()).exp())/C.pi()
assert finite(exponential.real()) and R(exponential.real().rad())<R(2)**-500
assert (exponential-answer).contains_zero()
atzero=theta_derivative(0,0)
assert R('0.49') < atzero < R('0.50')
assert atzero.overlaps(jet(0,0,640)[0])
# Mellin coefficients at the centre also test signs of even derivatives.
for m in [2,4]:
val=theta_derivative(0,m)
assert sign(val)==(-1)**(m//2)
assert val.overlaps(jet(0,m,640)[m])
return {'polynomial_integral':'3/2','exponential_integral':True,'incorrect_known_answer_rejected':True,'central_derivatives':[0,2,4]}
def fetch_records():
# check.stored requires a local Django database. The public API is the
# documented build-machine fallback and returns the same stored document.
doc=numberdb.table('T660')
from numberdb._generate import _stored_entries
assert list(doc['Parameters']) == ['m', 'k']
records = []
for identity, text in _stored_entries(doc).items():
m, k = identity.split(',')
records.append({'params': {'m': m, 'k': k}, 'number': text})
return records
def main(records=None):
start=time.monotonic()
control=controls()
print('CONTROLS',json.dumps(control),flush=True)
if records is None:
path=Path(__file__).with_name('entries.json')
records=json.loads(path.read_text()) if path.exists() else fetch_records()
expected=list(XiDerivativeZeros().enumerate())
assert [r['params'] for r in records]==expected
output=[]
for row in records:
m,k=int(row['params']['m']),int(row['params']['k'])
lo,hi,ulp=decimal_interval(row['number'])
# Independent endpoint signs certify the interval actually printed.
left=theta_derivative(lo,m);right=theta_derivative(hi,m)
assert sign(left)*sign(right)==-1,(m,k,'independent bracket')
# Direct higher-precision check of simplicity and displayed identities.
box=interval(lo,hi,640)
assert sign(jet(box,m+1,640)[m+1]),(m,k,'simplicity')
x=(lo+hi)/2
plus,minus=jet(x,m+1,640),jet(-x,m+1,640)
for j in range(m+2):
assert finite(plus[j]) and finite(minus[j])
assert (plus[j]-(-1)**j*minus[j]).contains_zero()
# Chain rule: use an s-direction Taylor jet, not the t-direction jet.
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
CC=ComplexBallField(640);P=PolynomialRing(CC,'z')
s=CC(QQ(1)/2,x)+P.gen()
L=m+2
f=s*(s-1)/2*((-s/2)*CC.pi().log())._exp_series(L)*(s/2)._gamma_series(L)*s._zeta_series(L)
for j in range(m+2):
value=CC(0,1)**j*math.factorial(j)*f[j]
assert not value.is_NaN() and finite(value.real())
assert (value-CC(plus[j])).contains_zero()
for offset in [-10,10]:
a,b=lo+offset*ulp,hi+offset*ulp
assert sign(jet(a,m,640)[m])==sign(jet(b,m,640)[m])!=0
proof={'m':m,'k':k,'left_sign':sign(left),'right_sign':sign(right),
'left_radius':str(left.rad()),'right_radius':str(right.rad())}
output.append(proof)
print('CHECKED',json.dumps(proof),flush=True)
result={'table':'T660','independent_method':'differentiated theta Mellin integral with rigorous quadrature and tails',
'entries':len(output),'independent_decimal_brackets':len(output),'simplicity_checks':len(output),
'parity_checks':len(output),'chain_rule_checks':len(output),'shifted_intervals_rejected':2*len(output),
'controls':control,'integration_bits':INTEGRATION_BITS,'theta_terms':THETA_TERMS,
'integration_upper_limit':UPPER_LIMIT,'quadrature_tolerance_bits':520,
'seconds':time.monotonic()-start,'rows':output}
print('CHECK_EVIDENCE_JSON',json.dumps(result),flush=True)
return result
if __name__=='__main__':
if os.environ.get('NUMBERDB_KEY_FROM_STDIN')=='1':
numberdb.configure(api_key=sys.stdin.read().strip())
main()