I have two random variables $X_1$ and $X_2$ where:
$$f_{X_1}(x) = f_{X_2}(x) = \begin{cases} e^{-\frac x2}, \quad \text{if} \; 0 \leq x \leq \mathrm{ln}\: 4\\ 0, \quad \quad \text{otherwise} \end{cases}$$
and a third random variable $Y = X_1 – X_2$. Now I understand that the sum of two independent random variables can found using a convolution so it makes sense that the difference can also be found using a convolution but how?
My PDF looks like this:
and I know that graphically the convolution for $X_1 +X_2$ looks like this:
- First integral from $0$ to the point where red is still inside blue (in this case $t$)
- Then integral from $t-\mathrm{ln}\:4$ to $\mathrm{ln}\:4$
So how does this change once we take the difference and not the sum? Essentially, if flipping and shifting is the convolution sum then what it different when there is a difference that needs to be calculated?
Edit: Based on the answer by perepelart I solved the convolution sum as follows:
to find $Y$ we can start the convolution as follows:
Step 1:
First, we flip $f_Z$ and slide it to the point that it starts entering $f_X$. Before this point $f_Y$ is zero.
Here-forth the convolution integral for $-\mathrm{ln}\: 4 \leq t<0$ becomes:
\begin{align*}
f_X \ast f_Z &= \int_{-\infty}^{\infty} f_X(x) f_Z(t-x) dx\\
& = \int_{0}^{t+\mathrm{ln}\: 4} f_X(x) f_Z(t-x) dx\\
& = \int_{0}^{t+\mathrm{ln}\: 4} e^{-\frac x2} e^{-\frac{(t-x)}{2}} dx\\
& = (t+\mathrm{ln}\: 4)e^{-\frac t2} \qquad \text{for} \: -\mathrm{ln}\: 4 \leq t<0
\end{align*}
Step 2:
In this step the sliding PDF $f_Z$ has began exiting the PDF $f_X$ which looks like this:
which will give us the values for $f_Y$ for $0\leq t\leq\mathrm{ln}\: 4$.
Here-forth the convolution integral for $0<t<\mathrm{ln}\: 4$ becomes:
\begin{align*}
f_X \ast f_Z &= \int_{-\infty}^{\infty} f_X(x) f_Z(t-x) dx\\
& = \int_{t}^{\mathrm{ln}\: 4} f_X(x) f_Z(t-x) dx\\
& = \int_{t}^{\mathrm{ln}\: 4} e^{-\frac x2} e^{-\frac{(t-x)}{2}} dx\\
& = -(t-\mathrm{ln}\: 4)e^{-\frac t2} \qquad \text{for} \; 0 \leq t \leq\mathrm{ln}\: 4
\end{align*}
Hence, the PDF of $Y$ is:
$$f_Y(y)= \begin{cases}
(y+\mathrm{ln}\: 4)e^{-\frac y2}, \qquad \text{for} \; -\mathrm{ln}\: 4 \leq y<0,\\
-(y-\mathrm{ln}\: 4)e^{-\frac y2}, \quad \; \text{for} \; 0 \leq y \leq \mathrm{ln}\: 4,\\
0 \qquad \qquad \qquad\qquad \text{otherwise}.
\end{cases}$$
The plot of $f_Y(y)$ looks as follows:
Although $f_Y$ is always non-negative it integrates to $2$, hence, it is an invalid PDF.
Best Answer
If we know the distribution of the $X_2$, we can find the distribution of the $-X_2.$ I tried to do it as straightforward as possible.
As $F_\xi(y)$ I denote the CDF of the random variable $\xi$.
$$F_{-X_2}(y)=\mathbb{P}(-X_2\leq y)=\mathbb{P}(X_2 \geq -y)=1-\mathbb{P}(X_2\le -y)=\\=1-F_{X_2}(-y).$$ Now, to find the density of $-X_2$, you can just differentiate $F_{-X_2}(y)$ : $$f_{-X_2}(y)=\frac{d}{dy}\left(F_{-X_2}(y)\right)=\frac{d}{dy}(1-F_{X_2}(-y))=\\=f_{X_2}(-y)=\mathbf{1}_{\{-\ln4\leq y\leq 0\}}e^{\frac{y}{2}}$$
By $\mathbf{1}_{A}(y)$ where $A$ is an event I denote indicator function. It equals $1$ whenever $y \in A$ and equals zero otherwise. It's just an elegant way to define a piecewise function.
Without indicator you can write it as follows :
$$f_{-X_2}(y)=\mathbf{1}_{\{-\ln4\leq y\leq 0\}}(y) \cdot e^{\frac{y}{2}} = \begin{cases}e^{\frac{y}{2}}, -\ln4\leq y\leq 0 \\ 0, \text{otherwise.} \end{cases}$$
Therefore you have two random variables, let's denote them $X:=X_1$ and $Y := -X_2$ and you need to find PDF of $X+Y$. And you know their densities so you can just use the convolution of the sum as you wanted.
UPDATE.
So you can check your work I added my calculations of the $f_{X+Y}(y)$. I will use indicator function during integrations to make derivations shorter.
For now we have : $f_X(x) = \mathbf{1}_{\{0 \leq x \leq \ln 4\}}e^{-\frac{x}{2}}, f_Y(y) = \mathbf{1}_{\{-\ln4 \leq y \leq 0\}}e^{\frac{y}{2}}$
Using convolution, we get :
$$f_{X+Y}(y)=\int\limits_{\mathbb{R}}f_X(x)f_Y(y-x)dx = \int\limits_{\mathbb{R}}\mathbf{1}_{\{0 \leq x \leq \ln 4\}}e^{-\frac{x}{2}}\mathbf{1}_{\{-\ln4 \leq y-x \leq 0\}}e^{\frac{y-x}{2}}dx = \\ =e^{\frac{y}{2}} \int\limits_{\mathbb{R}}\mathbf{1}_{\{0 \leq x \leq \ln 4\}}e^{-\frac{x}{2}}\mathbf{1}_{\{y \leq x \leq \ln4+y\}}e^{-\frac{x}{2}}dx = e^{\frac{y}{2}}\int\limits_{\max\{0,y\}}^{\min\{\ln4, \ln4+y\}}e^{-x}dx$$
To evaluate this integral I will consider different cases.
If $0 \leq y \leq \ln4$, we have :
$$f_{X+Y}(y)=e^{\frac{y}{2}}\int\limits_{y}^{\ln4}e^{-x}dx=-\frac{1}{4}e^{\frac{y}{2}} + e^{-\frac{y}{2}}$$
If $-\ln4 \leq y < 0 $, we have :
$$f_{X+Y}(y)=e^{\frac{y}{2}}\int\limits_{0}^{\ln4+y}e^{-x}dx=e^{\frac{y}{2}}-\frac{1}{4}e^{-\frac{y}{2}}$$
If $y > \ln 4$ or $y < - \ln 4$, $f_{X+Y}(y)$ will be equal to $0$.
Finally,
$$f_{X+Y}(y) = \mathbf{1}_{\{0 \leq y \leq \ln 4 \}}(y) \cdot \left(-\frac{1}{4}e^{\frac{y}{2}} + e^{-\frac{y}{2}}\right) + \mathbf{1}_{\{-\ln 4 \leq y < 0 \}}(y) \cdot\left(e^{\frac{y}{2}}-\frac{1}{4}e^{-\frac{y}{2}}\right)$$
We can check that it's integrates to $1$ :
$$\int\limits_{\mathbb{R}}\mathbf{1}_{\{0 \leq y \leq \ln 4 \}}(y) \cdot \left(-\frac{1}{4}e^{\frac{y}{2}} + e^{-\frac{y}{2}}\right)dy = \int\limits_{0}^{\ln 4}(-\frac{1}{4}e^{\frac{y}{2}} + e^{-\frac{y}{2}})dy = \frac{1}{2},$$
$$\int\limits_{\mathbb{R}}\mathbf{1}_{\{-\ln 4 \leq y < 0 \}}(y) \cdot\left(e^{\frac{y}{2}}-\frac{1}{4}e^{-\frac{y}{2}}\right)dy = \int\limits_{-\ln 4}^{0}(e^{\frac{y}{2}}-\frac{1}{4}e^{-\frac{y}{2}})dy = \frac{1}{2}$$
Hence, by additivity of the integral,
$$\int\limits_{\mathbb{R}}f_{X+Y}(y)dy=\frac{1}{2}+\frac{1}{2}=1$$
Without indicator function, we can rewrite it as follows :
$$f_{X+Y}(y)=\begin{cases}e^{\frac{y}{2}}-\frac{1}{4}e^{-\frac{y}{2}} , -\ln4 \leq y < 0 \\ -\frac{1}{4}e^{\frac{y}{2}} + e^{-\frac{y}{2}}, 0 \leq y \leq \ln 4 \\0, \text{otherwise}\end{cases}$$