Represent the difference of two random variables as indicator functions

I want to show for any random variables $X$ and $Y$, we have $X-Y = \int_{-\infty}^{\infty} \mathbb{1} \{X>a\}- \mathbb{1}\{Y>a\} d a$.

I know that for a postive r.v. $Z$, we have $Z = \int_{0}^{\infty} \mathbb{1}\{ Z>a\} da $. For $X = X^{+} - X^{-}$, we have $X=\int_{0}^{\infty}\mathbb{1} \{X>x\}- \mathbb{1}\{-X>x\}d x$. What can we conclude on $X-Y$? In general is it correct to say $X = \int_{-\infty}^{\infty} \mathbb{1}\{X>x\} dx$?


Solution 1:

In general, the inequality $X = \int_{-\infty}^{\infty} \mathbb{1}\{X>x\} dx$ does not hold, as the integral is divergent ($\mathbb{1}\{X>x\}\to 1$ as $x$ goes to $-\infty$).

In order to prove the wanted equality, let $\omega\in\Omega$, $x=X(\omega)$ and $y=Y(\omega)$. We can assume without loss of generality that $x\geqslant y$. Then $$ \mathbb{1} \{x>a\}- \mathbb{1}\{y>a\}=\begin{cases} 0 &\mbox{ if }a\leqslant y\mbox{ or }a\geqslant x\\ 1 &\mbox{ if }y\leqslant a<x. \end{cases} $$