Density of sum of two independent uniform random variables on $[0,1]$

If we want to use a convolution, let $f_X$ be the full density function of$X$, and let $f_Y$ be the full density function of $Y$. Let $Z=X+Y$. Then $$f_Z(z)=\int_{-\infty}^\infty f_X(x)f_Y(z-x)\,dx.$$

Now let us apply this general formula to our particular case. We will have $f_Z(z)=0$ for $z\lt 0$, and also for $z\ge 2$. Now we deal with the interval from $0$ to $2$. It is useful to break this down into two cases (i) $0\lt z\le 1$ and (ii) $1\lt z\lt 2$.

(i) The product $f_X(x)f_Y(z-x)$ is $1$ in some places, and $0$ elsewhere. We want to make sure we avoid calling it $1$ when it is $0$. In order to have $f_Y(z-x)=1$, we need $z-x\ge 0$, that is, $x\le z$. So for (i), we will be integrating from $x=0$ to $x=z$. And easily $$\int_0^z 1\,dx=z.$$ Thus $f_Z(z)=z$ for $0\lt z\le 1$.

(ii) Suppose that $1\lt z\lt 2$. In order to have $f_Y(z-x)$ to be $1$, we need $z-x\le 1$, that is, we need $x\ge z-1$. So for (ii) we integrate from $z-1$ to $1$. And easily $$\int_{z-1}^1 1\,dx=2-z.$$ Thus $f_Z(z)=2-z$ for $1\lt z\lt 2$.

Another way: (Sketch) We can go after the cdf $F_Z(z)$ of $Z$, and then differentiate. So we need to find $\Pr(Z\le z)$.

For a few fixed $z$ values, draw the lines with equation $x+y=z$ on an x-y axis plot. Draw the square $S$ with corners $(0,0)$, $(1,0)$, $(1,1)$, and $(0,1)$.

Then $\Pr(Z\le z)$ is the area of the part $S$ that is "below" the line $x+y=z$. That area can be calculated using basic geometry. For example, when z is 2, the whole square area is under the line so Pr=1. There is a switch in basic shape at $z=1$.


Here's why we need to break the convolution into cases. The integral we seek to evaluate for each $z$ is $$ f_Z(z):= \int_{-\infty}^\infty f(x)f(z-x)\,dx.\tag1 $$ (On the RHS of (1) I'm writing $f$ instead of $f_X$ and $f_Y$ since $X$ and $Y$ have the same density.) Here the density $f$ is the uniform density $f(x)$, which equals $1$ for $0<x<1$, and is zero otherwise. The integrand $f(x)f(z-x)$ will therefore have value either $1$ or $0$. Specifically, the integrand is $1$ when $$ 0<x<1\qquad\text{and}\qquad 0<z-x<1,\tag2 $$ and equals zero otherwise. To evaluate (1), which is an integral over $x$ (with $z$ held constant), we need to find the range of $x$-values where the conditions listed in (2) are satisfied. How does this range depend on $z$? Plotting the region defined by (2) in the $(x,z)$ plane, we find:

and it's clear how the limits of integration on $x$ depend on the value of $z$:

  1. When $0<z<1$, the limits run from $x=0$ to $x=z$, so $f_Z(z)=\int_0^z 1dx=z.$

  2. When $1<z<2$, the limits run from $x=z-1$ to $x=1$, so $f_Z(z)=\int_{z-1}^11dx=2-z.$

  3. When $z<0$ or $z>2$, the integrand is zero, so $f_Z(z)=0$.


By the hint of jay-sun, consider this idea, if and only if $f_X (z-y) = 1$ when $0 \le z-y \le 1$. So we get

$$ z-1 \le y \le z $$

however, $z \in [0, 2]$, the range of $y$ may not be in the range of $[0, 1]$ in order to get $f_X (z-y) = 1$, and the value $1$ is a good splitting point. Because $z-1 \in [-1, 1]$.

Consider (i) if $z-1 \le 0$ then $ -1 \le z-1 \le 0$ that is $ z \in [0, 1]$, we get the range of $y \in [0, z]$ since $z \in [0, 1]$. And we get $\int_{-\infty}^{\infty}f_X(z-y)dy = \int_0^{z} 1 dy=z$ if $z \in [0, 1]$.

Consider (ii) if $z-1 \ge 0$ that is $ z \in [1, 2]$, so we get the range of $y \in [z-1, 1]$, and $\int_{-\infty}^{\infty}f_X(z-y)dy = \int_{z-1}^{1} 1 dy = 2-z$ if $z \in [1, 2]$.

To sum up, consider to clip the range in order to get $f_X (z-y) = 1$.