back to table · edit · history · where entries came from · files · download
4617 bytes, as of the version from 2026-12-02 03:41 (current). Recorded here, not run.
"""Builder's alternate formula/library check for T856; no review verdict.
sage -python check_values.py offline-results.json
Uses mpmath theta constants and smooth integrals from Kleban--Zagier (4),(9),
not the generator or FLINT hypergeometric implementation. The inner integral
in (9) is the incomplete beta integral B_t(2/3,2/3). t=x*s^3 removes the outer
endpoint singularity. mpmath quadrature is independent numerical agreement,
not a rigorous error certificate. The production/explicit series supply balls.
"""
import json,sys,hashlib,time
from pathlib import Path
from fractions import Fraction
from decimal import Decimal
import mpmath as mp
mp.mp.dps=160
def fmp(q):
q=Fraction(q)
return mp.mpf(q.numerator)/q.denominator
def stored_bounds(text):
d=Decimal(text);e=d.as_tuple().exponent
ulp=Fraction(10)**e
mid=Fraction(d)
return mid-ulp,mid+ulp,ulp
def integral_value(r, complement=False):
r=fmp(r);q=mp.exp(-mp.pi*r)
x=(mp.jtheta(2,0,q)/mp.jtheta(3,0,q))**4
if complement:x=1-x
third=mp.mpf(1)/3
cardy=3*x**third/mp.beta(third,third)*mp.quad(lambda s:(1-x*s**3)**(-2*third),[0,1])
difference=3*x**third/(mp.sqrt(3)*mp.pi)*mp.quad(lambda s:(1-x*s**3)**(-2*third)*mp.betainc(2*third,2*third,0,x*s**3),[0,1])
return cardy-difference,x,cardy,difference
def matches(text,value):
if not mp.isfinite(value):return False
lo,hi,ulp=stored_bounds(text)
return fmp(lo)+mp.mpf('1e-140')*abs(value)<value<fmp(hi)-mp.mpf('1e-140')*abs(value)
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());results=[];failures=[]
square=mp.mpf(1)/4+mp.sqrt(3)/(4*mp.pi)*(3*mp.log(3)-4*mp.log(2))
square_value,*_=integral_value('1')
square_control=abs(square-square_value)<mp.mpf('1e-150') and mp.mpf('.3221')<square<mp.mpf('.3222')
_,x2,_,_=integral_value('2')
lambda_control=abs(x2-(17-12*mp.sqrt(2)))<mp.mpf('1e-150')
negative=not matches(data['entries'][0]['number'],square+mp.mpf('0.001'))
wrong_color=not matches(data['entries'][0]['number'],2*square)
nan_rejected=not matches(data['entries'][0]['number'],mp.nan)
if not all([square_control,lambda_control,negative,wrong_color,nan_rejected]):failures.append('controls')
for row in data['entries']:
start=time.monotonic();r=row['params']['r'];value,x,c,d=integral_value(r)
lo,hi,ulp=stored_bounds(row['number']);mid=(lo+hi)/2
ok=matches(row['number'],value)
elliptic_residual=abs(mp.ellipk(1-x)/mp.ellipk(x)-fmp(r))
bounds=(0<value<c<1 and d>0)
good=ok and bounds and elliptic_residual<mp.mpf('1e-145')
if not good:failures.append(r)
item={'r':r,'independent_value':mp.nstr(value,155),'contained_in_stored_interval':bool(ok),
'absolute_midpoint_error_ulps':mp.nstr(abs(value-fmp(mid))/fmp(ulp),12),
'elliptic_aspect_residual':mp.nstr(elliptic_residual,8),
'event_bounds':bool(bounds),'seconds':round(time.monotonic()-start,3)}
results.append(item);print('CHECK_ROW_JSON:'+json.dumps(item),flush=True)
symmetry=[]
for r in ['8/7','3/2','2']:
v,_,_,_=integral_value(r);v2,_,_,_=integral_value(r,True)
err=abs(v-v2);ok=err<mp.mpf('1e-145')
symmetry.append({'r':r,'complement_error':mp.nstr(err,8),'pass':bool(ok)})
if not ok:failures.append('complement '+r)
out={'table':'T856','stage':'builder alternate checks; independent-actor critique still required',
'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',
'working_decimal_digits':mp.mp.dps,'mpmath':mp.__version__,
'checked_entries':len(results),'total_entries':len(data['entries']),'failures':failures,
'known_answer_control':bool(square_control and lambda_control),
'negative_control_rejected':bool(negative and wrong_color and nan_rejected),
'controls':{'square_closed_form':bool(square_control),'lambda_at_two':bool(lambda_control),
'shifted_probability_rejected':bool(negative),'two_color_factor_rejected':bool(wrong_color),'nan_rejected':bool(nan_rejected)},
'symmetry_checks':symmetry,'entries':results}
print('CHECK_RESULT_JSON:'+json.dumps(out),flush=True)
if failures:raise SystemExit(1)
if __name__=='__main__':main()