
import mpmath as mp, json
mp.mp.dps=40
L=mp.log(5)
# h(x)=exp(-x^2/(2 s^2)); hhat(r)=int h(x)e^{-irx}dx = s*sqrt(2pi)*exp(-s^2 r^2/2)
out={}
for s in [mp.mpf(1),mp.mpf(2)]:
    h=lambda x: mp.e**(-x**2/(2*s**2))
    hh=lambda r: s*mp.sqrt(2*mp.pi)*mp.e**(-s**2*r**2/2)
    eig=mp.nsum(lambda n: hh(2*mp.pi*n/L),[-mp.inf,mp.inf])
    orb=L*mp.nsum(lambda k: h(k*L),[-mp.inf,mp.inf])
    # exact normalisation: sum_nu hhat(2pi nu/L) = L * sum_k h(kL)
    out['gauss_s=%s'%s]={'eig':mp.nstr(eig,25),'orb':mp.nstr(orb,25),'diff':mp.nstr(eig-orb,5)}
# bump h(x)=(1-x^2)^2 on |x|<1 ; hhat computed by quad
h=lambda x:(1-x*x)**2 if abs(x)<1 else 0
hh=lambda r: 2*mp.quad(lambda x:(1-x*x)**2*mp.cos(r*x),[0,1])
eig=sum(hh(2*mp.pi*n/L) for n in range(-4000,4001))
orb=L*h(0)  # L=log5>1 so only k=0
out['bump']={'eig':mp.nstr(eig,12),'orb':mp.nstr(orb,12),'diff':mp.nstr(eig-orb,5),'note':'truncated |nu|<=4000, tail ~ N^-3'}
print(json.dumps(out,indent=1))
open('compute/trace-circle-results.json','w').write(json.dumps(out,indent=1))

