"""Independently implemented integer interval proof for GEOMETRIC_LEMMA.md. Standard library only. Machin's identity for pi; explicit series remainders for logarithms, sine and exponential; isqrt for radicals. No other checker or search code is imported. Every arithmetic operation rounds outward. """ import json,argparse,hashlib,time from pathlib import Path from fractions import Fraction from math import isqrt if not __debug__:raise SystemExit('Refusing -O/-OO: assertions are part of the proof') Q=1<<200 def ceiling(n,d): assert d>0 return -((-n)//d) class I: def __init__(self,x=0,hi=None): if hi is not None:self.lo=int(x);self.hi=int(hi) elif isinstance(x,I):self.lo=x.lo;self.hi=x.hi else: v=Fraction(x);self.lo=v.numerator*Q//v.denominator;self.hi=ceiling(v.numerator*Q,v.denominator) assert self.lo<=self.hi def __add__(a,b): b=I(b);return I(a.lo+b.lo,a.hi+b.hi) __radd__=__add__ def __neg__(a):return I(-a.hi,-a.lo) def __sub__(a,b):return a+-I(b) def __rsub__(a,b):return I(b)+-a def __mul__(a,b): b=I(b);p=[a.lo*b.lo,a.lo*b.hi,a.hi*b.lo,a.hi*b.hi];return I(min(p)//Q,ceiling(max(p),Q)) __rmul__=__mul__ def __truediv__(a,b): b=I(b);assert b.lo>0 p=[(n*Q,d) for n in [a.lo,a.hi] for d in [b.lo,b.hi]] return I(min(n//d for n,d in p),max(ceiling(n,d) for n,d in p)) def __rtruediv__(a,b):return I(b)/a def __pow__(a,k): assert isinstance(k,int) and k>=0 r=I(1) while k: if k&1:r=r*a a=a*a;k//=2 return r def sqrt(a): assert a.lo>=0 l=isqrt(a.lo*Q);u=isqrt(a.hi*Q) if u*u0;assert len(nodes)==len(weights)>=2 and nodes[0]==c*c and nodes[-1]==R;assert all(nodes[j]0 for x in weights);assert sum(weights)==R pi=pi_interval();assert 3*Q0 and (U*U).hi<6*Q aa=(pi/(2*w))**2*(1-U*U/6)**2/X;delta=I(1-R);z=aa*delta*delta # Bound the numerator below and denominator above independently; # hence no dependency correlation is required for this enclosure. numerator=2*(6*aa).sqrt();denominator=(3*z*(2+z)).sqrt()+(4+6*z+3*z*z).sqrt();slope=numerator/denominator;assert slope.lo>I(ell).hi,('linear envelope',slope.bounds()) T=list(map(I,nodes));W=list(map(I,weights));B=[I(1)] for node in nodes[1:]: angle=pi*minus_log(node)/(2*w);sin=sin_interval(angle);assert sin.lo>0 y=sin*sin/X;hh=3*y*(2+y);root=hh.sqrt();g=2*root/(root+(hh+4).sqrt());assert 0=R;kB=int(d['second_tail_k']);assert kB>=1;t0,t1=map(F,[d['second_tail_t0'],d['second_tail_t1']]);assert Rnegative.hi,('second infinite tail',(tail-negative).bounds()) # Positive power recurrences and outward rounding for every moment. rp=I(R);powers=[I(1) for t in T];minsA=None;minsB=None;argA=argB=0 for k in range(1,max(kA,kB)): rp*=I(R);powers=[power*t for power,t in zip(powers,T)] if k0,('first moment',k,gap.bounds());relative=F(gap.lo,rp.hi) if minsA is None or relative0,('second moment',k,gap.bounds());relative=F(gap.lo,rp.hi) if minsB is None or relative