Conditional density function of gamma distributed R.V.'s, ${\Gamma(2,a)}$ I'm stuck on the following problem:
Let $X$ and $Y$ be independent $\Gamma(2,a)$-distributed random variables. Find the conditional distribution of $X$ given that $X+Y=2$.
So the problem is to find $f_{X\mid X+Y=2}(x)$ which from the definition equals $f_{X\mid X+Y=2}(x)=\frac{f_{X+Y=2,X}(2,x)}{f_{X+Y=2}(2)}$. I guess that I could find the distribution of $X+Y$(which I believe also is gamma), but then it would still be a problem of finding $f_{X+Y=2,X}(2,x)$. Is there an easy way of thinking about these kind of problems? 
 A: Let $Z=X+Y$, then the density $f_{X,Z}$ of $(X,Z)$ is defined by $f_{X,Z}(x,z)=f_X(x)f_Y(z-x)$ because $X$ and $Y$ are independent hence the conditional distribution of $X$ conditionally on $Z=z$ is proportional to $f_X(x)f_Y(z-x)$, that is, 
$$
f_{X\mid Z}(x\mid z)=\frac1{c(z)}f_X(x)f_Y(z-x),\qquad
c(z)=\displaystyle\int f_X(t)f_Y(z-t)\mathrm dt.
$$
In the special case asked for in the question, $f_X(x)=f_Y(x)\propto x\mathrm e^{-ax}\mathbf 1_{x\geqslant0}$, hence
$$
f_X(x)f_Y(z-x)\propto x(z-x)\mathrm e^{-az}\mathbf 1_{0\leqslant x\leqslant z},
$$ 
and, for every $z\geqslant0$,
$$
c(z)=\mathrm e^{-az}\int_0^z t(z-t)\mathrm dt\propto\mathrm e^{-az}z^3,
$$
that is,
$$
f_{X\mid Z}(x\mid z)=\frac6{z^3}x(z-x)\mathbf 1_{0\leqslant x\leqslant z}.
$$
In other words, $X=UZ$ where $U$ is independent of $Z$ and beta $(2,2)$.

More generally, if $X$ is gamma $(\alpha,a)$ and $Y$ is gamma $(\beta,a)$, then $f_X(x)\propto x^{\alpha-1}\mathrm e^{-ax}\mathbf 1_{x\geqslant0}$ and $f_Y(y)\propto y^{\beta-1}\mathrm e^{-ay}\mathbf 1_{y\geqslant0}$, hence
$$
f_X(x)f_Y(z-x)\propto x^{\alpha-1}(z-x)^{\beta-1}\mathrm e^{-az}\mathbf 1_{0\leqslant x\leqslant z},
$$ 
and
$$
f_{X\mid Z}(x\mid z)=\frac{\Gamma(\alpha+\beta)}{\Gamma(\alpha)\Gamma(\beta)z^{\alpha+\beta-1}}x^{\alpha-1}(z-x)^{\beta-1}\mathbf 1_{0\leqslant x\leqslant z}.
$$
In other words, $X=UZ$ where $U$ is independent of $Z$ and beta $(\alpha,\beta)$.
