[proofplan]
We start from $\mathbb{E}[X] = \int_{-\infty}^{\infty} x\, f_X(x)\, dx$ and split into positive and negative parts. For the positive part, we write $x = \int_0^x 1\, dt$ and interchange the order of integration (justified by Tonelli's theorem for non-negative integrands), converting $\int_0^{\infty} x\, f_X(x)\, dx$ into $\int_0^{\infty} \mathbb{P}(X \ge t)\, dt$. A parallel argument handles the negative part.
[/proofplan]
custom_env
admin
[step:Split $\mathbb{E}[X]$ into positive and negative contributions]
Write $X = X^+ - X^-$ where $X^+ = \max(X, 0)$ and $X^- = \max(-X, 0)$. Then $\mathbb{E}[X] = \mathbb{E}[X^+] - \mathbb{E}[X^-]$ (provided at least one is finite). We treat each term separately.
[/step]
custom_env
admin
[step:Convert $\mathbb{E}[X^+]$ to a tail probability integral by exchanging the order of integration]
Since $X$ has density $f_X$,
\begin{align*}
\mathbb{E}[X^+] = \int_0^{\infty} x\, f_X(x)\, dx.
\end{align*}
We represent $x$ as the integral $x = \int_0^{x} 1\, dt$ for $x > 0$, so
\begin{align*}
\mathbb{E}[X^+] = \int_0^{\infty} \left(\int_0^{x} 1\, dt\right) f_X(x)\, dx.
\end{align*}
The integrand $f_X(x) \cdot \mathbb{1}_{0 \le t \le x}$ is non-negative on $[0, \infty) \times [0, \infty)$, so by Tonelli's theorem we may interchange the order of integration. The region of integration is $\{(x, t) : 0 \le t \le x < \infty\}$, which equals $\{(x, t) : 0 \le t < \infty,\; x \ge t\}$. Switching to integrate over $x$ first (for fixed $t$),
\begin{align*}
\mathbb{E}[X^+] = \int_0^{\infty} \left(\int_t^{\infty} f_X(x)\, dx\right) dt = \int_0^{\infty} \mathbb{P}(X \ge t)\, dt.
\end{align*}[/step]
custom_env
admin
[guided]The idea is to exploit the representation $x = \int_0^x 1\, dt$, which converts the factor of $x$ inside the expectation into an extra integral. This is a standard "double-counting" trick: instead of summing $x$ units of probability density at each point $x$, we count, for each threshold $t \ge 0$, how much probability mass lies above $t$.
More concretely, consider the region $R = \{(x, t) \in \mathbb{R}^2 : x \ge 0,\; 0 \le t \le x\}$, which is the triangle below the line $t = x$ in the first quadrant. The integral $\int_0^{\infty} x\, f_X(x)\, dx$ integrates $f_X(x)$ over horizontal slices of $R$ (for each $x$, the slice has length $x$). By Tonelli's theorem — applicable because the integrand $f_X(x) \cdot \mathbb{1}_R(x,t)$ is non-negative — we may instead integrate over vertical slices: for each $t \ge 0$, the vertical slice is $\{x : x \ge t\}$, and integrating $f_X(x)$ over this slice gives $\mathbb{P}(X \ge t)$.[/guided]
custom_env
admin
[step:Apply the same argument to $\mathbb{E}[X^-]$ and combine]
By the same reasoning applied to $X^- = \max(-X, 0)$,
\begin{align*}
\mathbb{E}[X^-] = \int_0^{\infty} \mathbb{P}(X^- \ge t)\, dt = \int_0^{\infty} \mathbb{P}(-X \ge t)\, dt = \int_0^{\infty} \mathbb{P}(X \le -t)\, dt.
\end{align*}
Combining,
\begin{align*}
\mathbb{E}[X] = \mathbb{E}[X^+] - \mathbb{E}[X^-] = \int_0^{\infty} \mathbb{P}(X \ge t)\, dt - \int_0^{\infty} \mathbb{P}(X \le -t)\, dt.
\end{align*}
When $X \ge 0$, the second integral vanishes (since $\mathbb{P}(X \le -t) = 0$ for all $t > 0$), giving $\mathbb{E}[X] = \int_0^{\infty} \mathbb{P}(X \ge t)\, dt$.
[/step]