Did I find the right examples for you? yes no

# sympy.stats.variance

All Samples(41)  |  Call(37)  |  Derive(0)  |  Import(4)
```Variance of a random expression

Expectation of (X-E(X))**2

Examples
========

>>> from sympy.stats import Die, E, Bernoulli, variance
>>> from sympy import simplify, Symbol
(more...)
```

```        def variance(X, condition=None, **kwargs):
"""
Variance of a random expression

Expectation of (X-E(X))**2

Examples
========

>>> from sympy.stats import Die, E, Bernoulli, variance
>>> from sympy import simplify, Symbol

>>> X = Die('X', 6)
>>> p = Symbol('p')
>>> B = Bernoulli('B', p, 1, 0)

>>> variance(2*X)
35/3

>>> simplify(variance(B))
p*(-p + 1)
"""
return cmoment(X, 2, condition, **kwargs)
```

```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,
```
```
assert simplify(E(Y)) == mu
assert simplify(variance(Y)) == sigma**2
pdf = density(Y)
x = Symbol('x')
```
```def test_multiple_normal():
X, Y = Normal('x', 0, 1), Normal('y', 0, 1)

assert E(X + Y) == 0
assert variance(X + Y) == 2
assert variance(X + X) == 4
assert covariance(X, Y) == 0
assert covariance(2*X + Y, -X) == -2*variance(X)
```

```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,
```
```
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)) == S('1/3')
```
```    # Numeric
assert E(Y) == S('-1/2')
assert variance(Y) == S('33/4')

for x in range(-5, 5):
```
```
assert E(X) == 3 + S.Half
assert variance(X) == S(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)
```

```from sympy.stats.drv_types import (PoissonDistribution, GeometricDistribution,
Poisson)
from sympy.abc import x
from sympy import S, Sum
from sympy.stats import E, variance, density
```
```def test_Poisson():
l = 3
x = Poisson('x', l)
assert E(x) == l
assert variance(x) == l
```

```from sympy import (EmptySet, FiniteSet, S, Symbol, Interval, exp, erf, sqrt,