back to table · edit · history · where entries came from · files · download
4218 bytes, as of the version from 2026-12-02 03:41 (current). Recorded here, not run.
"""Alternate rigorous theta and positive-series check for T856.
sage -python bounded_series_check.py offline-results.json
No generator import. Replaces modular_lambda and both hypergeometric library
calls by explicit positive series with geometric tail bounds at 512 bits.
Elementary balls and gamma still share FLINT; check_values.py uses an alternate
library and integral formula. This is builder evidence, not a critic's verdict.
"""
import sys,json,hashlib
from pathlib import Path
from decimal import Decimal
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.rings.real_mpfi import RealIntervalField
PREC=512
R=RealBallField(PREC);I=RealIntervalField(PREC)
THETA_TERMS=20
HYP_TERMS=550
def tail(bound):
if not bound.is_finite() or not bound>0:raise ArithmeticError('Invalid positive tail')
return R(I(0,bound.upper()))
def alternative(r):
r=QQ(r);assert r>=1
q=(-R.pi()*R(r)).exp();assert 0<q<1
n=THETA_TERMS
s2=sum((q**(j*(j+1)) for j in range(n)),R(0))
s2+=tail(q**(n*(n+1))/(1-q**(2*n+2)))
th2=2*q**(QQ(1)/4)*s2
s3=sum((q**(j*j) for j in range(1,n)),R(0))
s3+=tail(q**(n*n)/(1-q**(2*n+1)))
th3=1+2*s3;x=(th2/th3)**4;assert 0<x<1
t2=R(1);h2=R(0);t3=R(1);h3=R(0)
for j in range(HYP_TERMS):
h2+=t2;h3+=t3
c2=(QQ(j)+QQ(1)/3)*(QQ(j)+QQ(2)/3)/((QQ(j)+QQ(4)/3)*(j+1))
c3=(QQ(j)+1)*(QQ(j)+QQ(4)/3)/((QQ(j)+2)*(QQ(j)+QQ(5)/3))
assert 0<c2<1 and 0<c3<1
t2*=c2*x;t3*=c3*x
# Each remaining term ratio is <x. t2,t3 are the first omitted terms.
h2+=tail(t2/(1-x));h3+=tail(t3/(1-x))
c=R(QQ(2)/3).gamma()/R(QQ(1)/3).gamma()**2*3*x**(QQ(1)/3)*h2
d=x*h3/(R(QQ(1)/3).gamma()*R(QQ(2)/3).gamma())
v=c-d
assert v.is_finite() and 0<v<c<1 and v.accuracy()>470
return v,x
def bounds(v):
b=I(v)
return Fraction(str(b.lower().exact_rational())),Fraction(str(b.upper().exact_rational()))
def stored(text):
d=Decimal(text);u=Fraction(10)**d.as_tuple().exponent;c=Fraction(d)
return c-u,c+u
def narrow_overlap(a,b):
if not a.is_finite() or not b.is_finite():return False
if a.accuracy()<330 or b.accuracy()<330:return False
return a.overlaps(b)
def main():
source=Path(sys.argv[1]) if len(sys.argv)>1 else Path(__file__).with_name('offline-results.json')
data=json.loads(source.read_text());out=[];failures=[]
square=R(QQ(1)/4)+R(3).sqrt()/(4*R.pi())*(3*R(3).log()-4*R(2).log())
av,_=alternative('1');_,x2=alternative('2')
known=narrow_overlap(av,square) and narrow_overlap(x2,17-12*R(2).sqrt())
bad=not narrow_overlap(av,square+R(QQ(1)/1000))
bad=bad and not narrow_overlap(av,R('nan')) and not narrow_overlap(av,R(I(0,1)))
if not known or not bad:failures.append('controls')
for row in data['entries']:
r=row['params']['r'];v,x=alternative(r);lo,hi=bounds(v);sl,sh=stored(row['number'])
overlap=lo<=Fraction(row['upper']) and Fraction(row['lower'])<=hi
containment=sl<=lo<=hi<=sh
if not overlap or not containment:failures.append(r)
out.append({'r':r,'lower':str(lo),'upper':str(hi),'accuracy_bits':int(v.accuracy()),
'overlaps_generator_ball':bool(overlap),'stored_contains_alternate':bool(containment)})
result={'table':'T856','stage':'builder explicit-series check; not an independent verdict',
'program_sha256':hashlib.sha256(Path(__file__).read_bytes()).hexdigest(),
'input_sha256':hashlib.sha256(source.read_bytes()).hexdigest(),
'skill_manifest':'../20261128T131351Z-build-skills/manifest.json',
'skill_bundle_sha256':'f20b09e3db5fd443660c0c6b29391ee369b7c710a43e22d8abb971ec3f54dd14',
'checked_entries':len(out),'total_entries':len(data['entries']),'failures':failures,
'known_answer_control':bool(known),'negative_control_rejected':bool(bad),
'working_bits':PREC,'theta_terms':THETA_TERMS,'hypergeometric_terms':HYP_TERMS,
'minimum_accuracy_bits':min(t['accuracy_bits'] for t in out),'entries':out}
print(json.dumps(result,indent=2))
if failures:raise SystemExit(1)
if __name__=='__main__':main()