Average Error: 0.4 → 0.3
Time: 1.4m
Precision: 64
Internal Precision: 128
\[\left(\frac{1}{6} \cdot {\left(-2 \cdot \log u1\right)}^{0.5}\right) \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5\]
\[(\left(\cos \left(\left(\pi \cdot 2\right) \cdot u2\right)\right) \cdot \left(\frac{{\left(-2 \cdot \log u1\right)}^{0.5}}{6}\right) + 0.5)_*\]

Error

Bits error versus u1

Bits error versus u2

Derivation

  1. Initial program 0.4

    \[\left(\frac{1}{6} \cdot {\left(-2 \cdot \log u1\right)}^{0.5}\right) \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5\]
  2. Simplified0.3

    \[\leadsto \color{blue}{(\left(\cos \left(u2 \cdot \left(2 \cdot \pi\right)\right)\right) \cdot \left(\frac{{\left(-2 \cdot \log u1\right)}^{0.5}}{6}\right) + 0.5)_*}\]
  3. Using strategy rm
  4. Applied div-inv0.4

    \[\leadsto (\left(\cos \left(u2 \cdot \left(2 \cdot \pi\right)\right)\right) \cdot \color{blue}{\left({\left(-2 \cdot \log u1\right)}^{0.5} \cdot \frac{1}{6}\right)} + 0.5)_*\]
  5. Using strategy rm
  6. Applied associate-*r/0.3

    \[\leadsto (\left(\cos \left(u2 \cdot \left(2 \cdot \pi\right)\right)\right) \cdot \color{blue}{\left(\frac{{\left(-2 \cdot \log u1\right)}^{0.5} \cdot 1}{6}\right)} + 0.5)_*\]
  7. Final simplification0.3

    \[\leadsto (\left(\cos \left(\left(\pi \cdot 2\right) \cdot u2\right)\right) \cdot \left(\frac{{\left(-2 \cdot \log u1\right)}^{0.5}}{6}\right) + 0.5)_*\]

Reproduce

herbie shell --seed 2019090 +o rules:numerics
(FPCore (u1 u2)
  :name "normal distribution"
  :pre (and (<= 0 u1 1) (<= 0 u2 1))
  (+ (* (* (/ 1 6) (pow (* -2 (log u1)) 0.5)) (cos (* (* 2 PI) u2))) 0.5))