"""Outward quadrature of the four-tent profile and overlapping frequency weights.""" from collections import defaultdict from functools import lru_cache from fractions import Fraction as F from math import factorial from mpmath import iv iv.dps = 39 I = iv.mpf LAMBDA = F(27,20) FREQ = (F(13,20), F(5), F(15,2), F(16), F(24), F(54), F(81), F(192), F(320)) MIX = tuple(F(n,10000) for n in (9310,440,120,35,55,20,5,10,5)) assert sum(MIX) == 1 BASE = 8192 # Grid spacing is pi/BASE. All frequencies are half-integers. def exact(x): f=F(x) return I(f.numerator)/f.denominator def spectrum_coefficients(): # P(y) = D(y)/y^3, where D is an even trigonometric polynomial. coeff=defaultdict(F) for a,weight in ((2,F(3,10)),(3,F(3,10)),(4,F(1,5)),(6,F(1,5))): c=8*weight/(a-F(1,2)) for k,d in ((1,c),(4*a-1,-c),(2*a+1,-c/2),(6*a-1,c/2)): coeff[k]+=d assert sum(coeff.values())==sum(d*k*k for k,d in coeff.items())==0 square=defaultdict(F) for i,a in coeff.items(): for j,b in coeff.items(): square[abs(i-j)]+=a*b/2 square[i+j]+=a*b/2 return coeff,square @lru_cache(maxsize=None) def sine_grid(n): return iv.sin(iv.pi*n/(2*BASE)) def spectrum(p,binverse, mesh=9, end=256): eps=exact(F(2,2**p)) b=exact(F(1,binverse)) lam=exact(LAMBDA) coeff,square=spectrum_coefficients() s0=exact(square.pop(0)) oscillatory=[(k,exact(2*d/k)) for k,d in square.items() if d] scale=iv.pi/BASE def primitive(n): return s0*scale*n+sum(c*sine_grid((n*k)%(4*BASE)) for k,c in oscillatory) def weight(x): # y exp(-Ci(by/eps)) is nondecreasing. Bound at a positive right endpoint. t=max(x.b,I('.04').b) u=b*t/eps z=t*iv.exp(min((2/u).b,(1/u+2/u**2).b)) den=I(0) for w,c,wmlam in prepared: y=iv.pi*x/w # 1/sinhc remains well scaled at a very large argument. inv=2*y*iv.exp(-y)/(1-iv.exp(-2*y)) den+=c*wmlam*inv**(1/lam) return (z**(2/lam)/den).b prepared=[(exact(w),exact(c),exact(w)**(-lam)) for w,c in zip(FREQ,MIX)] n=32; y0=scale*n K=exact(sum(abs(d)*F(k,2)**4/24 for k,d in coeff.items())) total=(K**2*y0**3*weight(y0)/3).b fa=primitive(n) cells=0 while n=0 total+=(area*weight(scale*m)/(scale*n)**6).b cells+=1 n=m;fa=fm finite=iv.sqrt(total).b ub=scale*n # Direct summation of the dyadic tails beyond the finite-band mixture. c=exact(sum(abs(d) for d in coeff.values())) wr=I('1.5'); z=2*iv.pi/wr sc=(iv.exp(z)-iv.exp(-z))/(2*z) power=I('2.5')-lam/2-1/lam tail=(wr**(lam/2)*c*I(2)**(1/lam)*sc**(1/(2*lam)) *iv.exp(2*eps/(lam*b*ub))*ub**(-power)/(iv.sqrt(I(5))*(1-I(2)**(-power)))).b print('p',p,'upper finite spectrum',finite,'tail',tail,'cells',cells,flush=True) return (finite+tail).b def buchstab(): # M(u)=u omega(u) is increasing. A right numerator and a left # denominator bound M' from above on every step of length 1/T. T=32768 unit=10**14 m=[unit]*(2*T+1) maxima=[F(0),F(0)] for j in range(2*T,8*T): m.append(m[j]+(m[j+1-T]+j-T-1)//(j-T)) if j>=7*T: maxima[1]=max(maxima[1],F(m[j+1]*T,unit*j)) maxima[0]=max(maxima[0],F(m[j+1]*T,unit*j)) # Each bound on a full final unit interval propagates by the delay equation. assert maxima[0]2 and (1-eta)/(2*b)>7 lam=exact(LAMBDA) omega2,omega7=buchstab() density=(omega2*omega7+1/(I(2)*7*factorial(6)))/2 length=support(H/b,lam) spec=spectrum(p,B) least=b*exact(min(FREQ))/eps reg=(density*iv.exp((lam/2+1/lam)*I('.577216')+lam*iv.exp(-least)/(2*least)) *(eps/b)**(I('1.5')-lam/2-1/lam)*iv.sqrt(length)*spec/(4*iv.sqrt(iv.pi))).b exc=exceptional(eps,b,eta) print('cutoff 1/b',B,'eta',eta,'support fraction',length,'odd large-group density',density,flush=True) print('regular',reg,'exceptional',exc,'ordinary BV cap four',2*(reg+exc), 'switched relative error',I('3.440568')*(reg+exc)/2,flush=True) return (I('3.440568')*(reg+exc)/2).b if __name__=='__main__': import sys for pair in sys.argv[1:] or ['15,25']: p,B=map(int,pair.split(',')) assert run(p,B)<1