def kl_term(x,y): """Helper function for kl: calculates one term in the sum.""" if x>0 and y>0: return x*math.log2(x/y) elif x==0: return 0.0 else: return math.inf