I recently learned about finding density functions of functions of random variables using the cumulative distribution function. For example, computing the density function for the difference of two uniform random variables on $[0,1]$ (as in Grinstead & Snell's free online book). I gave myself the following problem.
Say $X$ and $Y$ are independent random variables with exponential density $f(t) = a e^{-at}$. I'm trying to compute the density function for $Z = X-Y$, but I'm getting nonsense. Since $z<0$ is ok and the density function will go like $e^{-az}$, trying to check that $\int_{-\infty}^\infty f_{X-Y}(z) dz$ diverges! What is going wrong?
EDIT: The calculations are as follows. If $z > 0$, then $$ \begin{split} P(Z < z) &= \int_0^\infty dy \int_0^{y+z} dx a^2 e^{-a(x+y)} \\ &= 1 - \frac 1 2 e^{-a z} \end{split} $$ I found this by thinking about the (x,y) points satisfying $Y > X - z$, giving a region $y > 0, y+z > x > 0$. If $ z < 0$, $$ \begin{split} \displaystyle P(Z < z) &= \int_z^\infty dy \int_0^{y+z} dx a^2 e^{-a(x+y)} \\ &= -\frac 1 2 e^{-3 a z } + e^{-a z}.\end{split}$$