back to table · edit · history · where entries came from · files · download
6619 bytes, as of the version from 2026-12-01 03:36 (current). Recorded here, not run.
"""T882 checks using the convergent Ei series and regularized PV quadrature.
Run with SageMath, numberdb and mpmath: sage -python checks.py
Place entry.json (a record with a number string) beside this script. The
certificate tests the exact rational endpoints of the WRITTEN interval.
The generator's Ei routine is never used in the series certificate. Arb gamma
and log primitives are shared; mpmath quadrature and root comparisons supply
additional implementation and normalization checks, not certified error bounds.
"""
import json,sys,math,platform,importlib.metadata
from pathlib import Path
from fractions import Fraction
import numberdb.sage as numberdb
from sage.rings.rational_field import QQ
from sage.rings.real_arb import RealBallField
from sage.env import SAGE_VERSION
import mpmath as mp
HERE=Path(__file__).resolve().parent
def rational(text):
f=Fraction(str(text)); return QQ(f.numerator)/f.denominator
def ei_series(r, decimal_digits=200):
"""DLMF 6.6.1, with a rigorous nonnegative geometric tail.
t[k+1]/t[k] = r*k/(k+1)^2 <= r/4 for every integer k>=1.
On the positive balls used here, q=upper(r)/4<1. After t_N the
omitted positive tail is bounded by upper(t_{N+1})/(1-q).
"""
field=r.parent()
assert r.is_finite() and r>0
q=r.upper().exact_rational()/4
assert q<1
total=field(0);term=r; k=1
threshold=QQ(1)/10**(decimal_digits+35)
while True:
total+=term
next_term=term*r*k/(k+1)**2
tail=next_term.upper().exact_rational()/(1-q)
if tail<threshold:break
term=next_term;k+=1
result=field.euler_constant()+r.log()+total+field(0).union(field(tail))
assert result.is_finite()
return result, {'terms':k,'tail_bound':str(tail),'radius':str(result.rad())}
def certify_written(text):
field=RealBallField(896)
center=rational(text); ulp=QQ(1)/10**len(text.split('.')[1])
low,high=center-ulp,center+ulp
assert low>1 and high-low==2*ulp
left,el=ei_series(field(low).log())
right,er=ei_series(field(high).log())
assert left.rad().exact_rational()<ulp/10**100
assert right.rad().exact_rational()<ulp/10**100
return bool(left<0 and right>0), {'lower':str(low),'upper':str(high),
'ulp':str(ulp),'left_Ei_log':str(left),'right_Ei_log':str(right),
'left_series':el,'right_series':er}
# Exact coefficients of 1/log(1+z)-1/z, through z^30. This local expansion
# is used only for numerical quadrature where |z|<1e-10. Its omitted terms
# are far below the 200-digit quadrature comparison scale; no rigorous
# quadrature certification is claimed.
b=[QQ(1)]
for n in range(1,32):
b.append(-sum(((-1)**j*QQ(1)/(j+1))*b[n-j] for j in range(1,n+1)))
def pv_li(y):
coeff=[mp.mpf(str(c.numerator()))/int(c.denominator()) for c in b[1:]]
def h(t):
if t==0:return mp.mpf(1)
z=t-1
if abs(z)<mp.mpf('1e-10'):
return mp.polyval(list(reversed(coeff)),z)
return 1/mp.log(t)-1/z
# For 0<t<1/2, t=exp(-u) resolves the logarithmic endpoint.
def lower_integrand(u):
if mp.isinf(u):return mp.mpf(0)
t=mp.exp(-u)
return t*(-1/u+1/(-mp.expm1(-u)))
lower=mp.quad(lower_integrand,[mp.log(2),1,2,4,8,16,32,64,128,256,512,1024,mp.inf])
points=[mp.mpf('0.5'),mp.mpf('0.9'),mp.mpf(1),mp.mpf('1.1'),y]
points=sorted(set(p for p in points if p<=y))
return mp.log(y-1)+lower+mp.quad(h,points)
def run():
raw=json.loads((HERE/'entry.json').read_text());text=raw['number']
okay,certificate=certify_written(text);assert okay
center=rational(text);ulp=QQ(1)/10**len(text.split('.')[1])
wrong=str(Fraction(str(center+4*ulp)))
# A shifted interval has both signs positive; it must fail.
shifted=QQ(center+4*ulp)
R=RealBallField(896)
lo,_=ei_series(R(shifted-ulp).log());hi,_=ei_series(R(shifted+ulp).log())
negative=bool(not(lo<0 and hi>0));assert negative
one,_=ei_series(R(1));control=R(1).Ei()
assert one.is_finite() and one.rad().exact_rational()<QQ(1)/10**220
assert one.overlaps(control) and one>1
# Nonfinite and vacuous intervals do not qualify as certificates.
assert not R('nan').is_finite()
assert R(0).union(R(10)).rad().exact_rational()>ulp
comparisons=[]
for dps in (150,200):
with mp.workdps(dps+45):
root=mp.findroot(mp.ei,(mp.mpf('0.25'),mp.mpf('0.5')))
mu=mp.exp(root);c=mp.mpf(text);unit=mp.mpf(1)/10**99
distance=abs(mu-c)/unit;assert distance<1
pv=pv_li(c)
at_e=pv_li(mp.e);expected_e=mp.euler+mp.quad(lambda t:mp.expm1(t)/t if t else mp.mpf(1),[0,1])
at_two=pv_li(mp.mpf(2));expected_two=mp.ei(mp.log(2))
tolerance=mp.mpf(10)**(-dps+10)
assert abs(at_e-expected_e)<tolerance and expected_e>1
assert abs(at_two-expected_two)<tolerance and at_two>1
assert abs(pv)<4*unit
assert abs(pv-at_two)>1 # Wrong offset normalization is detected.
assert mp.nstr(mu,22).startswith('1.451369234883381050284')
assert mp.nstr(root,22).startswith('0.372507410781366634462')
comparisons.append({'dps':dps,'working_dps':dps+45,
'r0':mp.nstr(root,dps),'mu':mp.nstr(mu,dps),
'distance_ulp':mp.nstr(distance,20),
'PV_li_written_center':mp.nstr(pv,30),
'PV_e_nonzero':mp.nstr(at_e,35),
'PV_e_error':mp.nstr(at_e-expected_e,20),
'PV_2_nonzero':mp.nstr(at_two,35),
'PV_2_error':mp.nstr(at_two-expected_two,20),
'wrong_offset_residual':mp.nstr(pv-at_two,30)})
versions={'python':platform.python_version(),'SageMath':SAGE_VERSION,'mpmath':mp.__version__,'numberdb':numberdb.__version__}
for d in importlib.metadata.distributions():
name=d.metadata.get('Name','')
if ('flint' in name.lower() or 'arb' in name.lower()):versions[name]=d.version
result={'table':'T882','entry':text,'checked_entries':1,'total_entries':1,'failures':[],
'known_answer_control':True,'negative_control_rejected':negative,
'series_certificate':certificate,'Ei_one_control':str(one),'comparisons':comparisons,
'versions':versions,'skill_manifest':'../20261201T022104Z-build-skills/manifest.json',
'independence':'Explicit DLMF series vs generator Arb Ei. Gamma/log ball primitives shared. mpmath root and regularized PV quadrature are extra independent implementation checks; quadrature errors are comparison evidence only.'}
print('NUMBERDB_CHECKS_JSON='+json.dumps(result))
if __name__=='__main__':run()