# Cumulative distribution function of sub of two random variable

Let $X$ be a random variable:Choosing a random number with the following Probability density function: $f(x)= \\ 1+x \ ,if \ \ -1<x \le0 \\ 1-x \ ,if \ \ \ 0<x<1 \\0 \ ,else$

Given $X=x$,We will choose a second number $Y$ as following:

if $x\in(-1,0]$,then $Y \mathtt{\sim} U(-1-x,1+x)$.

if $x\in(0,1)$,then $Y\mathtt{\sim} U(x-1,1-x)$.

Find the Probability distribution of $X-Y$.

I wanted to calculate the Cumulative distribution function,but I really have no idea how...

Is this even correct-

$P(X-Y\le t)=E[P(X-Y\le t|X=x)]=\int_{-\infty}^{\infty}P(Y\ge X-t)f_X(x)dx=\int_{-\infty}^{\infty}(1-F_Y(x-t))f_X(x)dx$

And if so,how can I continue?

Or any other ideas?

(Here-$f_X$ is the Probability density function,and $F_X$ is the Cumulative distribution function).

Your approach is a good start. \begin{align*} P(X-Y \le t) &= E[P(X-Y \le t \mid X)]\\ &= \int_{-\infty}^\infty P(Y \ge x-t \mid X=x )f_X(x) \; dx \\ &= \int_{-1}^0 P(Y \ge x-t \mid X=x) f_X(x) \; dx + \int_0^1 P(Y \ge x-t \mid X=x) f_X(x) \; dx \\ &= \underbrace{\int_{-1}^0 \left( \int_{\max\{-1-x,x-t\}}^{1+x} \frac{1}{2+2x} \; du \right) (1+x) \; dx}_* + \underbrace{\int_0^1 \left( \int_{\max\{x-t,x-1\}}^{1-x} \frac{1}{2-2x} \; du \right) (1-x) \; dx}_{**} \end{align*}

We need to analyze the maximum in the $*$ integral. The maximum equals $x-t \iff x>(t-1)/2$. Since $x \in (-1,0)$, we need to incorporate this for $t \in (-1,1)$.

So if $t \in (-1,1)$ then $*$ equals \begin{align*} \int_{-1}^{(t-1)/2} (1+x) \; dx + \int_{(t-1)/2}^{0} \left(\int_{x-t}^{1+x} \frac{1}{2+2x} \; du\right) (1+x) \, dx= \frac{1}{8} (t+1)^2 + \frac{1}{4}(1-t^2) \end{align*} and if $t< -1$, then $*$ equals $0$ and if $t>1$, then $*$ equals 1/2.

Similarly, we look at $(**)$. Note that the maximum in $(**)$ is $x-t$ as long as $t<1$. We also need this maximum $x-t$ to be less than the upper bound $1-x$, which occurs when $x < \frac{t+1}{2}$.

So if $t>1$, we get $1/2$, and if $t<-1$ we get 0, and if $t \in (-1,1)$, we get $$(**) = \int_0^{(t+1)/2} \left( \int_{x-t}^{1-x} \frac{1}{2-2x} \; du \right) (1-x) \; dx = \frac{1}{8} (t+1)^2$$

In conclusion, $$P(X-Y \le t) = \begin{cases}\frac{1}{4} (t+1)^2 + \frac{1}{4}(1-t^2)= (t+1)/2, \quad t \in (-1,1) \\ 0 , \quad t \le -1 \\ 1, \quad t \ge 1. \end{cases}$$

Taking the derivative wrt $t$, we get $f_{X-Y}(t) = \frac{1}{2}, \ -1 < t < 1$.

(I'm wondering if there was an easier way to do this . . . exploiting symmetry or something . . . )