"""Interval certificate at h=2^-14, treating empty large-factor groups separately.""" from fractions import Fraction as F from math import factorial from mpmath import iv from window_ballot21 import exact, BASE, spectrum_coefficients, sine_grid, support iv.dps=42 I=iv.mpf LAM=F(27,20) EPS=F(1,8192) B=F(33,2) # reciprocal of the physical cutoff b RHO=35*EPS*B KAPPA=4/iv.pi EM=I('.577216') SCALES=[(F(9,4),9260),(F(31,100),546),(F(1,10),129), (F(45,1000),33),(F(23,1000),19),(F(9,1000),13)] assert sum(c for r,c in SCALES)==10000 def eu(z): assert z<12 return sum(z**j/(factorial(j)*j) for j in range(1,65))+2*z**65/(65*factorial(65)) def density_checks(): T=32768;unit=10**15 m=[unit]*(2*T+1) bounds={2:F(5672,10000),3:F(565,1000),4:F(562,1000),6:F(5616,10000)} for j in range(2*T,8*T): m.append(m[j]+(m[j+1-T]+j-T-1)//(j-T)) cutoff=max(i for i in bounds if i*T<=j) b=bounds[cutoff] assert m[j+1]*T*b.denominator=6:return F(5616,10000) if x>=4:return F(562,1000) if x>=3:return F(565,1000) return max(F(5672,10000),1/x) def signed(x): n=int(x-1) c=F(1) if n<2 else F(62,100) if n==2 else F(3,10) return c/(x*factorial(n)) def pbound(s): a=max(F(1),(F(1,2)-35*EPS/2)*B-s) h=max(F(1),(B-s)/2) return (omega(a)*omega(h)+signed(a)*signed(h))/2 def to_floor(x): return int(iv.floor(x.a)) if hasattr(iv,'floor') else int(x.a) def poisson(): # Independent upper rounding of the jumps above 1/T. The discarded # first interval has the scale-invariant total X'/T. T=256; K=20; unit=10**28;lam=exact(LAM) a=[0,0];upper=[I(0),I(0)] for j in range(2,T+1): x=j*lam*iv.log(I(j)/(j-1)) a.append(to_floor(x*unit));upper.append(x.b) nmax=int(B*T)+T+1 prob=[to_floor(unit*T**(-lam))] cum=0; upper_tail=[I(1)] for n in range(1,nmax+1): prob.append(sum(a[j]*prob[n-j] for j in range(2,min(n,T)+1))//(n*unit)) cum+=prob[n-1] upper_tail.append((1-I(cum)/unit).b) rare=iv.exp(lam*eu(I(3))-3*K) moment_rare=rare*lam*(iv.exp(3)-1)/3 rho=exact(RHO) mean=sum(upper)/T remainder=((rho+mean)*rare+moment_rare/T).b def moment(t): n=max(0,-((-t*T+K)//1)) tail=upper_tail[n] return ((rho+F(K,T).numerator/I(F(K,T).denominator))*tail+ sum(upper[j]*upper_tail[max(n-j,0)] for j in range(2,T+1))/T+remainder).b return moment def first(): density_checks() M=poisson();r=exact(RHO);lam=exact(LAM) p=pbound(F(0)) upper=(exact(p*p)*support(r,lam)).b for j in range(int(B*10)): u=F(j,10) pnew=pbound(u+F(1,10)) assert pnew>=p if pnew>p: upper+=(exact(pnew*pnew-p*p)*M(u)).b p=pnew assert p==1 print('compound Poisson first factor square',upper,flush=True) return upper.b def bands(mesh=9): coeff,square=spectrum_coefficients() const=exact(square.pop(0)) oscill=[(k,exact(2*d/k)) for k,d in square.items() if d] dy=iv.pi/BASE def primitive(n): return const*dy*n+sum(c*sine_grid((n*k)%(4*BASE)) for k,c in oscill) lam=exact(LAM); kappa=4/iv.pi cutoff=1/(exact(EPS)*exact(B)) # K(x) has a positive last term at index 25, and the unused tail alternates. ks=[exact(F(2*(-1)**(j+1),factorial(2*j)*(2*j-1)*(2*j))) for j in range(1,26)] rr=[(exact(r),exact(F(c,10000))*exact(r)**lam) for r,c in SCALES] J=400 C=(kappa*EM+(8/iv.pi)*(sum(iv.log(n)/(4*n*n-1) for n in range(2,J+1))+ (iv.log(J)+1)/(J*(4-I(1)/(J+1)**2)))).b def abs_exp(y): t=max((y*cutoff).b,I(8)) return (iv.exp(C+8/(iv.pi*t))*t**kappa).b def regular(y): t=max(y.b,I('.04'));v=t*cutoff z=t*iv.exp(min((2/v).b,(1/v+2/v**2).b)) den=I(0) for r,c in rr: x=r*y if x.b>16:continue xx=x*x h=ks[-1] for cc in reversed(ks[:-1]): h=cc+xx*h den+=c*iv.exp(-xx*h.b/lam) assert den.a>0 return (z**(2/lam)*iv.exp(lam*(1-I('.57721566')))/den).b n=32;y0=dy*n near=exact(sum(abs(d)*F(k,2)**4/24 for k,d in coeff.items())) energy=(near**2*y0**3*regular(y0)/3).b absolute=(near*y0**2*abs_exp(y0)/2).b prev=primitive(n);cells=0 while n<256*BASE: step=1<=0 x=dy*m energy+=(a*regular(x)/(dy*n)**6).b absolute+=(iv.sqrt(dy*(m-n)*a)*abs_exp(x)/(dy*n)**3).b cells+=1;n=m;prev=nxt Y=dy*n c=exact(sum(abs(d) for d in coeff.values())) wr=I('1.5');zz=2*iv.pi/wr;sc=(iv.exp(zz)-iv.exp(-zz))/(2*zz) power=I('2.5')-lam/2-1/lam tail=(wr**(lam/2)*c*I(2)**(1/lam)*sc**(1/(2*lam))*iv.exp(2/(lam*cutoff*Y)) *Y**(-power)/(iv.sqrt(I(5))*(1-I(2)**(-power)))).b absolute+=(c*iv.exp(C+8/(iv.pi*cutoff*Y))*cutoff**kappa*Y**(kappa-2)/(2-kappa)).b print('spectral finite, tail, empty L1, cells',iv.sqrt(energy).b,tail,absolute,cells,flush=True) return (iv.sqrt(energy)+tail).b,absolute.b def run(): a=first() spec,ab=bands() lam=exact(LAM);e=exact(EPS);binv=exact(B) # Tail uses original exponential weights. Uniform Euler E1 error is # smaller than exp(-100) there. Clipped linear weights are exact. reg=(iv.exp((lam/2+1/lam)*EM+iv.exp(-100))*(e*binv)**(I('1.5')-lam/2-1/lam)* iv.sqrt(a)*spec/(4*iv.sqrt(iv.pi))).b q=I('2.4');q2=I('3.3') exc=(e*ab/(4*iv.pi)*(2*binv*iv.exp(2*eu(q)-q*(I('.5')-35*e/2)*binv) +2*iv.exp(2*eu(q2)-q2*(binv-1)))).b bound=(I('3.440568')*(reg+exc)/2).b print('p 14 1/b',B,'regular',reg,'empty',exc,'switched relative upper',bound,flush=True) assert bound<1 if __name__=='__main__':run()