Average Error: 0.4 → 0.4
Time: 32.7s
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\]
\[\log \left(\mathsf{expm1}\left(\mathsf{log1p}\left(e^{\mathsf{fma}\left(\frac{{\left(-2 \cdot \log u1\right)}^{0.5}}{6} \cdot 1, \cos \left(2 \cdot \left(\pi \cdot u2\right)\right), 0.5\right)}\right)\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(\mathsf{expm1}\left(\mathsf{log1p}\left(e^{\mathsf{fma}\left(\frac{{\left(-2 \cdot \log u1\right)}^{0.5}}{6} \cdot 1, \cos \left(2 \cdot \left(\pi \cdot u2\right)\right), 0.5\right)}\right)\right)\right)
double f(double u1, double u2) {
        double r1875008 = 1.0;
        double r1875009 = 6.0;
        double r1875010 = r1875008 / r1875009;
        double r1875011 = -2.0;
        double r1875012 = u1;
        double r1875013 = log(r1875012);
        double r1875014 = r1875011 * r1875013;
        double r1875015 = 0.5;
        double r1875016 = pow(r1875014, r1875015);
        double r1875017 = r1875010 * r1875016;
        double r1875018 = 2.0;
        double r1875019 = atan2(1.0, 0.0);
        double r1875020 = r1875018 * r1875019;
        double r1875021 = u2;
        double r1875022 = r1875020 * r1875021;
        double r1875023 = cos(r1875022);
        double r1875024 = r1875017 * r1875023;
        double r1875025 = r1875024 + r1875015;
        return r1875025;
}

double f(double u1, double u2) {
        double r1875026 = -2.0;
        double r1875027 = u1;
        double r1875028 = log(r1875027);
        double r1875029 = r1875026 * r1875028;
        double r1875030 = 0.5;
        double r1875031 = pow(r1875029, r1875030);
        double r1875032 = 6.0;
        double r1875033 = r1875031 / r1875032;
        double r1875034 = 1.0;
        double r1875035 = r1875033 * r1875034;
        double r1875036 = 2.0;
        double r1875037 = atan2(1.0, 0.0);
        double r1875038 = u2;
        double r1875039 = r1875037 * r1875038;
        double r1875040 = r1875036 * r1875039;
        double r1875041 = cos(r1875040);
        double r1875042 = fma(r1875035, r1875041, r1875030);
        double r1875043 = exp(r1875042);
        double r1875044 = log1p(r1875043);
        double r1875045 = expm1(r1875044);
        double r1875046 = log(r1875045);
        return r1875046;
}

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}{\mathsf{fma}\left(\frac{{\left(-2 \cdot \log u1\right)}^{0.5}}{\frac{6}{1}}, \cos \left(2 \cdot \left(\pi \cdot u2\right)\right), 0.5\right)}\]
  3. Using strategy rm
  4. Applied add-log-exp0.3

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

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

    \[\leadsto \log \color{blue}{\left(e^{\frac{{\left(-2 \cdot \log u1\right)}^{0.5}}{\frac{6}{1}} \cdot \cos \left(2 \cdot \left(\pi \cdot u2\right)\right)} \cdot e^{0.5}\right)}\]
  8. Using strategy rm
  9. Applied expm1-log1p-u0.4

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

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

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

Reproduce

herbie shell --seed 2019174 +o rules:numerics
(FPCore (u1 u2)
  :name "normal distribution"
  :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))