Average Error: 0.4 → 0.4
Time: 32.4s
Precision: 64
\[0 \le u1 \le 1 \land 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{log1p}\left(\left(\mathsf{expm1}\left(\left(\mathsf{log1p}\left(\left(\mathsf{expm1}\left(\left(\mathsf{fma}\left(\left(\cos \left(2 \cdot \left(u2 \cdot \pi\right)\right) \cdot {\left({-2}^{1.0} \cdot {\left(\log u1\right)}^{1.0}\right)}^{0.5}\right), \frac{1}{6}, 0.5\right)\right)\right)\right)\right)\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
\mathsf{log1p}\left(\left(\mathsf{expm1}\left(\left(\mathsf{log1p}\left(\left(\mathsf{expm1}\left(\left(\mathsf{fma}\left(\left(\cos \left(2 \cdot \left(u2 \cdot \pi\right)\right) \cdot {\left({-2}^{1.0} \cdot {\left(\log u1\right)}^{1.0}\right)}^{0.5}\right), \frac{1}{6}, 0.5\right)\right)\right)\right)\right)\right)\right)\right)\right)
double f(double u1, double u2) {
        double r1920872 = 1.0;
        double r1920873 = 6.0;
        double r1920874 = r1920872 / r1920873;
        double r1920875 = -2.0;
        double r1920876 = u1;
        double r1920877 = log(r1920876);
        double r1920878 = r1920875 * r1920877;
        double r1920879 = 0.5;
        double r1920880 = pow(r1920878, r1920879);
        double r1920881 = r1920874 * r1920880;
        double r1920882 = 2.0;
        double r1920883 = atan2(1.0, 0.0);
        double r1920884 = r1920882 * r1920883;
        double r1920885 = u2;
        double r1920886 = r1920884 * r1920885;
        double r1920887 = cos(r1920886);
        double r1920888 = r1920881 * r1920887;
        double r1920889 = r1920888 + r1920879;
        return r1920889;
}

double f(double u1, double u2) {
        double r1920890 = 2.0;
        double r1920891 = u2;
        double r1920892 = atan2(1.0, 0.0);
        double r1920893 = r1920891 * r1920892;
        double r1920894 = r1920890 * r1920893;
        double r1920895 = cos(r1920894);
        double r1920896 = -2.0;
        double r1920897 = 1.0;
        double r1920898 = pow(r1920896, r1920897);
        double r1920899 = u1;
        double r1920900 = log(r1920899);
        double r1920901 = pow(r1920900, r1920897);
        double r1920902 = r1920898 * r1920901;
        double r1920903 = 0.5;
        double r1920904 = pow(r1920902, r1920903);
        double r1920905 = r1920895 * r1920904;
        double r1920906 = 0.16666666666666666;
        double r1920907 = fma(r1920905, r1920906, r1920903);
        double r1920908 = expm1(r1920907);
        double r1920909 = log1p(r1920908);
        double r1920910 = expm1(r1920909);
        double r1920911 = log1p(r1920910);
        return r1920911;
}

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

    \[\leadsto \color{blue}{\mathsf{log1p}\left(\left(\mathsf{expm1}\left(\left(\mathsf{fma}\left(\left(\cos \left(u2 \cdot \left(2 \cdot \pi\right)\right)\right), \left(\frac{{\left(-2 \cdot \log u1\right)}^{0.5}}{6}\right), 0.5\right)\right)\right)\right)\right)}\]
  5. Taylor expanded around -inf 62.0

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

    \[\leadsto \mathsf{log1p}\left(\color{blue}{\left(\mathsf{expm1}\left(\left(\mathsf{fma}\left(\left({\left({\left(0 + \log u1\right)}^{1.0} \cdot {-2}^{1.0}\right)}^{0.5}\right), \left(\frac{1}{6} \cdot \cos \left(\left(\pi \cdot 2\right) \cdot u2\right)\right), 0.5\right)\right)\right)\right)}\right)\]
  7. Using strategy rm
  8. Applied log1p-expm1-u0.4

    \[\leadsto \mathsf{log1p}\left(\left(\mathsf{expm1}\left(\color{blue}{\left(\mathsf{log1p}\left(\left(\mathsf{expm1}\left(\left(\mathsf{fma}\left(\left({\left({\left(0 + \log u1\right)}^{1.0} \cdot {-2}^{1.0}\right)}^{0.5}\right), \left(\frac{1}{6} \cdot \cos \left(\left(\pi \cdot 2\right) \cdot u2\right)\right), 0.5\right)\right)\right)\right)\right)\right)}\right)\right)\right)\]
  9. Simplified0.4

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

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

Reproduce

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