= Solution
For <normal rejection sampling with an exponential envelope>, complete the square in the <probability density function> ratio:
$$
\frac{h(x)}{g(x)}
=\frac{\sqrt{2/\pi}}{\lambda}
\exp\!\left(-\frac{x^2}{2}+\lambda x\right)
=\frac{\sqrt{2/\pi}}{\lambda}e^{\lambda^2/2}
e^{-(x-\lambda)^2/2}.
$$
The maximum occurs at $x=\lambda$, which lies in the support because $\lambda>0$. Thus
$$
\boxed{M(\lambda)=\frac{\sqrt{2/\pi}}{\lambda}e^{\lambda^2/2}
=\sqrt{\frac{2e^{\lambda^2}}{\pi\lambda^2}}.}
$$
The PDF exponent is $e^{\lambda^2}$ inside the square root; this distinction is lost in the converted TeX.
The acceptance rule simplifies to
$$
U\leq e^{-(Y-\lambda)^2/2},
\qquad Y\sim\operatorname{Exp}(\lambda).
$$
An exponential proposal can be generated as $Y=-\lambda^{-1}\log V$ from an <independent> <uniform distribution> value $V$. Since the target is normalized, the overall acceptance <probability> is $1/M(\lambda)$. To maximize it,
$$
\frac{d}{d\lambda}\log M=\lambda-\lambda^{-1},
\qquad
\frac{d^2}{d\lambda^2}\log M=1+\lambda^{-2}>0.
$$
Therefore \b[the optimal rate is $\lambda=1$], with acceptance <probability> $\sqrt{\pi/(2e)}$.
Finally, give each accepted <half-normal distribution> value $Y$ an <independent> fair sign $R\in\{-1,1\}$ and output $Z=RY$. On each half-line its <probability density function> is half the reflected <half-normal distribution> <probability density function>:
$$
p_Z(z)=\frac12h(|z|)=\frac1{\sqrt{2\pi}}e^{-z^2/2}.
$$
Consequently \b[$Z\sim N(0,1)$]. The sign must be drawn independently; rejection itself does not supply it.
Back to article page