I'm trying to prove the following theorem.
Theorem. If $X$ is a positive random variable with distribution function $F$ and density function $f$, then, for each $y \geq 0$,
$$E[\min{(X,y)}]=\int_{x=0}^{y}{(1-F(x))}\text{d}x$$
The proof says:
\begin{align*} \int_{x=0}^{y}{(1-F(x))}\text{d}x &= \int_{x=0}^{y}{\left(\int_{z=x}^{\infty}f(z)dz\right)}\text{d}x\\ &=\int_{z=0}^{\infty}\int_{x=0}^{\min(z,y)}f(z)\text{d}z\text{d}x\\ &=\int_{z=0}^{\infty}{\min(z,y)}f(z)\text{d}z \end{align*}
I understood the first line in the proof... but I'm lost after that...
$(1)$ Why the second equation in the first line becomes the equation in the second line?
$(2)$ Why the equation in the second line equals to the equation in the third line?
Any hint or guide would be greatly appreciated..!
There is a misprint in the second line. It should read $\int_0^{\infty} \int_0^{\min (z,y)} f(z) dx dz$. This is obtained from the first line by interchanging the order of integration and noting that the conditions $x<z,x<y,x>0$ are equivalent to $0<x<\min {(z,y)}$ and $z>0$. The last step is obtained by noting that $f(z)$ is a constant whe you integrate w.r.t. $x$.