More general definition of expected value Let $X$ be a random variable with pdf $f$. I would like to know why:
$$\operatorname{E} [X]  = \int_\Omega X \, \mathrm{d}P = \int_\Omega X(\omega) P(\mathrm{d}\omega)= \int_{-\infty}^\infty x f(x)\, \mathrm{d}x .   $$
I mean I don't get it why it is all equal and what the notation in third term means. Thanks for any calrification.
 A: Let $X$ be a random variable in the probability space $(\mathsf \Omega, \mathsf \Sigma, \mathsf P)$; where $\mathsf \Omega$ is the sample space, $\mathsf \Sigma$ is the set of events (each event containing zero or more outcomes), and $\mathsf P$ be the probability measure.
Then by definition the expected value is the integration of all possible values of the random variable over the sample space with respect to the probability measure.
$$\mathsf E [X]  = \int_\mathsf \Omega X \, \operatorname{d}\mathsf P$$
More generally, if $X$ can be expressed as a measurable function of individual outcomes $\omega$ within the sample space then:
$$\mathsf E [X]  = \int_\mathsf\Omega X(\omega) \, \operatorname{d}\mathsf P(\omega) = \int_\mathsf\Omega X(\omega) \, \mathsf P(\operatorname{d}\omega)$$
(You might be more familiar with the middle notation; they equivalently mean that the integration is with respect to the measure of the outcome and over the sample space $\mathsf\Omega$. The later notation just more correctly identifies that we're integrating over the domain of the outcomes, rather than the domain of the probability measure.)
In the specific case where we have let $X$ be a random variable with pdf $f$, then the probability space is implicitly the real domain $\mathsf \Omega\equiv (-\infty,\infty)$, the individual outcomes ($\omega$) may be represented as a real variable ($x$), the value of the random variable at each outcome is simply the outcome, $X(x)=x$, and by the definition of the probability density: $f(x)\mathrm d x \equiv \mathsf P(\operatorname{d}x)$, so :
$$\begin{align}
\mathsf E[X] & = \int_\mathsf\Omega X\operatorname{d}\mathsf P
\\ & = \int_\mathsf\Omega X(\omega)\mathsf P(\operatorname{d}\omega) & \because X, \mathsf P \text{ are measurable functions of }\omega\in\mathsf\Omega 
\\ & = \int_{-\infty}^{+\infty} X(\omega) \mathsf P(\operatorname{d}\omega) & \because \text{here } \mathsf\Omega = \mathbb R
\\ & = \int_{-\infty}^{+\infty} X(x) \mathsf P(\operatorname{d}x) & \because \text{change of variable, } \omega = x
\\ & = \int_{-\infty}^{+\infty} x \; \mathsf P(\operatorname{d}x) & \because \text{here } X(x)=x
\\ & = \int_{-\infty}^{+\infty} x \; f(x)\operatorname{d} x & \because f(x) \mathop{:\!}=\frac{\operatorname{d}\mathsf P(x)}{\operatorname{d} x}
\end{align}$$
A: Let us show that
$$
\int_\Omega g(X)\,\mathrm dP=\int_\mathbb{R}g\, \mathrm d P_X=\int_\mathbb{R} gf\mathrm d\lambda,\tag{1}
$$
for all measurable $g$ such that $g(X)$ is integrable. Here $\lambda$ is the Lebesgue-measure. 
To this end, let $g$ be an indicator function, i.e. $g=\mathbf{1}_B$ for some Borel set $B\subseteq\mathbb{R}$. Then
$$
\int_\Omega g(X)\,\mathrm dP=\int_\Omega \mathbf{1}_{X^{-1}(B)}\,\mathrm dP=P_X(B)=\int_\mathbb{R} g\,\mathrm dP_X.
$$
Thus, the first equality of $(1)$ holds for indicator functions and can easily be extended to a general $g$ by using the linearity of the integral.
As for the second equality we have, with the same $g$, that
$$
\int_{\mathbb{R}}g\,\mathrm dP_X=P_X(B)=\int_B f\,\mathrm d\lambda=\int_\mathbb{R} gf\,\mathrm d\lambda,
$$
since $X$ has density $f$ with respect to $\lambda$. Thus, the second equality of $(1)$ holds for indicator functions and can easily be extended to a general $g$.
To answer your question, let $g$ be the identity function, i.e. $g(x)=x$.
