Average Error: 0.4 → 0.3
Time: 1.4min
Precision: binary64
Cost: 20032
\[0 \leq u1 \land u1 \leq 1 \land 0 \leq u2 \land u2 \leq 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\]
\[0.5 + \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \cdot \frac{\sqrt{-2 \cdot \log u1}}{6}\]
\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
0.5 + \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \cdot \frac{\sqrt{-2 \cdot \log u1}}{6}
(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
 (+ 0.5 (* (cos (* (* 2.0 PI) u2)) (/ (sqrt (* -2.0 (log u1))) 6.0))))
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 0.5 + (cos((2.0 * ((double) M_PI)) * u2) * (sqrt(-2.0 * log(u1)) / 6.0));
}

Error

Bits error versus u1

Bits error versus u2

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Alternatives

Alternative 1
Error1.2
Cost13248
\[0.5 + \frac{\sqrt{-2 \cdot \log u1}}{6}\]
Alternative 2
Error52.9
Cost64
\[1\]

Error

Time

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. Using strategy rm
  3. Applied associate-*l/_binary640.3

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

    \[\leadsto \frac{\color{blue}{\sqrt{-2 \cdot \log u1}}}{6} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5\]
  5. Using strategy rm
  6. Applied *-un-lft-identity_binary640.3

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

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

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

    \[\leadsto \left(\color{blue}{1} \cdot \frac{\sqrt{-2 \cdot \log u1}}{6}\right) \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5\]
  10. Using strategy rm
  11. Applied +-commutative_binary640.3

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

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

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

Reproduce

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