contour_check.py

back to table · edit · history · where entries came from · files · download

3816 bytes, as of the version from 2026-11-17 07:50 (current). Recorded here, not run.

"""Independent analytic presentation of g, AM equation (3.1).

Run: sage -python contour_check.py > contour-check.log
The required exact sample is below, including the near-zero and greatest-
cancellation arguments. Quadrature uses acb_calc at 400 bits, |y|<=100,
absolute and relative goals 2^-370. The positive y half suffices by conjugation.
The integrand is meromorphic; no branch-cut projection is used in quadrature.
The real projection is taken only after the rigorous complex integral.
Tail derivation and source passages are in contour-derivation.md.

Each CHECKPOINT_JSON line is a resumable per-argument result. Save the accumulated
rows as contour-checkpoint.json alongside this file to resume without repeating
successful quadrature. A checkpoint must come from this exact method/precision.
"""
import sys,json,time
from pathlib import Path
import numberdb.sage as numberdb
from sage.rings.real_arb import RealBallField
from sage.rings.complex_arb import ComplexBallField
from sage.rings.rational_field import QQ
import generate
from check_values import inside

R=RealBallField(400);C=ComplexBallField(400);pi=R.pi();i=C(0,1)
SAMPLE=['1','1/20','1/4','1/3','1/2','2/3','19/20','20/19','3/2','2','3','4','20','5/17','6/19']
T=100

def compute(x):
    lx=R(QQ(x)).log()
    def f(y,analytic):
        s=C(QQ(3)/2)+i*y
        return s.zeta()*(1-s).zeta()/(C.pi()*s).sin()*(s*lx).exp()
    q=C.integral(f,0,T,abs_tol=R(2)**-370,rel_tol=R(2)**-370,eval_limit=100000,depth_limit=30)
    tail=18*R(QQ(x))**(QQ(3)/2)/(pi*pi)*(-pi*T).exp()*((R(T)+QQ(1)/2)/pi+1/(pi*pi))
    v=(-(2*pi*R(QQ(x))).log()+R.euler_constant()+2*q.real())/pi
    v=v.add_error(tail)
    assert (q.real().is_finite() and q.imag().is_finite()) and v.is_finite() and v.accuracy()>=350
    return v,tail,q

def main():
    checkpoint=Path(__file__).with_name('contour-checkpoint.json')
    cached=json.loads(checkpoint.read_text()) if checkpoint.exists() else []
    rows={r['x']:r for r in cached}
    from numberdb._write import to_text
    for x in SAMPLE:
        if x in rows:
            assert rows[x]['working_bits']==400 and rows[x]['T']==100
            v=R(rows[x]['ball']); text=to_text(generate.evaluate({'x':x}),100)
            assert inside(v,text)
            rows[x]['number']=text; rows[x]['inside_stored_interval']=True
            print('REUSED',x,flush=True);continue
        start=time.time();v,tail,q=compute(x);text=to_text(generate.evaluate({'x':x}),100)
        assert inside(v,text)
        row={'x':x,'ball':str(v),'radius':str(v.rad()),'accuracy_bits':int(v.accuracy()),'tail_bound':str(tail),'quadrature':str(q),'seconds':time.time()-start,'working_bits':400,'T':100,'number':text,'inside_stored_interval':True}
        rows[x]=row
        print('CHECKPOINT_JSON '+json.dumps(row),flush=True)
    controls={x:rows[x]['inside_stored_interval'] for x in ['1','1/2','1/3','1/4']}
    # Reverse the sign of the integral on the known x=1 control.
    # For a cached probe, recover its integral from g and the elementary part.
    v=R(rows['1']['ball']);base=(-(2*pi).log()+R.euler_constant())/pi
    reversed_orientation=2*base-v
    assert not inside(reversed_orientation,rows['1']['number'])
    output={'stage':'build','method':'AM equation (3.1), upward contour, ds=i dy; positive y half and conjugation','sample':SAMPLE,'checked_entries':len(SAMPLE),'total_entries':255,'failures':[],'known_answer_control':all(controls.values()),'negative_control_rejected':True,'negative_control':'reversed contour orientation at x=1','rows':[rows[x] for x in SAMPLE],'limitations':'Only these 15 arguments are checked by contour integration. All 255 are independently checked by the finite Estermann formula. Both methods share Arb.'}
    print('CONTOUR_JSON '+json.dumps(output),flush=True)
if __name__=='__main__':main()