Probabilty one random variable exceeds another by at least k I have a constant $k \in [-1,1]$ . I take two independent draws $x,y$ from a distribution uniform over 0,1. What is the probability that $x-y > k$? Intuitively, I think that if $k > 0$, the probability will be:
$1/2* (1-k)^2$
and if $k < 0$, it will be:
$1-[1/2* (k+1)^2]$
Since these are the areas I get when I draw a picture of the problem. Is this correct, and is it is, is it possible to show this using integration, rather than just using pictures, and have a single, differentiable function that combines these two cases?
 A: First of all, note that $0< x,y <1$ and we are trying to calculate
\begin{equation}
\int\int_{\{x-y>k\}} f(x)g(y)dydx
\end{equation}
where f(x) and g(y) is 1 on $[0,1]$ and 0 otherwise.
Observe;
- If $k>0$ and $k> x$, there is no $y$ such that $x-y > k$.
and
- If k < 0 and $x> 1+k$, $x-y>k$ is satisfied for all $y$.
Hence;
\begin{equation}
\int_{\{x<k\}}\int_{\{x-y>k\}}f(x)g(y)dydx + \int_{\{x>k\}}\int_{\{x-y>k\}}f(x)g(y)dydx\\=\int_k^1\int_0^{x-k}dydx \quad\quad if \quad k>0
\end{equation}
and
\begin{equation}
\int_{\{x>1+k\}}\int_{\{x-y>k\}}f(x)g(y) dydx+\int_{\{x<1+k\}}\int_{\{x-y>k\}}f(x)g(y)dydx\\=-k + \int_0^{1+k}\int_0^{x-k}dydx \quad\quad if \quad k<0
\end{equation}
[Hint. We are trying to seperate regions where $\int g(y)=0$ or $\int g(y)=1$]
After taking integrals, you can write it in the form;
\begin{equation}
P(x-y>k) = 
\begin{cases}
\frac{1}{2} - k + \frac{k^3}{|k|} \quad &if\quad k\neq 0\\
1/2 \quad &if\quad k=0
\end{cases}
\end{equation}
which is equivalent to your answer.
