Trouble with integral expressing $\mathbb E[X^2]$ where $X \sim N(0,1)$ Let $X \sim N(0,1)$
Then to find $E[X^2]$, we can do:
$$
\int_{-\infty}^\infty x^2\frac{1}{\sqrt{2\pi}}e^{-\frac{x^2}{2}} dx
$$
Let's say we didn't know this is an odd function, and decided to take the integral by splitting it into 2 pieces:
$$
\frac{1}{\sqrt{2\pi}} \left( \int_{-\infty}^0 x^2e^{-\frac{x^2}{2}} \, dx + \int_0^\infty x^2 e^{-\frac{x^2}{2}} \, dx \right)
$$
Then substitute $t = \frac{x^2}{2}$, we get:
$$
\frac{1}{\sqrt{2\pi}} \left( \int_\infty^0 \sqrt{2t}e^{-t} \, dt + \int_0^\infty \sqrt{2t}e^{-t} \, dt \right) \\
= \frac{1}{\sqrt{2\pi}} \left( - \int_0^\infty \sqrt{2t}e^{-t} \, dt + \int_0^\infty \sqrt{2t}e^{-t} \, dt \right) 
= 0
$$
Which is $= 0 $, but obviously it shouldn't be $0$. Those two integrals should be adding together instead of canceling each other out. Where did I make a mistake in my math? Thanks!

Let
\begin{align}
I(a) &= \int\limits_{0}^{\infty} \mathrm{e}^{-ax^{2}} \mathrm{d}x \\
&= \frac{1}{\sqrt{a}} \int\limits_{0}^{\infty} \mathrm{e}^{-y^{2}} \mathrm{d}y \\
&= \frac{\sqrt{\pi}}{2} \frac{1}{\sqrt{a}} \mathrm{erf}(y) \Big|_{0}^{\infty} \\
&= \frac{\sqrt{\pi}}{2} \frac{1}{\sqrt{a}}
\end{align}
using the substitution $y^{2} = ax^{2}$.
Then
\begin{align}
I &= \frac{1}{\sqrt{2 \pi}} \int\limits_{-\infty}^{\infty} x^{2} \mathrm{e}^{-x^{2}/2} \mathrm{d}x 
= \frac{2}{\sqrt{2 \pi}} \int\limits_{0}^{\infty} x^{2} \mathrm{e}^{-x^{2}/2} \mathrm{d}x \\
&= -\frac{2}{\sqrt{2 \pi}} \lim_{a \to 1/2} \frac{\partial I(a)}{\partial a} 
= \frac{2}{\sqrt{2 \pi}} \lim_{a \to 1/2} \int\limits_{0}^{\infty} x^{2} \mathrm{e}^{-ax^{2}} \mathrm{d}x 
= \frac{2}{\sqrt{2 \pi}} \int\limits_{0}^{\infty} x^{2} \mathrm{e}^{-x^{2}/2} \mathrm{d}x \\
&= -\frac{2}{\sqrt{2 \pi}} \frac{\sqrt{\pi}}{2} \lim_{a \to 1/2} \frac{\partial}{\partial a} a^{-1/2}
= -\frac{1}{\sqrt{2}} \left(-\frac{1}{2}\right) \lim_{a \to 1/2} a^{-3/2} \\
&= 1
\end{align}
