back to table · edit · history · where entries came from · files · download
6101 bytes, as of the version from 2026-12-02 04:36 (current). Recorded here, not run.
"""Focused repair check, no uploads. All Sage work uses agents/sage.sh.
Run from repository cwd: python3 /path/repair_theta_check.py --collect
DLMF 20.2.1: theta1(u,e^-pi)=2 sum (-1)^n exp(-pi(n+1/2)^2) sin((2n+1)u).
For |Im u|<=B, omitted absolute terms n>=K are at most
2 exp(-pi(K+1/2)^2+(2K+1)B)/(1-exp(-pi(2K+2)+2B)).
Successive bounds decrease geometrically from n=K. We use B=4 for all
complex sample arguments and B=0 for the derivative at zero. The derivative
tail includes the ratio (2K+3)/(2K+1). Add errors before sigma evaluation.
This checks the unchanged sigma formula at six representative stored lifts;
it does not regenerate or upload entries. All 167 prior independent checks
are retained only with explicitly checked unchanged mathematical inputs.
"""
import sys,json,subprocess,re,platform
from pathlib import Path
from fractions import Fraction
if sys.argv[1:]==['--collect']:
w=Path(__file__).resolve().parent
p=subprocess.run(['agents/sage.sh',str(Path(__file__).resolve()),str(w/'repair-check-input.json')],stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True)
(w/'repair-theta-check.log').write_text(p.stdout)
marker='REPAIR_THETA_JSON='
if marker not in p.stdout:
print(p.stdout[-3000:]);sys.exit(p.returncode or 1)
r=json.loads(p.stdout.split(marker,1)[1]);(w/'repair-theta-results.json').write_text(json.dumps(r,indent=2)+'\n')
print(json.dumps({k:r[k] for k in ['checked_entries','total_entries','failures','known_answer_control','negative_control_rejected','maximum_component_radius']},indent=2))
sys.exit(p.returncode)
import numberdb.sage as numberdb
from sage.rings.rational_field import QQ
from sage.rings.real_arb import RealBallField
from sage.rings.complex_arb import ComplexBallField
from sage.env import SAGE_VERSION
R=RealBallField(640);C=ComplexBallField(640);pi=R.pi();K=30
threshold=R(10)**-130
def theta(c):
u=pi*C(c)
assert abs(u.imag())<4
s=sum((2*(1-2*(n%2))*(-pi*QQ((2*n+1)**2)/4).exp()*((2*n+1)*u).sin() for n in range(K)),C(0))
B=R(4)
tail=2*(-pi*QQ((2*K+1)**2)/4+(2*K+1)*B).exp()/(1-(-pi*(2*K+2)+2*B).exp())
e=R(0).add_error(tail)
return s+C(e,e)
def derivative():
s=sum((2*(1-2*(n%2))*(2*n+1)*(-pi*QQ((2*n+1)**2)/4).exp() for n in range(K)),R(0))
ratio=QQ(2*K+3)/(2*K+1)*(-pi*(2*K+2)).exp()
tail=2*(2*K+1)*(-pi*QQ((2*K+1)**2)/4).exp()/(1-ratio)
return s.add_error(tail)
def narrow(z):
z=C(z)
return all(v.is_finite() and R(v.rad())<threshold for v in [z.real(),z.imag()])
def agrees(x,y):
return bool(narrow(x) and narrow(y) and C(x).overlaps(C(y)))
def q(text):
f=Fraction(text);return QQ(f.numerator)/f.denominator
def component(text):
if text.startswith('['):
lo,hi=text[1:-1].split(',');return q(lo),q(hi)
v=q(text)
if '.' not in text and 'e' not in text.lower():return v,v
mant,_,ex=text.lower().partition('e');ulp=QQ(10)**(int(ex or '0')-len(mant.partition('.')[2]));return v-ulp,v+ulp
def bounds(text):
s=re.sub(r'\s+','',text)
if 'i*' not in s:return [component(s),(QQ(0),QQ(0))]
left,right=s.split('i*');sign=-1 if left.endswith('-') else 1
left=left[:-1] if left.endswith(('+','-')) else left
lo,hi=component(right)
return [component(left or '0'),(lo,hi) if sign>0 else (-hi,-lo)]
pa=theta(QQ(1)/3);pb=theta(QQ(4)/3);pc=theta(QQ(7)/3)
D=derivative();I=C(0,1)
controls={'theta_origin':agrees(theta(0),0),'theta_nonzero':bool(narrow(pa) and pa.real()>QQ(1)/2),'theta_pi_antiperiod':agrees(pa,-pb),'theta_two_pi_period':agrees(pa,pc),'theta_prime_nonzero':bool(D>QQ(1)/2 and narrow(D))}
neg={'false_pi_period_rejected':not agrees(pa,pb),'wrong_theta_sign_rejected':not agrees(pa,-pa),'nan_rejected':not agrees(C(R('nan'),0),pa),'wide_ball_rejected':not agrees(C(R(0).add_error(R(10)**20),0),pa)}
packet=json.loads((Path(__file__).parent/'repair-check-input.json').read_text())
sample=[(2,1,0),(2,0,1),(3,1,2),(4,1,3),(4,3,1),(8,7,7)]
comparisons=[];failures=[];worst=R(0)
for key in sample:
row=next(r for r in packet['records'] if tuple(int(r['params'][k]) for k in ('N','a','b'))==key)
N,a,b=key;z=C(QQ(a)/N,QQ(b)/N)
value=(pi*z*z/2).exp()*theta(z)/(pi*D)
contained=[]
for j,(ball,(lo,hi)) in enumerate(zip([value.real(),value.imag()],bounds(row['number']))):
if lo==hi:
zero_proved=(a==0 or (4*a==N and 4*b==3*N)) if j==0 else (b==0 or (4*a==3*N and 4*b==N))
ok=lo==0 and zero_proved and narrow(value) and ball.contains_zero()
else:ok=narrow(value) and lo<=ball.lower().exact_rational() and ball.upper().exact_rational()<=hi
contained.append(bool(ok));worst=max(worst,R(ball.rad()))
if not all(contained):failures.append({'key':key,'contained':contained})
comparisons.append({'key':key,'stored':row['number'],'theta_sigma_enclosure':str(value),'component_pass':contained})
# A missing exponential and a period-one theta argument must fail on a mixed lift.
if key==(3,1,2):
neg['missing_sigma_exponential_rejected']=not agrees(value,theta(z)/(pi*D))
neg['missing_pi_in_theta_argument_rejected']=not agrees(value,(pi*z*z/2).exp()*theta(z/pi)/(pi*D))
for name,ok in {**controls,**neg}.items():
if not ok:failures.append({'control':name})
result={'table':'T911','scope':'repair checks; six sampled unchanged sigma values plus theta period controls, no new independent verdict','checked_entries':len(sample),'total_entries':len(packet['records']),'failures':failures,'known_answer_control':all(controls.values()),'negative_control_rejected':all(neg.values()),'controls':controls,'negative_controls':neg,'period_values':{'theta1(pi/3)':str(pa),'theta1(4pi/3)':str(pb),'theta1(7pi/3)':str(pc)},'theta_prime_zero':str(D),'working_bits':640,'terms':K,'comparisons':comparisons,'maximum_component_radius':str(worst),'sources':['https://dlmf.nist.gov/20.2#E1','https://dlmf.nist.gov/20.2#E6','https://dlmf.nist.gov/23.6#E9'],'versions':{'Sage':SAGE_VERSION,'Python':platform.python_version(),'numberdb':numberdb.__version__},'skill_manifest':'agents/runs/20261202T042924Z-repair-skills/manifest.json','skill_bundle_sha256':'7d5d33191e95ac0ecbe6ea08138f5e72999e7300d2030b1b43004895de61bca0'}
print('REPAIR_THETA_JSON='+json.dumps(result,sort_keys=True))
assert not failures