Average Error: 0.4 → 0.2
Time: 15.0s
Precision: binary64
\[\left(0 \leq u1 \land u1 \leq 1\right) \land \left(0 \leq u2 \land u2 \leq 1\right)\]
\[\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 \]
\[\mathsf{fma}\left(\sqrt{-0.05555555555555555 \cdot \log u1}, \cos \left(2 \cdot \left(\pi \cdot u2\right)\right), 0.5\right) \]
\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
\mathsf{fma}\left(\sqrt{-0.05555555555555555 \cdot \log u1}, \cos \left(2 \cdot \left(\pi \cdot u2\right)\right), 0.5\right)
(FPCore (u1 u2)
 :precision binary64
 (+
  (* (* (/ 1.0 6.0) (pow (* -2.0 (log u1)) 0.5)) (cos (* (* 2.0 PI) u2)))
  0.5))
(FPCore (u1 u2)
 :precision binary64
 (fma (sqrt (* -0.05555555555555555 (log u1))) (cos (* 2.0 (* PI u2))) 0.5))
double code(double u1, double u2) {
	return (((1.0 / 6.0) * pow((-2.0 * log(u1)), 0.5)) * cos((2.0 * ((double) M_PI)) * u2)) + 0.5;
}
double code(double u1, double u2) {
	return fma(sqrt(-0.05555555555555555 * log(u1)), cos(2.0 * (((double) M_PI) * u2)), 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. Applied add-sqr-sqrt_binary640.4

    \[\leadsto \left(\color{blue}{\left(\sqrt{\frac{1}{6}} \cdot \sqrt{\frac{1}{6}}\right)} \cdot {\left(-2 \cdot \log u1\right)}^{0.5}\right) \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
  3. Applied associate-*l*_binary640.3

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

    \[\leadsto \left(\sqrt{\frac{1}{6}} \cdot \color{blue}{\left(\sqrt{-2 \cdot \log u1} \cdot \sqrt{0.16666666666666666}\right)}\right) \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
  5. Applied sqrt-unprod_binary640.3

    \[\leadsto \left(\sqrt{\frac{1}{6}} \cdot \color{blue}{\sqrt{\left(-2 \cdot \log u1\right) \cdot 0.16666666666666666}}\right) \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
  6. Applied sqrt-unprod_binary640.3

    \[\leadsto \color{blue}{\sqrt{\frac{1}{6} \cdot \left(\left(-2 \cdot \log u1\right) \cdot 0.16666666666666666\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
  7. Simplified0.2

    \[\leadsto \sqrt{\color{blue}{\left(-2 \cdot \log u1\right) \cdot 0.027777777777777776}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
  8. Taylor expanded in u1 around 0 0.2

    \[\leadsto \color{blue}{\sqrt{-0.05555555555555555 \cdot \log u1} \cdot \cos \left(2 \cdot \left(\pi \cdot u2\right)\right) + 0.5} \]
  9. Simplified0.2

    \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{-0.05555555555555555 \cdot \log u1}, \cos \left(2 \cdot \left(\pi \cdot u2\right)\right), 0.5\right)} \]
  10. Final simplification0.2

    \[\leadsto \mathsf{fma}\left(\sqrt{-0.05555555555555555 \cdot \log u1}, \cos \left(2 \cdot \left(\pi \cdot u2\right)\right), 0.5\right) \]

Reproduce

herbie shell --seed 2021275 
(FPCore (u1 u2)
  :name "normal distribution"
  :precision binary64
  :pre (and (and (<= 0.0 u1) (<= u1 1.0)) (and (<= 0.0 u2) (<= u2 1.0)))
  (+ (* (* (/ 1.0 6.0) (pow (* -2.0 (log u1)) 0.5)) (cos (* (* 2.0 PI) u2))) 0.5))