# Box-Muller
An algorithm for computing normal distribution from uniform distribution.
Let $U_1,U_2\leftarrow \text{Uniform}(0,1)$.
define $Z_0=\sqrt{-2\ln(U_1)}\cdot \cos(2\pi U_2)$, $Z_1=\sqrt{-2\ln(U_1)}\cdot \sin(2\pi U_2)$
Then $Z_0,Z_1$ are independent random variables with normal distribution.
Proof:
Let $R=\sqrt{-2\ln(U_1)}$ and $\Theta=2\pi U_2$ . $R$ and $\Theta$ are independent random variable because $U_1$ and $U_2$ are independent. $\Theta\leftarrow \text{Uniform}(0,2\pi)$ i.e., $f_\Theta(\theta)=1/2\pi$ . $R$ follows a Rayleigh distribution because:
The cumulative distribution function (CDF) of $R$ is: $P(r\le R)=P\bigg(r \le \sqrt{-2\ln(U_1)}\bigg)=P\big(U_1\ge e^{-r^2/2}\big)=1-P\big(U_1<e^{-r^2/2}\big)=1-e^{-r^2/2} $ and $f_R(r)=re^{-r^2/2}$ .
we have $\bigg|\frac{\partial(Z_0,Z_1)}{\partial (r,\theta)}\bigg|^{-1}=r$. $f_{R,\Theta}(r,\theta)=f_R(r)\cdot f_\Theta(\theta)=re^{-r^2/2}\cdot\frac{1}{2\pi}=\frac{re^{-r^2/2}}{2\pi}$
$f_{Z_0,Z_1}(z_0,z_1)dZ_0Z_1=f_{R,\Theta}(r,\theta)\cdot\bigg|\frac{\partial(Z_0,Z_1)}{\partial (r,\theta)}\bigg|^{-1}dr\cdot d\theta=\frac{e^{r^2/2}}{2\pi}=\frac{e^{(z_0^2+z_1^2)/2}}{2\pi}$
It follows that $f_{Z_0}(z_0)=\int_{-\infty}^\infty f_{Z_0,Z_1}(z_0,z_1)dz_1=\frac{e^{z_0^2/2}}{2\pi}$ i.e., $Z_0$ is a random variable with normal distribution and $Z_1$ as well .
Q.E.D.
## Created 2024-12-13 17:44