Show that $E(|X-a|) = \int_{-\infty}^a P(X < x) \, dx + \int_a^\infty P(X > x) \, dx$ How to show:
$E(|X-a|) = \int_{-\infty}^a P(X < x) \, dx + \int_a^\infty P(X > x) \, dx$.
I have:
$$E(|X-a|) = \int |X-a| \, dP = \int_{\mathbb{R}} |x-a| P_X(dx) = \int_{(-\infty,a)} a-x P_X(dx) + \int_{(a,\infty)} x-a P_X(dx)$$
But I do not see where to go. And how do I get to the Riemann-Integral? It is just $E(|X|)<\infty$ known, but nothing about an density function (in this case I would know how to get to the Riemann integral).

$$E(|X-a|) = \int_{(0,\infty)} P(|X-a| > t) \lambda(dt) = \int_{(0,\infty)} P(\max(X-a,0)+\max(a-X,0) > t) \lambda(dt)$$
This gives, since the events are disjoint, and with Rieman-integrability:
$$E(|X-a|) = \int_0^{\infty} P(\max(X-a,0) > t) + P(\max(a-X,0) > t) dx$$
How to go on? Integral is linear, but I do not know how separating them would help..

Finally it is first proven that:
$E(|X|) = \int_{-\infty}^0 P(X < x) \, dx + \int_0^\infty P(X > x) \, dx$.
Now I want to conclude for $|X-a|$.
$E(|X-a|) = \int_{-\infty}^0 P(X-a < x) \, dx + \int_0^\infty P(X-a > x) \, dx$
$= \int_{-\infty}^0 P(X < x+a) \, dx + \int_0^\infty P(X > x+a) \, dx$
$= \int_{-\infty}^a P(X < x) \, dx + \int_a^\infty P(X > x) \, dx$
 A: I think it would be easier if we start from the formula 
$$\mathbb E(Y)=\int_0^{+\infty}\mathbb P\{Y>t\}\mathrm dt,$$
where $Y$ is a non-negative random variable. 
Then notice that for a real number $x$, we have $|x|=\max\{x,0\}+\max\{0,-x\}$.
Making a substitution $u=x-a$ in the two integral in the RHS of the equality we want to prove, we notice that we can assume that $a=0$. 
We thus have 
$$\mathbb E|X|=\mathbb E\max\{X,0\}+\mathbb E\max\{0,-X\}.$$
We have for $t>0$
$$\{\max\{X,0\}>t\}=\{X>t\}$$
and 
$$\{\max\{-X,0\}>t\}=\{X<-t\},$$
hence we get the result integrating.
A: Normally, for a positive variable, I think of
$$
\mathrm{E}(Y)=-\int_0^\infty x\,\frac{\mathrm{d}}{\mathrm{d}x}P(Y\ge x)\,\mathrm{d}x
$$
Since $-\frac{\mathrm{d}}{\mathrm{d}x}P(Y\ge x)$ is the probability density of $Y$ being near $x$. $P(Y\ge x)$ is monotonic decreasing and so it is differentiable almost everywhere. If $P(Y\ge x)$ is not differentiable everywhere, we can use the Riemann-Stieltjes Integral and define
$$
\mathrm{E}(Y)=-\int_0^\infty x\,\mathrm{d}P(Y\ge x)
$$
Integration by parts, which is valid for the Riemann-Stieltjes integral, yields
$$
\mathrm{E}(Y)=-\lim_{x\to\infty}x\,P(Y\ge x)+\int_0^\infty P(Y\ge x)\,\mathrm{d}x
$$
Summation by parts gives
$$
\begin{align}
\mathrm{E}(Y)
&\ge\sum_{k=0}^\infty2^k\left(P(Y\ge2^k)-P(Y\ge2^{k+1})\right)\\
&=2^0P(Y\ge2^0)+\sum_{k=0}^\infty(2^{k+1}-2^k)P(Y\ge2^{k+1})\\
&=P(Y\ge1)+\sum_{k=0}^\infty2^kP(Y\ge2^{k+1})
\end{align}
$$
Since the summation converges, $2^kP(Y\ge2^k)\to0$. Therefore, since $P(Y\ge x)$ is monotonic non-increasing, we get
$$
\lim_{x\to\infty}x\,P(Y\ge x)=0
$$
Therefore,
$$
\mathrm{E}(Y)=\int_0^\infty P(Y\ge x)\,\mathrm{d}x
$$
For $\mathrm{E}(|X-a|)$, this becomes,
$$
\begin{align}
\mathrm{E}(|X-a|)
&=\int_0^\infty P(|X-a|\ge x)\,\mathrm{d}x\\
&=\int_a^\infty P(X\ge x)\,\mathrm{d}x+\int_{-\infty}^a P(X\le x)\,\mathrm{d}x
\end{align}
$$
A: Note that the integrands are monotone.  And therefore (improperly) Riemann integrable.
