<s>[INST] Problem with an identity involving fractions. In a proof concerning normal distributions, the following step is a little difficult to understand:
$$\int_{-\infty}^\infty \frac{1}{\sqrt{2\pi}\sigma_Y} e^{-{(z-x-\mu_Y)^2 \over 2\sigma_Y^2}} \frac{1}{\sqrt{2\pi}\sigma_X} e^{-{(x-\mu_X)^2 \over 2\sigma_X^2}} \, dx$$
$$= \int_{-\infty}^\infty \frac{1}{\sqrt{2\pi}\sqrt{\sigma_X^2+\sigma_Y^2}} \exp \left[ - { (z-(\mu_X+\mu_Y))^2 \over 2(\sigma_X^2+\sigma_Y^2) } \right]  \frac{1}{\sqrt{2\pi} \frac{\sigma_X\sigma_Y}{\sqrt{\sigma_X^2+\sigma_Y^2}}} \exp \left[ - \frac{\left(x-\frac{\sigma_X^2(z-\mu_Y)+\sigma_Y^2\mu_X}{\sigma_X^2+\sigma_Y^2}\right)^2}{2\left(\frac{\sigma_X\sigma_Y}{\sqrt{\sigma_X^2+\sigma_Y^2}}\right)^2} \right] \, dx$$
The part that I'm not sure about is why
$$ e^{-{(z-x-\mu_Y)^2 \over 2\sigma_Y^2}} e^{-{(x-\mu_X)^2 \over 2\sigma_X^2}} = \exp \left[ - { (z-(\mu_X+\mu_Y))^2 \over 2(\sigma_X^2+\sigma_Y^2) } \right]  \exp \left[ - \frac{\left(x-\frac{\sigma_X^2(z-\mu_Y)+\sigma_Y^2\mu_X}{\sigma_X^2+\sigma_Y^2}\right)^2}{2\left(\frac{\sigma_X\sigma_Y}{\sqrt{\sigma_X^2+\sigma_Y^2}}\right)^2} \right] $$
In other words, why
$$ -{(z-x-\mu_Y)^2 \over 2\sigma_Y^2}-{(x-\mu_X)^2 \over 2\sigma_X^2} = - { (z-(\mu_X+\mu_Y))^2 \over 2(\sigma_X^2+\sigma_Y^2) } - \frac{\left(x-\frac{\sigma_X^2(z-\mu_Y)+\sigma_Y^2\mu_X}{\sigma_X^2+\sigma_Y^2}\right)^2}{2\left(\frac{\sigma_X\sigma_Y}{\sqrt{\sigma_X^2+\sigma_Y^2}}\right)^2} $$
Any help is appreciated.
 [/INST] To prove that
$$
-{(z-x-\mu_Y)^2 \over 2\sigma_Y^2}-{(x-\mu_X)^2 \over 2\sigma_X^2} = - { (z-(\mu_X+\mu_Y))^2 \over 2(\sigma_X^2+\sigma_Y^2) } - \frac{\left(x-\frac{\sigma_X^2(z-\mu_Y)+\sigma_Y^2\mu_X}{\sigma_X^2+\sigma_Y^2}\right)^2}{2\left(\frac{\sigma_X\sigma_Y}{\sqrt{\sigma_X^2+\sigma_Y^2}}\right)^2}
$$
we could first change the signs and multiply by $2$. Then we could multiply by $\sigma_X^2\sigma_Y^2(\sigma_X^2+\sigma_Y^2)$ to have the LHS
$$
(z-x-\mu_Y)^2\sigma_X^2(\sigma_X^2+\sigma_Y^2)+(x-\mu_X)^2\sigma_Y^2(\sigma_X^2+\sigma_Y^2)
$$
and RHS
$$
(z-\mu_X-\mu_Y)^2\sigma_X^2\sigma_Y^2+\left[x(\sigma_X^2+\sigma_Y^2)-\sigma_X^2 z+\sigma_X^2\mu_Y-\sigma_Y^2\mu_X\right]^2
$$
and it is now relatively simple to check term by term that the two sides are equal. For instance we find $z^2\sigma_X^2(\sigma_X^2+\sigma_Y^2)$ on the LHS and $z^2\sigma_X^2\sigma_Y^2+\sigma_X^4 z^2$ on the RHS, so those match up. As another example $-2z\mu_Y\sigma_X^2(\sigma_X^2+\sigma_Y^2)$ from LHS is found as $-2z\mu_Y\sigma_X^2\sigma_Y^2-2z\mu_Y\sigma_X^4$ on the RHS, so those also match up. The term $-2z\mu_X\sigma_X^2\sigma_Y^2$ stemming from the first term on the RHS is cancelled by the second term where we find $2\sigma_X^2 z\sigma_Y^2\mu_X$, so this letter combination not found on the LHS is cancelled on the RHS anyway. Checking the other terms is similar and they have a nice repetitive pattern in the reasoning behind the matching up process.
</s>