Average Error: 0.4 → 0.3
Time: 11.6s
Precision: 64
\[0.0 \le u1 \le 1 \land 0.0 \le u2 \le 1\]
\[\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(1 \cdot \frac{{\left(-2 \cdot \log u1\right)}^{0.5}}{6}, \cos \left(\left(2 \cdot \pi\right) \cdot u2\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(1 \cdot \frac{{\left(-2 \cdot \log u1\right)}^{0.5}}{6}, \cos \left(\left(2 \cdot \pi\right) \cdot u2\right), 0.5\right)
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((1.0 * (pow((-2.0 * log(u1)), 0.5) / 6.0)), cos(((2.0 * ((double) M_PI)) * u2)), 0.5);
}

Error

Bits error versus u1

Bits error versus u2

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

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.4

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

    \[\leadsto \mathsf{fma}\left(\color{blue}{\left(1 \cdot \frac{1}{6}\right)} \cdot {\left(-2 \cdot \log u1\right)}^{0.5}, \cos \left(\left(2 \cdot \pi\right) \cdot u2\right), 0.5\right)\]
  5. Applied associate-*l*0.4

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

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

    \[\leadsto \mathsf{fma}\left(1 \cdot \frac{{\left(-2 \cdot \log u1\right)}^{0.5}}{6}, \cos \left(\left(2 \cdot \pi\right) \cdot u2\right), 0.5\right)\]

Reproduce

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