How to prove $E[g(x)] = \int_0^\infty g'(x)S(x) dx$ Given that $E[g(X)] = \int_{-\infty}^\infty g(x)f(x) dx$, how to prove $E[g(X)] = \int_{0}^\infty g'(x)S(x)dx$, where $S(x) = 1-F(x)$?
By integration by parts, I can get the following:
\begin{align}
E[g(X)] &= \int_{-\infty}^\infty g(x)f(x) dx \\
        &= \int_{-\infty}^\infty g(x)F'(x) dx \\
        &= g(x)F(x)|_{-\infty}^\infty - \int_{-\infty}^\infty g'(x)F(x) dx \\
        &= g(x)F(x)|_{-\infty}^\infty + \int_{-\infty}^\infty g'(x)[1-S(x)] dx \\
        &= g(x)F(x)|_{-\infty}^\infty - \int_{-\infty}^\infty g'(x)dx +\int_{-\infty}^\infty g'(x)S(x) dx\\
\end{align}
Then I am stuck.
 A: I think what you are trying to prove is not exactly correct. I will work through the problem and show the correct answer at the end.
You need to split the integral into two, one for the region $x\ge 0$ and one for $x\le 0$. 
In the positive region, instead of writing $f(x)=F'(x)$ and integrating by parts, you need to use $f=(F(x)-1)'$. This is the only choice which ensures that the resulting integral actually exists; note that $F(x)-1$ goes to zero as $x\to+\infty$, but $F(x)$ does not.
\begin{align}
\int_0^\infty g(x)f(x)\,dx
  &=\int_0^\infty g(x)[F(x)-1]'\,dx
\\&=g(x)[F(x)-1]\Big|^\infty_0-\int_0^\infty g'(s)[F(x)-1]\,dx
\\&=\underbrace{\Big(\lim_{x\to\infty}g(x)[F(x)-1]\Big)}_{=0}-g(0)[F(0)-1]+\int_0^\infty g'(x)S(x)\,dx
\end{align}
It takes some doing, but you can show that that limit actually is zero, as long as $E[g(X)]$ is finite. See Is it true that $\lim\limits_{x\to\infty}{x·P[X>x]}=0$? for some inspiration. Edit: Actually, I am not quite sure this is true without some additional assumptions on $g.$ It is true as long as $g$ is either bounded or monotonic. 
For the negative region, you do want to use $F(x)$ as the antiderivate of $f(x)$, because $\lim_{x\to-\infty}F(x)=0$.
\begin{align}
\int_{-\infty}^0 g(x)f(x)\,dx
  &=\int_{-\infty}^0 g(x)F(x)'\,dx
\\&=g(x)F(x)\Big|^0_{-\infty}-\int_{-\infty}^0 g'(s)F(x)\,dx
\\&=g(0)F(0)-\underbrace{\Big(\lim_{x\to-\infty}g(x)F(x)\Big)}_{=0}-\int_{-\infty}^0 g'(x)F(x)\,dx
\end{align}
Putting this all together, we get
$$
\bbox[7px,border:2px solid red]{\int_{-\infty}^\infty g(x)f(x)\,dx=g(0)+\int_0^\infty g'(x)S(x)\,dx-\int_{-\infty}^0g'(x)F(x)\,dx}
$$
This is correct for any function $g$ such that $E[g(X)]$ is finite. Edit: Well, as long as $g$ is either bounded or monotonic.
If we make further assumptions about $g$, we can write this more nicely. Assuming $g(-\infty):=\lim_{x\to-\infty}g(x)$ exists, you would have
$$
g(0)=g(-\infty)+\int_{-\infty}^0 g'(x)\,dx
$$
so 
$$
\bbox[7px,border:2px solid green]{\int_{-\infty}^\infty g(x)f(x)\,dx=g(-\infty)+\int_{-\infty}^\infty g'(x)S(x)\,dx}
$$
You cannot in general avoid the presence of some constant $g(a)$. This is because the $\int g'(x)S(x)\,dx$ part of the formula does not change when $g$ is shifted by a constant (this does not affect $g'$), but $E[g(x)]$ does change when $g$ is shifted by a constant. 
A: Write $1-F(x)=\int_{(x,\infty)} d\mu(y)$ where $\mu$ is the measure corresponding to $F$. Now apply Fubini/Tonelli Theorem to the right hand side.  
