# Correct bounds when finding PDF of $X + Y$, where $X,Y$ i.i.d.

Let $$X,Y \sim \mathcal{U}([0,a])$$ be independent identically continuously uniform distributed real random variables. Find the PDF of $$Z := X + Y$$.

I know that this can be accomplished via convolution: For $$x \in \mathbb{R}$$ we have \begin{align*} \int_{\mathbb{R}} f_{X}(x - y) f_{Y}(y) \ \text{dy} & = \frac{1}{(a - 0)^2} \int_{\mathbb{R}} 1_{[0,a]}(x - y) \cdot 1_{[0,a]}(y) \ \text{dy} \\ & = \frac{1}{a^2} \int_{0}^{a} 1 \ \text{dy} \cdot 1_{[0,2a]}(x) = \frac{1_{[0,2a]}(x)}{a}. \end{align*} I obtained the bounds like this. From the second integral in the first line we have $$0 \le x - y \le a \qquad \text{and} \qquad 0 \le y \le a.$$ Adding both inequalities yields $$y \le x + y \le 2a + y$$ or $$0 \le x \le 2 a.$$ Therefore $$x < a$$ and the bounded on the dy-integral are [0, a] and furthermore we know that $$x \in [0,2a]$$.

Is this (result and procedure) correct and / or is there an easier way to do this?

In this task I faced a similar challenge: Let $$X,Y \sim \text{Exp}(\lambda)$$ for some $$\lambda > 0$$ be independent and identically distributed. Find the density of $$X + Y$$.

\begin{align*} (f_{X} \ast f_{Y})(x) & = \int_{\mathbb{R}} f_{X}(x - y) f_{Y}(y) \ \text{dy} \\ & = \int_{\mathbb{R}} \lambda e^{-\lambda (x - y)} 1_{[0, \infty)}(x - y) \cdot \lambda e^{-\lambda y} 1_{[0, \infty)}(y) \ \text{dy} \\ & = \lambda^2 \int_{0}^{x} e^{-\lambda (x - y)} \cdot e^{-\lambda y} \ \text{dy} \cdot 1_{[0, \infty)}(x) = \lambda^2 \int_{0}^{x} e^{-\lambda x} \ \text{dy} \cdot 1_{[0, \infty)}(x) \\ & = \lambda^2 x \cdot e^{-\lambda x} \cdot 1_{[0, \infty)}(x). \end{align*}

Here the same question as above applies.

First part (uniform). If you want to use the CDF method to find $$P(Z \le z)$$ by integration, the following plots (made from a simulation), may help you find the limits on integrals. I used $$a = 2.$$

The left-hand plot shows the region of integration for $$P(Z \le 1.5).$$ For values of $$z$$ above $$2$$ it seems easiest to break the integral into two parts. [However, because the joint distribution is uniform, this can be a high school geometry/algebra problem, if you like.]

The middle plot shows the empirical CDF (jump of $$1/10^5$$ at each of $$10^5$$ simulated values of $$Z),$$ which suggests the form of the CDF you'll get.

The right-hand plot shows a histogram of $$10^5$$ simulated values of $$Z.$$ [A discrete analogue of this is the 'triangular' PDF from the sum upon rolling two fair dice.]

Second part (exponential). If you know about moment generating functions, that's probably the easiest way to show that the sum of two independent exponential random variables, each with rate $$\lambda$$ is $$\mathsf{Gamma}(\text{shape}=2,\text{rate}=\lambda).$$ However, the PDF and convolution methods also work. [Perhaps see Wikipedia on gamma distributions to check your answer.]

Another simulation to indicate the result:

set.seed(708);  m = 10^6
x = rexp(m, .1); y = rexp(m, .1);  z = x+y
hist(z, prob=T, br=50, col="skyblue2")
curve(dgamma(x, 2, .1), add=T, lwd=2, col="red")


Notes: (a) This exponential relationship is much used in applications, including queueing theory. [Q. A person is next in line for a bank teller whose service times are exponential with rate one every five minutes, what is the probability that person finishes being served within 8 minutes? A. In R, code pgamma(8, 2, 1/5) returns 0.4750691.]

(b) If the two exponential random variables have different rates, the problem is very much messier. (If interested, perhaps google 'sum of exponentials different rates'.)

(c) In case you want it, the R code for making the figure is provided below:

par(mfrow=c(1,3))
set.seed(2019)
m = 30000
x = runif(m, 0, 2);  y = runif(m, 0, 2)
plot(x, y, pch=".")
event = (x + y < 1.5)
points(x[event], y[event], pch=".", col="green2")
m = 10^5
X = runif(m, 0, 2);  Y = runif(m, 0, 2)
Z = X+Y
plot(ecdf(Z))
hist(X+Y, prob=T, br=50, col="skyblue2")
par(mfrow=c(1,1))

• Well, from the middle plot for the uniform I get that the CDF is non-linear, but when I integrate my PDF I get that $\mathbb{P}(Z \le x) = \frac{x}{a}$ for $0 \le x \le 2a$, which 1) is linear and 2) returns 2 for $x = 2a$, which isn't possible. Where is my mistake? Also, my CDF and PDF for $Z$ then coincide with the CDF / PDF of $X$ (or $Y$) they are just on an interval twice the size, which seems wrong, since they have to sum up ( integrate) to 1 and not 2. – Ramanujan Jul 9 '19 at 11:30
• As a note, unfortunately we haven't covered moment-generating functions, just characteristic functions. – Ramanujan Jul 9 '19 at 12:18
• Characteristic functions will do the same job. ChFs require at least a minimal knowledge of complex numbers and exist for all dist'ns. MGFs are a bit simpler to use, but do not exist for all dist'ns. – BruceET Jul 9 '19 at 18:03
• Can you show me how? Also I'd like to know if my results are correct. – Ramanujan Jul 9 '19 at 19:14
• Product of MGFs is MGF of sum. MGF of $EXP(rate=\lambda)$ is $\frac{\lambda}{\lambda - t}$ for $t > \lambda).$ MGF of $GAMMA(2, \lambda)$ is $(\frac{\lambda}{\lambda - t})^2.$ See Wikipedia. – BruceET Jul 9 '19 at 19:22