Solving integration of Normal CDF problem to get $\sqrt{\frac{2}{\pi}}$ I encountered the following example:

(Folded Normal). Let $Y = \vert Z \vert$ with $Z ∼ N(0, 1)$. The distribution of $Y$ is called a Folded Normal with parameters $\mu = 0$ and $\sigma^2 = 1$. At first sight, $Y$ may seem tricky to deal with since the absolute value function is not differentiable at $0$ (due to its sharp corner), but $Y$ has a perfectly valid continuous distribution.
$$E(Y) = E \vert Z \vert = \int_{-\infty}^\infty \vert z \vert \dfrac{1}{\sqrt{2\pi}} e^{-z^2/2} \ dz = 2 \int_0^\infty z \dfrac{1}{\sqrt{2\pi}} e^{-z^2/2} \ dz = \sqrt{\dfrac{2}{\pi}}.$$

I can tell that the authors got $\int_{-\infty}^\infty \vert z \vert \dfrac{1}{\sqrt{2\pi}} e^{-z^2/2} \ dz = 2 \int_0^\infty z \dfrac{1}{\sqrt{2\pi}} e^{-z^2/2} \ dz$ by the symmetry of the normal distribution; that's fine.
However, the problem arises when attempting to integrate. If I'm not mistaken, in order to use integration by parts, we need to find the integral of $e^{-z^2/2}$. But, according to WolframAlpha, this is $\sqrt{\dfrac{\pi}{2}} \text{erf} \left( \dfrac{z}{\sqrt{2}} \right)$. This raises two questions for me:

*

*How do the authors integrate this problem to get $\sqrt{\dfrac{2}{\pi}}$?


*Given that this is an inherent property of trying to integration the Normal CDF, how do people in general solve CDF problems for the Normal distribution? After all, the Normal distribution is, probably, the most common distribution (in applications), and people do calculations with it all the time. Is it the case that all of these calculations are numerical (using computational software)? Or is this actually solved analytically in some other way that I'm not aware of?
Thank you.
 A: While $\int e^{-x^2} dx$ is non-elementary (this is sort of the "simplest" form of the integral you're trying to handle), $\int_{-\infty}^\infty  e^{-x^2}dx$ is actually quite doable owing to the fact it's over an interval (not just looking for any antiderivative like the indefinite integral).
Dr. Peyam, a math YouTuber, has compiled a number of ways to calculate this integral, known as the Gaussian integral. You can see the playlist here. 

I'm mostly a fan of the first video, which uses polar coordinates. Essentially, it can be shown that
$$\mathcal I = \int_{-\infty}^\infty e^{-x^2}dx \implies \mathcal I^2 = \int_{-\infty}^\infty \int_{-\infty}^\infty e^{-(x^2+y^2)}\; dx\; dy$$
From here, the usual polar coordinate substitutions apply ($x=r \cos \theta, y = r \sin \theta, dx\;dy = r \; dr \; d\theta$) then give us
$$\mathcal I^2 = \int_0^{2 \pi} \int_0^\infty re^{-r^2} \; dr \; d\theta$$
which is easily evaluated via a $u$-substitution, $u=r^2 \implies du = 2r \; dr$, and you can go from there to show $\mathcal I^2 = \pi$. And thus, $\mathcal I = \sqrt \pi$, and by symmetry
$$\int_0^\infty e^{-x^2} dx = \frac{\sqrt \pi}2$$
More detail and explanation can be found in Dr. Peyam's video here.

That said, aside from the constants involved, the above also somewhat spoils how you find your integral. You see, you're looking to handle $\int ze^{-z^2}dz$, not $\int e^{-z^2}dz$ (just with a few more constants involved). As noted above, a $u$-substitution of $u=z^2 \implies du = 2z\; dz$ handles this quite adequately once you go through the math. 
In your case, just account for the constants as you apply this analogously to your case, and you shouldn't have any difficulty.
