joint density problem from P1 probability actuary book - solving density function of the subtraction of random variables Let X and Y be two random variables with joint density function $$f_{XY} $$.
Compute the pdf of $$ U = Y − X $$
I've looked at this problem multiple times and I keep getting a different answer than the book.
For my joint density function I'm getting the following:
$$f_{Y −X}(a)= \int_{-\infty}^{\infty} f_{X,Y}(x, a+x) dx = \int_{-\infty}^{\infty} -f_{X,Y}(y-a, y) dy $$
If X and Y are independent I'm getting the following:
$$ f_{Y −X}(a)= \int_{-\infty}^{\infty} f_{Y}(a+x) \cdot f_X(x) dx =  \int_{-\infty}^{\infty} -f_{X}(y-a) \cdot f_Y(y) dy $$
The book gives this answer:
$$ f_{Y −X}(a) = \int_{-\infty}^{\infty} f_{X,Y} (y − a, y)dy $$ Moreover, the book says If X and Y are independent then
$$  f_{Y −X}(a) = \int_{-\infty}^{\infty} f_X(y − a)f_Y (y)dy = \int_{-\infty}^{\infty}f_X(y)f_Y (a + y)dy $$
would anyone kindly explain how the book got this answer and am I wrong? I was simply following the same approach as if we were to calculate $$ U = X+Y $$ but it seems something is really off with my answer...
 A: Just remove the minus signs and you are correct:
$$f_{Y −X}(a)= \int_{-\infty}^{\infty} f_{X,Y}(x, a+x) dx = \int_{-\infty}^{\infty} f_{X,Y}(y-a, y) dy $$
If X and Y are independent:
$$ f_{Y −X}(a)= \int_{-\infty}^{\infty} f_{Y}(a+x) \cdot f_X(x) dx =  \int_{-\infty}^{\infty} f_{X}(y-a) \cdot f_Y(y) dy $$
This is consistent with what the book says, and with the fact that pdf's must be positive.

Let us prove the second one : $f_{Y −X}(a)= \int_{-\infty}^{\infty} f_{X,Y}(y-a, y) dy$. I highlight in bold what I suspect you might have gotten wrong.
Let $h$ be any positive measurable function.
We use the definition of density and Fubini's theorem to obtain
$$E[h(Y-X)] = \int_{\Bbb R^2} h(y-x) f_{X,Y}(x,y) dx dy = \int_{-\infty}^{\infty}\left(\int_{-\infty}^{\infty} h(y-x) f_{X,Y}(x,y) dx\right) dy$$
Now we perform the change of variables  $a=y-x$ in the inner integral, with $dx = -da$.
$$= \int_{-\infty}^{\infty}\left(\int_{\infty}^{-\infty} -h(a) f_{X,Y}(y-a,y) dx\right)dy$$
Now a minus sign has appeared but at the same time the bounds of integration have been reversed. We put them back in the correct order.
$$= \int_{-\infty}^{\infty}\left(\int_{-\infty}^{\infty} h(a) f_{X,Y}(y-a,y) dx\right)dy$$
Fubini again
$$= \int_{-\infty}^{\infty} h(a)\left(\int_{-\infty}^{\infty} f_{X,Y}(y-a,y) dy\right)da$$
So the thing inside the parenthesis is $f_{Y-X}(a)$ QED.
