# Distribution of a difference of two Uniform random variables?

Let $X$ and $Y$ both be distributed between $[1,2]$, what is the distribution of $Z=X-Y$?

• Clearly, $Z$ has a range $[-1,1]$ so what are the problems of computing its density? – Ilya Mar 28 '13 at 15:47
• If you are interested in the answer only, try PDF[TransformedDistribution[ x - y, {Distributed[x, UniformDistribution[{1, 2}]], Distributed[y, UniformDistribution[{1, 2}]]}], z] in Mathematica. Otherwise state the origin of the problem, and share what you had attempted so far. – Sasha Mar 28 '13 at 15:59
• $f_Z(z)=\int_{-\infty}^\infty f_X(z+y)f_Y(y)dy=\int_{-1}^1f_X(z+y)dy$ Is this right? – Tarek Abed Mar 28 '13 at 16:00
• @TarekAbed: $y\in [1,2]$ rather than in $[-1,1]$ – Ilya Mar 28 '13 at 16:06
• @Ilya: $f_Z(z)=\int_{-\infty}^\infty f_X(z+y)f_Y(y)dy=\int_{1}^2f_X(z+y)dy$ What comes next? – Tarek Abed Mar 28 '13 at 16:17

## 1 Answer

If $x,y$ are independent and uniformly distributed on $[1,2]$, then the PDF of $x$ is $1_{[1,2]}$ and the PDF of $-y$ (note the minus sign) is $1_{[-2,-1]}$. Then the PDF of $z=x-y$ is given by the convolution $f_z=1_{[1,2]} * 1_{[-2,-1]}$.

Computing this is straightforward. \begin{eqnarray} f_z(x) &=& \int 1_{[1,2]}(y) 1_{[-2,-1]}(x-y) dy \\ &=& \int_1^2 1_{[-2,-1]}(x-y) dy \\ &=& \int_{x-2}^{x-1}1_{[-2,-1]}(t) dt \\ &=& \int 1_{[x-2,x-1] \cap [-2,-1]}(t)dt \\ &=& m([x-2,x-1] \cap [-2,-1]) \\ &=& m([x,x+1] \cap [0,1]) \\ &=& (1-|x|)1_{[-1,1]}(x) \end{eqnarray}

• What is m()? Also I dont get the second = where you go to using $t$. – jacob Oct 7 '15 at 23:08
• @jacob: The $m$ is the Lebesgue measure, it is the length of the interval in this case. For the second, I use the change of variables $t=x-y$ (remember that $x$ is fixed for the integration). – copper.hat Oct 7 '15 at 23:47
• Ok I get the second = now. I have not used the Lebesgue measure but maybe I can think of it as a usual integral? If so, then I think the 4th = sign is that "integrating from $x-2$ to $x-1$ for the integrand $t$ is the same as integrating over from $- \infty$ to $\infty$ for the integrand $1_{x-2, x-1} (t)$ correct? (Where $- \infty$ to $\infty$ rather is "for all values of $t$". And if that is true, then I do not get the fifth = sign because the primitive function of $t$ is $t^2$ but you apply some sort of logic here. – jacob Oct 10 '15 at 11:10
• @jacob: Here I am using $m$ to denote the length of an interval. Yes regarding the 4th =. For the 5th, remember that you are integrating a function that only takes values $0,1$, not $t$. – copper.hat Oct 10 '15 at 15:18