def test_rademacher(): X = Rademacher('X') assert E(X) == 0 assert variance(X) == 1 assert density(X)[-1] == Rational(1, 2) assert density(X)[1] == Rational(1, 2)
def test_discreteuniform(): # Symbolic a, b, c = symbols('a b c') X = DiscreteUniform('X', [a, b, c]) assert X.pspace.distribution.pdf(a) == Rational(1, 3) assert X.pspace.distribution.pdf(p) == 0 assert E(X) == (a + b + c)/3 assert simplify(variance(X) - ((a**2 + b**2 + c**2)/3 - (a/3 + b/3 + c/3)**2)) == 0 assert P(Eq(X, a)) == P(Eq(X, b)) == P(Eq(X, c)) == Rational(1, 3) Y = DiscreteUniform('Y', range(-5, 5)) # Numeric assert E(Y) == -Rational(1, 2) assert variance(Y) == Rational(33, 4) for x in range(-5, 5): assert P(Eq(Y, x)) == Rational(1, 10) assert P(Y <= x) == Rational(x + 6, 10) assert P(Y >= x) == Rational(5 - x, 10) assert dict(density(Die('D', 6)).items()) == \ dict(density(DiscreteUniform('U', range(1, 7))).items())
def test_lognormal(): mean = Symbol('mu', real=True) std = Symbol('sigma', positive=True, real=True) X = LogNormal('x', mean, std) # The diofant integrator can't do this too well # assert E(X) == exp(mean+std**2/2) # assert variance(X) == (exp(std**2)-1) * exp(2*mean + std**2) # Right now, only density function and sampling works # Test sampling: Only e^mean in sample std of 0 for i in range(3): X = LogNormal('x', i, 0) assert sample(X) == N(exp(i)) # The diofant integrator can't do this too well # assert E(X) == mu = Symbol("mu", extended_real=True) sigma = Symbol("sigma", positive=True) X = LogNormal('x', mu, sigma) assert density(X)(x) == (sqrt(2)*exp(-(-mu + log(x))**2 / (2*sigma**2))/(2*x*sqrt(pi)*sigma)) X = LogNormal('x', 0, 1) # Mean 0, standard deviation 1 assert density(X)(x) == sqrt(2)*exp(-log(x)**2/2)/(2*x*sqrt(pi))
def test_conditional_1d(): X = Normal('x', 0, 1) Y = given(X, X >= 0) assert density(Y)(x) == 2 * density(X)(x) assert Y.pspace.domain.set == Interval(0, oo, right_open=True) assert E(Y) == sqrt(2/pi) assert E(X**2) == E(Y**2)
def test_difficult_univariate(): """ Since using solve in place of deltaintegrate we're able to perform substantially more complex density computations on single continuous random variables """ x = Normal('x', 0, 1) assert density(x**3) assert density(exp(x**2)) assert density(log(x))
def test_dice(): # TODO: Make iid method! X, Y, Z = Die('X', 6), Die('Y', 6), Die('Z', 6) a, b = symbols('a b') assert E(X) == 3 + Rational(1, 2) assert variance(X) == Rational(35, 12) assert E(X + Y) == 7 assert E(X + X) == 7 assert E(a*X + b) == a*E(X) + b assert variance(X + Y) == variance(X) + variance(Y) == cmoment(X + Y, 2) assert variance(X + X) == 4 * variance(X) == cmoment(X + X, 2) assert cmoment(X, 0) == 1 assert cmoment(4*X, 3) == 64*cmoment(X, 3) assert covariance(X, Y) == 0 assert covariance(X, X + Y) == variance(X) assert density(Eq(cos(X*pi), 1))[True] == Rational(1, 2) assert correlation(X, Y) == 0 assert correlation(X, Y) == correlation(Y, X) assert smoment(X + Y, 3) == skewness(X + Y) assert smoment(X, 0) == 1 assert P(X > 3) == Rational(1, 2) assert P(2*X > 6) == Rational(1, 2) assert P(X > Y) == Rational(5, 12) assert P(Eq(X, Y)) == P(Eq(X, 1)) assert E(X, X > 3) == 5 == moment(X, 1, 0, X > 3) assert E(X, Y > 3) == E(X) == moment(X, 1, 0, Y > 3) assert E(X + Y, Eq(X, Y)) == E(2*X) assert moment(X, 0) == 1 assert moment(5*X, 2) == 25*moment(X, 2) assert P(X > 3, X > 3) == 1 assert P(X > Y, Eq(Y, 6)) == 0 assert P(Eq(X + Y, 12)) == Rational(1, 36) assert P(Eq(X + Y, 12), Eq(X, 6)) == Rational(1, 6) assert density(X + Y) == density(Y + Z) != density(X + X) d = density(2*X + Y**Z) assert d[22] == Rational(1, 108) and d[4100] == Rational(1, 216) and 3130 not in d assert pspace(X).domain.as_boolean() == Or( *[Eq(X.symbol, i) for i in [1, 2, 3, 4, 5, 6]]) assert where(X > 3).set == FiniteSet(4, 5, 6) X = Die('X', 2) x = X.symbol assert X.pspace.compute_cdf(X) == {1: Rational(1, 2), 2: 1} assert X.pspace.sorted_cdf(X) == [(1, Rational(1, 2)), (2, 1)] assert X.pspace.compute_density(X)(1) == Rational(1, 2) assert X.pspace.compute_density(X)(0) == 0 assert X.pspace.compute_density(X)(8) == 0 assert X.pspace.density == x
def test_Poisson(): l = 3 x = Poisson('x', l) assert E(x) == l assert variance(x) == l assert density(x) == PoissonDistribution(l) assert isinstance(E(x, evaluate=False), Sum) assert isinstance(E(2*x, evaluate=False), Sum) assert density(x)(z) == 3**z/(exp(3)*factorial(z))
def test_Density(): X = Die('X', 6) d = Density(X) assert d.doit() == density(X) r = Rational(1, 6) assert density(2*X).dict == {2: r, 4: r, 6: r, 8: r, 10: r, 12: r} X = Normal('X', 0, 1) Y = Normal('Y', 0, 1) assert str(density(X - Y, Y)(z)) == 'sqrt(2)*E**(-(Y + z)**2/2)/(2*sqrt(pi))'
def test_bernoulli(): p, a, b = symbols('p a b') X = Bernoulli('B', p, a, b) assert E(X) == a*p + b*(-p + 1) assert density(X)[a] == p assert density(X)[b] == 1 - p X = Bernoulli('B', p, 1, 0) assert E(X) == p assert simplify(variance(X)) == p*(1 - p) assert E(a*X + b) == a*E(X) + b assert simplify(variance(a*X + b)) == simplify(a**2 * variance(X))
def test_frechet(): a = Symbol("a", positive=True) s = Symbol("s", positive=True) m = Symbol("m", extended_real=True) X = Frechet("x", a, s=s, m=m) assert density(X)(x) == a*((x - m)/s)**(-a - 1)*exp(-((x - m)/s)**(-a))/s
def test_f_distribution(): d1 = Symbol("d1", positive=True) d2 = Symbol("d2", positive=True) X = FDistribution("x", d1, d2) assert density(X)(x) == (d2**(d2/2)*sqrt((d1*x)**d1*(d1*x + d2)**(-d1 - d2)) / (x*beta(d1/2, d2/2)))
def test_dagum(): p = Symbol("p", positive=True) b = Symbol("b", positive=True) a = Symbol("a", positive=True) X = Dagum('x', p, a, b) assert density(X)(x) == a*p*(x/b)**(a*p)*((x/b)**a + 1)**(-p - 1)/x
def test_chi_noncentral(): k = Symbol("k", integer=True) l = Symbol("l") X = ChiNoncentral("x", k, l) assert density(X)(x) == (x**k*l*(x*l)**(-k/2) * exp(-x**2/2 - l**2/2)*besseli(k/2 - 1, x*l))
def test_coins(): C, D = Coin('C'), Coin('D') H, T = symbols('H, T') assert P(Eq(C, D)) == Rational(1, 2) assert density(Tuple(C, D)) == {(H, H): Rational(1, 4), (H, T): Rational(1, 4), (T, H): Rational(1, 4), (T, T): Rational(1, 4)} assert dict(density(C).items()) == {H: Rational(1, 2), T: Rational(1, 2)} F = Coin('F', Rational(1, 10)) assert P(Eq(F, H)) == Rational(1, 10) d = pspace(C).domain assert d.as_boolean() == Or(Eq(C.symbol, H), Eq(C.symbol, T)) pytest.raises(ValueError, lambda: P(C > D)) # Can't intelligently compare H to T
def test_rayleigh(): sigma = Symbol("sigma", positive=True) X = Rayleigh('x', sigma) assert density(X)(x) == x*exp(-x**2/(2*sigma**2))/sigma**2 assert E(X) == sqrt(2)*sqrt(pi)*sigma/2 assert variance(X) == -pi*sigma**2/2 + 2*sigma**2
def test_fisher_z(): d1 = Symbol("d1", positive=True) d2 = Symbol("d2", positive=True) X = FisherZ("x", d1, d2) assert density(X)(x) == (2*d1**(d1/2)*d2**(d2/2) * (d1*exp(2*x) + d2)**(-d1/2 - d2/2) * exp(d1*x)/beta(d1/2, d2/2))
def test_quadratic_u(): a = Symbol("a", extended_real=True) b = Symbol("b", extended_real=True) X = QuadraticU("x", a, b) assert density(X)(x) == (Piecewise((12*(x - a/2 - b/2)**2/(-a + b)**3, And(x <= b, a <= x)), (0, True))) assert X.pspace.domain.set == Interval(a, b)
def test_pareto(): xm, beta = symbols('xm beta', positive=True, finite=True) alpha = beta + 5 X = Pareto('x', xm, alpha) dens = density(X) x = Symbol('x') assert dens(x) == x**(-(alpha + 1))*alpha*xm**alpha
def test_uniformsum_d(): n = Symbol("n", integer=True) k = Symbol("k") X = UniformSum('x', n) d = density(X)(x) assert d == 1/factorial(n - 1)*Sum((-1)**k*(x - k)**(n - 1) * binomial(n, k), (k, 0, floor(x)))
def test_raised_cosine(): mu = Symbol("mu", extended_real=True) s = Symbol("s", positive=True) X = RaisedCosine("x", mu, s) assert density(X)(x) == (Piecewise(((cos(pi*(x - mu)/s) + 1)/(2*s), And(x <= mu + s, mu - s <= x)), (0, True))) assert X.pspace.domain.set == Interval(mu - s, mu + s)
def test_die_args(): pytest.raises(ValueError, lambda: Die('X', -1)) # issue sympy/sympy#8105: negative sides. pytest.raises(ValueError, lambda: Die('X', 0)) pytest.raises(ValueError, lambda: Die('X', 1.5)) # issue sympy/sympy#8103: non integer sides. k = Symbol('k') sym_die = Die('X', k) pytest.raises(ValueError, lambda: density(sym_die).dict)
def test_FiniteRV(): F = FiniteRV('F', {1: Rational(1, 2), 2: Rational(1, 4), 3: Rational(1, 4)}) assert dict(density(F).items()) == {1: Rational(1, 2), 2: Rational(1, 4), 3: Rational(1, 4)} assert P(F >= 2) == Rational(1, 2) assert pspace(F).domain.as_boolean() == Or( *[Eq(F.symbol, i) for i in [1, 2, 3]])
def test_density_call(): x = Bernoulli('x', p) d = density(x) assert d(0) == 1 - p assert d(5) == 0 assert 0 in d assert 5 not in d assert d(0) == d[0]
def test_GeometricDistribution(): p = Rational(1, 5) d = GeometricDistribution(p) assert d.expectation(x, x) == 1/p assert d.expectation(x**2, x) - d.expectation(x, x)**2 == (1-p)/p**2 assert abs(d.cdf(20000).evalf() - 1) < .001 X = Geometric("x", p) assert density(X)(z) == Rational(4, 5)**(z - 1)/5
def test_benini(): alpha = Symbol("alpha", positive=True) b = Symbol("beta", positive=True) sigma = Symbol("sigma", positive=True) X = Benini('x', alpha, b, sigma) assert density(X)(x) == ((alpha/x + 2*b*log(x/sigma)/x) * exp(-alpha*log(x/sigma) - b*log(x/sigma)**2)) assert X.pspace.domain.set == Interval(sigma, oo, False, True)
def test_maxwell(): a = Symbol("a", positive=True) X = Maxwell('x', a) assert density(X)(x) == (sqrt(2)*x**2*exp(-x**2/(2*a**2)) / (sqrt(pi)*a**3)) assert E(X) == 2*sqrt(2)*a/sqrt(pi) assert simplify(variance(X)) == a**2*(-8 + 3*pi)/pi
def test_uniformsum(): n = Symbol("n", integer=True) X = UniformSum('x', n) assert X.pspace.domain.set == Interval(0, n) # see test_uniformsum_d() d = density(X)(z) assert str(d) == ("Sum((-1)**_k*(z - _k)**(n - 1)*binomial(n, _k), " "(_k, 0, floor(z)))/factorial(n - 1)")
def test_triangular(): a = Symbol("a") b = Symbol("b") c = Symbol("c") X = Triangular('x', a, b, c) assert density(X)(x) == Piecewise( ((2 * x - 2 * a) / ((-a + b) * (-a + c)), And(a <= x, x < c)), (2 / (-a + b), x == c), ((-2 * x + 2 * b) / ((-a + b) * (b - c)), And(x <= b, c < x)), (0, True))
def test_nakagami(): mu = Symbol("mu", positive=True) omega = Symbol("omega", positive=True) X = Nakagami('x', mu, omega) assert density(X)(x) == (2*x**(2*mu - 1)*mu**mu*omega**(-mu) * exp(-x**2*mu/omega)/gamma(mu)) assert simplify(E(X, meijerg=True)) == (sqrt(mu)*sqrt(omega) * gamma(mu + Rational(1, 2))/gamma(mu + 1)) assert simplify(variance(X, meijerg=True)) == ( omega - omega*gamma(mu + Rational(1, 2))**2/(gamma(mu)*gamma(mu + 1)))
def test_triangular(): a = Symbol("a") b = Symbol("b") c = Symbol("c") X = Triangular('x', a, b, c) assert density(X)(x) == Piecewise( ((2*x - 2*a)/((-a + b)*(-a + c)), And(a <= x, x < c)), (2/(-a + b), Eq(x, c)), ((-2*x + 2*b)/((-a + b)*(b - c)), And(x <= b, c < x)), (0, True))
def test_nakagami(): mu = Symbol("mu", positive=True) omega = Symbol("omega", positive=True) X = Nakagami('x', mu, omega) assert density(X)(x) == (2 * x**(2 * mu - 1) * mu**mu * omega**(-mu) * exp(-x**2 * mu / omega) / gamma(mu)) assert simplify(E(X, meijerg=True)) == (sqrt(mu) * sqrt(omega) * gamma(mu + S.Half) / gamma(mu + 1)) assert simplify(variance( X, meijerg=True)) == (omega - omega * gamma(mu + Rational(1, 2))**2 / (gamma(mu) * gamma(mu + 1)))
def test_die_args(): pytest.raises( ValueError, lambda: Die('X', -1)) # issue sympy/sympy#8105: negative sides. pytest.raises(ValueError, lambda: Die('X', 0)) pytest.raises( ValueError, lambda: Die('X', 1.5)) # issue sympy/sympy#8103: non integer sides. k = Symbol('k') sym_die = Die('X', k) pytest.raises(ValueError, lambda: density(sym_die).dict)
def test_FiniteRV(): F = FiniteRV('F', {1: S.Half, 2: S.One / 4, 3: S.One / 4}) assert dict(density(F).items()) == { Integer(1): S.Half, Integer(2): S.One / 4, Integer(3): S.One / 4 } assert P(F >= 2) == S.Half assert pspace(F).domain.as_boolean() == Or( *[Eq(F.symbol, i) for i in [1, 2, 3]])
def test_coins(): C, D = Coin('C'), Coin('D') H, T = symbols('H, T') assert P(Eq(C, D)) == Rational(1, 2) assert density(Tuple(C, D)) == { (H, H): Rational(1, 4), (H, T): Rational(1, 4), (T, H): Rational(1, 4), (T, T): Rational(1, 4) } assert dict(density(C).items()) == {H: Rational(1, 2), T: Rational(1, 2)} F = Coin('F', Rational(1, 10)) assert P(Eq(F, H)) == Rational(1, 10) d = pspace(C).domain assert d.as_boolean() == Or(Eq(C.symbol, H), Eq(C.symbol, T)) pytest.raises(ValueError, lambda: P(C > D)) # Can't intelligently compare H to T
def test_Sample(): X = Die('X', 6) Y = Normal('Y', 0, 1) z = Symbol('z') assert sample(X) in [1, 2, 3, 4, 5, 6] assert sample(X + Y).is_Float P(X + Y > 0, Y < 0, numsamples=10).is_number assert E(X + Y, numsamples=10).is_number assert variance(X + Y, numsamples=10).is_number pytest.raises(ValueError, lambda: P(Y > z, numsamples=5)) assert P(sin(Y) <= 1, numsamples=10) == 1 assert P(sin(Y) <= 1, cos(Y) < 1, numsamples=10) == 1 # Make sure this doesn't raise an error E(Sum(1 / z**Y, (z, 1, oo)), Y > 2, numsamples=3) assert all(i in range(1, 7) for i in density(X, numsamples=10)) assert all(i in range(4, 7) for i in density(X, X > 3, numsamples=10))
def test_discreteuniform(): # Symbolic a, b, c = symbols('a b c') X = DiscreteUniform('X', [a, b, c]) assert E(X) == (a + b + c)/3 assert simplify(variance(X) - ((a**2 + b**2 + c**2)/3 - (a/3 + b/3 + c/3)**2)) == 0 assert P(Eq(X, a)) == P(Eq(X, b)) == P(Eq(X, c)) == Rational(1, 3) Y = DiscreteUniform('Y', range(-5, 5)) # Numeric assert E(Y) == -Rational(1, 2) assert variance(Y) == Rational(33, 4) for x in range(-5, 5): assert P(Eq(Y, x)) == Rational(1, 10) assert P(Y <= x) == Rational(x + 6, 10) assert P(Y >= x) == Rational(5 - x, 10) assert dict(density(Die('D', 6)).items()) == \ dict(density(DiscreteUniform('U', range(1, 7))).items())
def test_hypergeometric_numeric(): for N in range(1, 5): for m in range(N + 1): for n in range(1, N + 1): X = Hypergeometric('X', N, m, n) N, m, n = map(sympify, (N, m, n)) assert sum(density(X).values()) == 1 assert E(X) == n * m / N if N > 1: assert variance(X) == n*(m/N)*(N - m)/N*(N - n)/(N - 1) # Only test for skewness when defined if N > 2 and 0 < m < N and n < N: assert skewness(X) == simplify((N - 2*m)*sqrt(N - 1)*(N - 2*n) / (sqrt(n*m*(N - m)*(N - n))*(N - 2)))
def test_FiniteRV(): F = FiniteRV('F', { 1: Rational(1, 2), 2: Rational(1, 4), 3: Rational(1, 4) }) assert dict(density(F).items()) == { 1: Rational(1, 2), 2: Rational(1, 4), 3: Rational(1, 4) } assert P(F >= 2) == Rational(1, 2) assert pspace(F).domain.as_boolean() == Or( *[Eq(F.symbol, i) for i in [1, 2, 3]])
def test_single_normal(): mu = Symbol('mu', real=True) sigma = Symbol('sigma', real=True, positive=True) X = Normal('x', 0, 1) Y = X*sigma + mu assert simplify(E(Y)) == mu assert simplify(variance(Y)) == sigma**2 pdf = density(Y) x = Symbol('x') assert (pdf(x) == sqrt(2)*exp(-(x - mu)**2/(2*sigma**2))/(2*sqrt(pi)*sigma)) assert P(X**2 < 1) == erf(sqrt(2)/2) assert E(X, Eq(X, mu)) == mu
def test_gamma(): k = Symbol('k', positive=True) theta = Symbol('theta', positive=True) X = Gamma('x', k, theta) assert density(X)(x) == x**(k - 1)*theta**(-k)*exp(-x/theta)/gamma(k) assert cdf(X, meijerg=True)(z) == Piecewise( (-k*lowergamma(k, 0)/gamma(k + 1) + k*lowergamma(k, z/theta)/gamma(k + 1), z >= 0), (0, True)) # assert simplify(variance(X)) == k*theta**2 # handled numerically below assert E(X) == moment(X, 1) k, theta = symbols('k theta', real=True, positive=True) X = Gamma('x', k, theta) assert simplify(E(X)) == k*theta # can't get things to simplify on this one so we use subs assert variance(X).subs({k: 5}) == (k*theta**2).subs({k: 5})
def test_beta(): a, b = symbols('alpha beta', positive=True) B = Beta('x', a, b) assert pspace(B).domain.set == Interval(0, 1) dens = density(B) x = Symbol('x') assert dens(x) == x**(a - 1)*(1 - x)**(b - 1) / beta(a, b) # This is too slow # assert E(B) == a / (a + b) # assert variance(B) == (a*b) / ((a+b)**2 * (a+b+1)) # Full symbolic solution is too much, test with numeric version a, b = Integer(1), Integer(2) B = Beta('x', a, b) assert expand_func(E(B)) == a/(a + b) assert expand_func(variance(B)) == (a*b)/(a + b)**2/(a + b + 1)
def test_Density(): X = Die('X', 6) d = Density(X) assert d.doit() == density(X)
def test_cauchy(): x0 = Symbol('x0') gamma = Symbol('gamma', positive=True) X = Cauchy('x', x0, gamma) assert density(X)(x) == 1/(pi*gamma*(1 + (x - x0)**2/gamma**2))
def test_normality(): X, Y = Normal('X', 0, 1), Normal('Y', 0, 1) x, z = symbols('x, z', real=True) dens = density(X - Y, Eq(X + Y, z)) assert integrate(dens(x), (x, -oo, oo)) == 1
def test_chi_squared(): k = Symbol('k', integer=True) X = ChiSquared('x', k) assert density(X)(x) == 2**(-k/2)*x**(k/2 - 1)*exp(-x/2)/gamma(k/2)
def test_chi(): k = Symbol('k', integer=True) X = Chi('x', k) assert density(X)(x) == 2**(-k/2 + 1)*x**(k - 1)*exp(-x**2/2)/gamma(k/2)
def test_gamma_inverse(): a = Symbol('a', positive=True) b = Symbol('b', positive=True) X = GammaInverse('x', a, b) assert density(X)(x) == x**(-a - 1)*b**a*exp(-b/x)/gamma(a)
def test_erlang(): k = Symbol('k', integer=True, positive=True) l = Symbol('l', positive=True) X = Erlang('x', k, l) assert density(X)(x) == x**(k - 1)*l**k*exp(-x*l)/gamma(k)
def test_laplace(): mu = Symbol('mu') b = Symbol('b', positive=True) X = Laplace('x', mu, b) assert density(X)(x) == exp(-abs(x - mu)/b)/(2*b)
def test_kumaraswamy(): a = Symbol('a', positive=True) b = Symbol('b', positive=True) X = Kumaraswamy('x', a, b) assert density(X)(x) == x**(a - 1)*a*b*(-x**a + 1)**(b - 1)
def test_studentt(): nu = Symbol('nu', positive=True) X = StudentT('x', nu) assert density(X)(x) == (1 + x**2/nu)**(-nu/2 - 1/2)/(sqrt(nu)*beta(1/2, nu/2))
def test_logistic(): mu = Symbol('mu', extended_real=True) s = Symbol('s', positive=True) X = Logistic('x', mu, s) assert density(X)(x) == exp((-x + mu)/s)/(s*(exp((-x + mu)/s) + 1)**2)
def test_conjugate_priors(): mu = Normal('mu', 2, 3) x = Normal('x', mu, 1) assert isinstance(simplify(density(mu, Eq(x, y), evaluate=False)(z)), Integral)
def test_random_parameters(): mu = Normal('mu', 2, 3) meas = Normal('T', mu, 1) assert density(meas, evaluate=False)(z) assert isinstance(pspace(meas), ProductPSpace)
def test_density_unevaluated(): X = Normal('X', 0, 1) Y = Normal('Y', 0, 2) assert isinstance(density(X+Y, evaluate=False)(z), Integral)
def test_wignersemicircle(): R = Symbol('R', positive=True) X = WignerSemicircle('x', R) assert density(X)(x) == 2*sqrt(-x**2 + R**2)/(pi*R**2) assert E(X) == 0
def test_von_mises(): mu = Symbol('mu') k = Symbol('k', positive=True) X = VonMises('x', mu, k) assert density(X)(x) == exp(k*cos(x - mu))/(2*pi*besseli(0, k))
def test_density_constant(): assert density(3)(2) == 0 assert density(3)(3) == DiracDelta(0)
def test_betaprime(): alpha = Symbol('alpha', positive=True) betap = Symbol('beta', positive=True) X = BetaPrime('x', alpha, betap) assert density(X)(x) == x**(alpha - 1)*(x + 1)**(-alpha - betap)/beta(alpha, betap)