In [1]: from sympy.stats import ContinuousRV, P
In [2]: var('x')
Out[2]: x
In [3]: X = ContinuousRV(x, exp(-x), (0, oo))
In [4]: P(X < Rational(1,2))
TypeError: Input must be Sets or iterables of Sets
In [6]: var('k')
Out[6]: k
In [7]: cdf = integrate(exp(-x), (x, 0, k))
In [8]: solve(cdf - Rational(1, 2), k)
Out[8]: [log(2)]In [15]: X = ContinuousRV(x, exp(-x), Interval(0, oo))
In [16]: P(X < 1/2)
Out[16]:
-1/2
- ℯ + 1
In [17]: P(X < log(2))
AttributeError: 'bool' object has no attribute 'is_Piecewise'
In [1]: from sympy.stats import *
In [2]: from sympy import *
In [3]: ;var x
Out[3]: x
In [4]: X = ContinuousRV(x, exp(-x), Interval(0, oo))
In [5]: P(X < log(2).n())
Out[5]: 0.500000000000000
In [6]: P(X < log(2))
Out[6]: oo
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6%2BvrUtKCu1fU_78Hy7jYXLxWTE6V-YdOvrhBWtQ9T6_Cg%40mail.gmail.com.
Generally when debugging sympy.stats I recommend inspecting the integrals that it produces using the evaluate=False keyword. Sympy.stats almost always shoves off most of the hard work onto another SymPy module like integrals.In [1]: from sympy.stats import *In [2]: X = ContinuousRV(x, exp(-x), Interval(0, oo))In [3]: P(X < log(2), evaluate=False)Out[3]:0⌠⎮ -z⎮ ℯ⎮ ─── dz⎮ 2⌡-∞
> /home/.../sympy/sympy/stats/crv.py(392)compute_density()
391 fy = sum(fx(g) * abs(g.diff(y)) for g in gs)
--> 392 return Lambda(y, fy)
393