Solution (source code)

= Solution

The <expectation> of a real <random variable> $X$ on a <probability space> is its <integral> against the <probability measure>:
$$
\boxed{\mathbb E X=\int_\Omega X(\omega)\,d\mathbb P(\omega).}
$$
For a discrete <random variable>, this becomes $\mathbb E X=\sum_x x\mathbb P(X=x)$; for a <random variable> with <probability density function> $f$, it becomes $\mathbb E X=\int_{-\infty}^{\infty}xf(x)\,dx$. A finite <expectation> requires $\mathbb E|X|<\infty$, making $X$ an <integrable random variable>. An extended <expectation> can also be defined when just one of the positive and negative parts has finite <expectation>; the indeterminate difference $\infty-\infty$ is not allowed.