def test_H(): X = Normal('X', 0, 1) D = Die('D', sides=4) G = Geometric('G', 0.5) assert H(X, X > 0) == -log(2) / 2 + S(1) / 2 + log(pi) / 2 assert H(D, D > 2) == log(2) assert comp(H(G).evalf().round(2), 1.39)
def test_H(): X = Normal("X", 0, 1) D = Die("D", sides=4) G = Geometric("G", 0.5) assert H(X, X > 0) == -log(2) / 2 + S.Half + log(pi) / 2 assert H(D, D > 2) == log(2) assert comp(H(G).evalf().round(2), 1.39)
def test_issue_20286(): n, p = symbols('n p') B = Binomial('B', n, p) k = Dummy('k', integer=True) eq = Sum( Piecewise( (-p**k * (1 - p)**(-k + n) * log(p**k * (1 - p)**(-k + n) * binomial(n, k)) * binomial(n, k), (k >= 0) & (k <= n)), (nan, True)), (k, 0, n)) assert eq.dummy_eq(H(B))