Average Error: 0.4 → 0.2
Time: 7.0s
Precision: binary64
\[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 \]
\[\log \left(e^{0.5} \cdot e^{\sqrt{\left(-2 \cdot \log u1\right) \cdot 0.027777777777777776} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)}\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
\log \left(e^{0.5} \cdot e^{\sqrt{\left(-2 \cdot \log u1\right) \cdot 0.027777777777777776} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)}\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
 (log
  (*
   (exp 0.5)
   (exp
    (*
     (sqrt (* (* -2.0 (log u1)) 0.027777777777777776))
     (cos (* (* 2.0 PI) u2)))))))
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 log(exp(0.5) * exp(sqrt((-2.0 * log(u1)) * 0.027777777777777776) * cos((2.0 * ((double) M_PI)) * u2)));
}

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}{0.5 + \left(0.16666666666666666 \cdot \sqrt{-2 \cdot \log u1}\right) \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)} \]
  3. Using strategy rm
  4. Applied add-sqr-sqrt_binary640.4

    \[\leadsto 0.5 + \left(\color{blue}{\left(\sqrt{0.16666666666666666} \cdot \sqrt{0.16666666666666666}\right)} \cdot \sqrt{-2 \cdot \log u1}\right) \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  5. Applied associate-*l*_binary640.4

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

    \[\leadsto 0.5 + \left(\sqrt{0.16666666666666666} \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) \]
  7. Using strategy rm
  8. Applied sqrt-unprod_binary640.3

    \[\leadsto 0.5 + \left(\sqrt{0.16666666666666666} \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) \]
  9. Applied sqrt-unprod_binary640.3

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

    \[\leadsto 0.5 + \sqrt{\color{blue}{\left(-2 \cdot \log u1\right) \cdot 0.027777777777777776}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  11. Using strategy rm
  12. Applied add-log-exp_binary640.2

    \[\leadsto 0.5 + \color{blue}{\log \left(e^{\sqrt{\left(-2 \cdot \log u1\right) \cdot 0.027777777777777776} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)}\right)} \]
  13. Applied add-log-exp_binary640.2

    \[\leadsto \color{blue}{\log \left(e^{0.5}\right)} + \log \left(e^{\sqrt{\left(-2 \cdot \log u1\right) \cdot 0.027777777777777776} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)}\right) \]
  14. Applied sum-log_binary640.2

    \[\leadsto \color{blue}{\log \left(e^{0.5} \cdot e^{\sqrt{\left(-2 \cdot \log u1\right) \cdot 0.027777777777777776} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)}\right)} \]
  15. Final simplification0.2

    \[\leadsto \log \left(e^{0.5} \cdot e^{\sqrt{\left(-2 \cdot \log u1\right) \cdot 0.027777777777777776} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)}\right) \]

Reproduce

herbie shell --seed 2021204 
(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))