I'm trying to understand a derivation of the density of a Chi-Square distribution with one degree of freedom that my professor gave in class. Here are the steps:
\begin{align} p(y) &= \int_{-\infty}^{+\infty} p(x,y)dx\\\ &= \int_{-\infty}^{+\infty}p(y|x)p(x)dx\\ &=\int_{-\infty}^{+\infty}\delta(y-x^2)\frac{1}{\sqrt{2\pi}}e^{\frac{-x^2}{2}}dx \end{align}
Now we use the substitution $u=x^2$ to get:
\begin{align} p(y) &= 2\int_{0}^{+\infty} \delta(y-u)\frac{1}{\sqrt{2\pi}}\frac{e^{\frac{-u}{2}}}{2\sqrt{u}}du\\ &= \frac{1}{\sqrt{2\pi}}\frac{e^{\frac{-y}{2}}}{\sqrt{y}} \end{align}
The substitution puzzles me for a few reasons. Firstly, it removes integrating over the negative values, therefore how can we evaluate the dirac delta? Secondly, where do we get that extra factor of 2 from which fortuitously cancels the one in the Jacobian? I've been looking at this a while, help anyone?
Note $\delta(y-(-x)^2) \frac{1}{\sqrt{2 \pi}} e^{-(-x)^2/2} = \delta(y-x^2) \frac{1}{\sqrt{2 \pi}} e^{-x^2/2}$, so $\int_{-\infty}^\infty \delta(y-x^2) \frac{1}{\sqrt{2 \pi}} e^{-x^2/2} dx$ can be written as $\int_0^\infty \delta(y-(-x)^2) \frac{1}{\sqrt{2 \pi}} e^{-(-x)^2/2} dx + \int_0^\infty \delta(y-x^2) \frac{1}{\sqrt{2 \pi}} e^{-x^2/2} dx$ where the first term corresponds to negative $x$ and the second to positive $x$ in the original integral. Thus, noting the equivalence mentioned, $\int_{-\infty}^\infty \delta(y-x^2) \frac{1}{\sqrt{2 \pi}} e^{-x^2/2} dx= 2 \int_0^\infty \delta(y-x^2) \frac{1}{\sqrt{2 \pi}} e^{-x^2/2} dx$. Then use the sifting property of the Dirac delta.