TITLE: Proving something similar to $\mathbb E(g(X)) = \int_0^\infty g'(x) P(X>x) dP$
QUESTION [5 upvotes]: For a non-negative r.v. $X$ s.t. $\mathbb E{X}<\infty$, and $g$ s.t. $||g||_\infty$ and $||g'||_\infty$ are both $<\infty$ (where $||\cdot ||_\infty$ is the essential supremum), we have that
$$\begin{aligned}
\int_0^\infty g'(x) P(X>x) d P &= \int_0^\infty \int_\Omega g'(x) 1_{[X>x]} dP dx = \int_\Omega \int_0^\infty g'(x) 1_{[X>x]} dx dP \\
&= \int_\Omega \int_0^X g'(x) dx dP = \int_\Omega g(X) - g(0) d P = \mathbb{E}(g(X))-g(0) \\
\end{aligned}$$
where the integral interchange is justified because
$$\int_\Omega \int_0^\infty |g' 1_{[X>x]}|dxdP \leq \int_\Omega \int_0^X ||g'||_\infty dx dP = ||g'||_\infty \mathbb E{X} < \infty$$
In this link: How to prove $E[g(x)] = \int_0^\infty g'(x)S(x) dx$, one of the answers has a formula for general r.v.'s $X$ (i.e. not just non-negative one), but having to go to density functions and integrating by parts (and perhaps some extra conditions on $g$). Is there a proof of the general case without resorting to density functions, like my proof above? 
Second, is there a more general formulation if we want $\mathbb{E}[g(X)1_{[a<X\leq b]}]$ instead?

REPLY [4 votes]: First,
\begin{align}
\int_0^\infty g'(x)\mathsf{P}(X>x)\,dx &=\int_{\Omega}1\{X\ge 0\}\int_0^Xg'(x) \,dx\,d\mathsf{P} \\
&=\int_{\Omega}1\{X\ge 0\}(g(X)-g(0))\,d\mathsf{P} \\
&=\mathsf{E} g(X)1\{X\ge 0\}-g(0)\mathsf{P}(X\ge 0).\tag{1}\label{1}
\end{align}
Similarly,
\begin{align}
\int_{-\infty}^0 g'(x)\mathsf{P}(X\le x)\,dx &=\int_{\Omega}1\{X< 0\}\int_X^0g'(x) \,dx\,d\mathsf{P} \\
&=\int_{\Omega}1\{X< 0\}(g(0)-g(X))\,d\mathsf{P} \\
&=g(0)\mathsf{P}(X< 0)-\mathsf{E} g(X)1\{X< 0\}.\tag{2}\label{2}
\end{align}
Subtracting $\eqref{2}$ from $\eqref{1}$, one gets
$$
\mathsf{E}g(X)=g(0)+\int_0^\infty g'(x)\mathsf{P}(X> x)\, dx-\int_{-\infty}^0 g'(x)\mathsf{P}(X\le x)\, dx.
$$