Did I find the right examples for you? yes no

# sympy.stats.P

All Samples(52)  |  Call(49)  |  Derive(0)  |  Import(3)
```Probability that a condition is true, optionally given a second condition

Parameters
----------
expr : Relational containing RandomSymbols
The condition of which you want to compute the probability
given_condition : Relational containing RandomSymbols
A conditional expression. P(X>1, X>0) is expectation of X>1 given X>0
numsamples : int
Enables sampling and approximates the probability with this many samples(more...)
```

```        def probability(condition, given_condition=None, numsamples=None,
evaluate=True, **kwargs):
"""
Probability that a condition is true, optionally given a second condition

Parameters
----------
expr : Relational containing RandomSymbols
The condition of which you want to compute the probability
given_condition : Relational containing RandomSymbols
A conditional expression. P(X>1, X>0) is expectation of X>1 given X>0
numsamples : int
Enables sampling and approximates the probability with this many samples
evalf : Bool (defaults to True)
If sampling return a number rather than a complex expression
evaluate : Bool (defaults to True)
In case of continuous systems return unevaluated integral

Examples
========

>>> from sympy.stats import P, Die
>>> from sympy import Eq
>>> X, Y = Die('X', 6), Die('Y', 6)
>>> P(X>3)
1/2
>>> P(Eq(X, 5), X>2) # Probability that X == 5 given that X > 2
1/4
>>> P(X>Y)
5/12
"""

if numsamples:
return sampling_P(condition, given_condition, numsamples=numsamples,
**kwargs)
if given_condition is not None:  # If there is a condition
# Recompute on new conditional expr
return probability(given(condition, given_condition, **kwargs), **kwargs)

# Otherwise pass work off to the ProbabilitySpace
result = pspace(condition).probability(condition, **kwargs)
if evaluate and hasattr(result, 'doit'):
return result.doit()
else:
return result
```

```from sympy.stats import (P, E, where, density, variance, covariance, skewness,
given, pspace, cdf, ContinuousRV, sample,
Arcsin, Benini, Beta, BetaPrime, Cauchy,
Chi, ChiSquared,
ChiNoncentral, Dagum, Erlang, Exponential,
```
```            2**S.Half*exp(-(x - mu)**2/(2*sigma**2))/(2*pi**S.Half*sigma))

assert P(X**2 < 1) == erf(2**S.Half/2)

assert E(X, Eq(X, mu)) == mu
```
```def test_cdf():
X = Normal('x', 0, 1)

d = cdf(X)
assert P(X < 1) == d(1)
```
```    d = cdf(Y)
assert d(-5) == 0
assert P(Y > 3) == 1 - d(3)

raises(ValueError, lambda: cdf(X + Y))
```
```
assert variance(X) == variance(Y)
assert P(X > 0) == P(Y > 0)

```

```from sympy import (EmptySet, FiniteSet, S, Symbol, Interval, exp, erf, sqrt,
symbols, simplify, Eq, cos, And, Tuple, integrate, oo, sin, Sum, Basic,
DiracDelta)
from sympy.stats import (Die, Normal, Exponential, P, E, variance, covariance,
skewness, density, given, independent, dependent, where, pspace,
```
```def test_overlap():
X = Normal('x', 0, 1)
Y = Normal('x', 0, 2)

raises(ValueError, lambda: P(X > Y))
```
```    assert variance(X + Y, numsamples=10).is_number

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
```

```from sympy import (EmptySet, FiniteSet, S, Symbol, Interval, exp, erf, sqrt,
symbols, simplify, Eq, cos, And, Tuple, Or, Dict, sympify, binomial,
factor)
from sympy.stats import (DiscreteUniform, Die, Bernoulli, Coin, Binomial,
Hypergeometric, P, E, variance, covariance, skewness, sample, density,
```
```def BayesTest(A, B):
assert P(A, B) == P(And(A, B)) / P(B)
assert P(A, B) == P(B, A) * P(A) / P(B)

```