back to table · edit · history · where entries came from · files · download
6058 bytes, as of the version from 2026-11-17 14:09 (current). Recorded here, not run.
"""Builder's independent formulas for T738 (not the independent critique).
Run: sage -python check_values.py. Needs prepared-values.json in this directory;
set CHECK_DOCUMENT to a read-back table JSON to check stored intervals instead.
The roster below is independently transcribed from DPVZ Table 2.10. It does not
import the generator. Finite narrow Arb balls check the 11 disk cases; Barnes
integration checks 6 continued cases to 100 digits; 35-dps Abel quadrature
independently checks the rank-four relation on all 17, with controls. Barnes
and Abel quadrature are heuristic; no certified tail claim is made for them.
"""
import json,os,pathlib,time,math
import numberdb.sage as numberdb
from sage.rings.real_mpfr import RealField
from sage.rings.rational_field import QQ
from sage.rings.complex_arb import ComplexBallField
import mpmath as mp
ROOT=pathlib.Path(__file__).parent
HALF='1/2'
ROSTER=[
('2.2.2.2.2','-1/4',[HALF]*5),
('2.2.2.2.2','-4',[HALF]*5),
('2.2.2.2.2','-1/1024',[HALF]*5),
('2.2.2.2.2','-1024',[HALF]*5),
('2.2.2.3','27/64',[HALF]*3+['1/3','2/3']),
('2.2.2.3','-27',[HALF]*3+['1/3','2/3']),
('2.5','-3125/256',[HALF,'1/5','2/5','3/5','4/5']),
('2.2.2.4','1/16',[HALF]*3+['1/4','3/4']),
('2.3.4','-1/48',[HALF,'1/3','2/3','1/4','3/4']),
('2.3.4','-27/16',[HALF,'1/3','2/3','1/4','3/4']),
('2.3.6','-729/4096',[HALF,'1/3','2/3','1/6','5/6']),
('2.3.6','729/15625',[HALF,'1/3','2/3','1/6','5/6']),
('2.3.6','-1/512000',[HALF,'1/3','2/3','1/6','5/6']),
('2.4.6','-1/1024',[HALF,'1/4','3/4','1/6','5/6']),
('2.8','1/2401',[HALF,'1/8','3/8','5/8','7/8']),
('2.2.2.3','-18414+8235*sqrt(5)',[HALF]*3+['1/3','2/3']),
('2.2.2.3','-18414-8235*sqrt(5)',[HALF]*3+['1/3','2/3']),
]
def rat(s):
q=QQ(s);return mp.mpf(int(q.numerator()))/int(q.denominator())
def arg(identity):
if 'sqrt' in identity:
sign=1 if '+' in identity else -1
return 27*((-1+sign*mp.sqrt(5))/2)**15
return rat(identity)
def barnes(upper,z):
c=-min(upper)/2;normal=mp.fprod(mp.gamma(a) for a in upper)
def f(t):
s=c+1j*t
return (mp.fprod(mp.gamma(a+s) for a in upper)*mp.gamma(-s)
/mp.gamma(1+s)**(len(upper)-1)
*mp.exp(s*mp.log(-z))/normal).real/mp.pi
return mp.quad(f,[0,mp.mpf(1)/2,1,2,4,8,16,32,64,128])
def abel(upper,z):
reduced=list(upper);reduced.remove(mp.mpf(1)/2)
return 2/mp.pi*mp.quad(lambda t:mp.hyper(reduced,[1]*3,z*mp.sin(t)**2),
[0,mp.pi/16,mp.pi/8,mp.pi/4,mp.pi/2])
def agm_control(z):
a=mp.mpf(1);b=mp.sqrt(1-z)
for _ in range(20): a,b=(a+b)/2,mp.sqrt(a*b)
return 1/a
def accept(reference,number,digits=100):
# Exact numberdb decimal semantics: +/- one unit in last place.
from decimal import Decimal
center=mp.mpf(number);ulp=mp.power(10,Decimal(number).as_tuple().exponent)
return bool(mp.isfinite(reference) and abs(reference-center)<=ulp)
prepared=json.load(open(ROOT/'prepared-values.json'))
expected={(v['params']['template'],v['params']['z']):v['high200'] for v in prepared['values']}
document_path=os.environ.get('CHECK_DOCUMENT')
stored=None
if document_path:
doc=json.load(open(document_path))
# This build uses flat records. Refuse any unexpected format explicitly.
records=doc.get('Numbers',doc.get('Data'))
assert isinstance(records,list)
stored={(str(v['params']['template']),str(v['params']['z'])):str(v['number']) for v in records}
assert set(stored)==set(expected)
with mp.workdps(115):
v=barnes([mp.mpf(1)/2]*2,mp.mpf(-4));control=agm_control(mp.mpf(-4))
assert abs(v-control)<mp.mpf('1e-105')
assert accept(v,mp.nstr(control,100))
assert not accept(2*v,mp.nstr(control,100))
assert not accept(v,mp.nstr(control+mp.mpf('1e-95'),100))
print(json.dumps({'event':'controls','known_answer_control':True,
'negative_control_rejected':True,'Barnes_2F1_minus4':str(v),
'AGM_2F1_minus4':str(control),'origin':1}),flush=True)
assert abel([mp.mpf(1)/2]*5,0)==1
for template,identity,upper_strings in ROSTER:
t=time.monotonic()
with mp.workdps(115):
upper=[rat(a) for a in upper_strings];z=arg(identity)
if abs(z)<1:
C=ComplexBallField(512)
if 'sqrt' in identity:
sign=1 if '+' in identity else -1
zball=27*((-1+sign*C(5).sqrt())/2)**15
else: zball=C(QQ(identity))
ball=zball.hypergeometric([QQ(a) for a in upper_strings],[1]*4)
assert all(not x.is_NaN() and not x.is_infinity() for x in [ball.real(),ball.imag()])
assert ball.accuracy()>400 and ball.imag().contains_zero()
reference=mp.mpf(str(ball.real().mid()))
method='Arb direct _5F4, 512 bits, exact input enclosure'
detail={'ball':str(ball),'accuracy_bits':int(ball.accuracy())}
else:
reference=barnes(upper,z)
method='Barnes contour Re(s)=-min(alpha)/2, 115 dps, |Im(s)|<=128'
detail={}
truth=mp.mpf(expected[template,identity])
rel=abs(reference-truth)/abs(truth)
assert rel<mp.mpf('1e-103'),(identity,rel)
if stored is not None: assert accept(reference,stored[template,identity])
high_result=str(reference);rel_result=str(rel)
with mp.workdps(35):
v=abel([rat(a) for a in upper_strings],arg(identity))
abel_rel=abs(v-mp.mpf(expected[template,identity]))/abs(v)
assert mp.isfinite(v) and abel_rel<mp.mpf('1e-28'),(identity,abel_rel)
abel_result=str(v);abel_error=str(abel_rel)
print(json.dumps({'event':'check','params':{'template':template,'z':identity},
'method':method,'reference':high_result,'relative_discrepancy':rel_result,
'abel35':abel_result,'abel_relative_discrepancy':abel_error,
'stored_interval_checked':stored is not None,'seconds':time.monotonic()-t,**detail}),flush=True)
print(json.dumps({'event':'summary','checked_entries':17,'total_entries':17,
'failures':[],'known_answer_control':True,'negative_control_rejected':True}),flush=True)