Average Error: 24.2 → 7.6
Time: 42.4s
Precision: 64
\[x - \frac{\log \left(\left(1.0 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -1.200391987755555 \cdot 10^{-81}:\\ \;\;\;\;x - \frac{1}{t} \cdot \left(\log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right) + \log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right)\right)\\ \mathbf{elif}\;z \le 1.9712400723203086 \cdot 10^{-138}:\\ \;\;\;\;x - \mathsf{fma}\left(\frac{z}{t}, y \cdot 1.0, \mathsf{fma}\left(0.5, \frac{\left(z \cdot z\right) \cdot y}{t}, \frac{\log 1.0}{t}\right)\right)\\ \mathbf{elif}\;z \le 8.16242381116947 \cdot 10^{-121}:\\ \;\;\;\;x - \frac{1}{t} \cdot \left(\log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right) + \log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\mathsf{fma}\left(y, z \cdot \mathsf{fma}\left(z, 0.5, 1.0\right), \log 1.0\right)}{t}\\ \end{array}\]
x - \frac{\log \left(\left(1.0 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
\mathbf{if}\;z \le -1.200391987755555 \cdot 10^{-81}:\\
\;\;\;\;x - \frac{1}{t} \cdot \left(\log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right) + \log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right)\right)\\

\mathbf{elif}\;z \le 1.9712400723203086 \cdot 10^{-138}:\\
\;\;\;\;x - \mathsf{fma}\left(\frac{z}{t}, y \cdot 1.0, \mathsf{fma}\left(0.5, \frac{\left(z \cdot z\right) \cdot y}{t}, \frac{\log 1.0}{t}\right)\right)\\

\mathbf{elif}\;z \le 8.16242381116947 \cdot 10^{-121}:\\
\;\;\;\;x - \frac{1}{t} \cdot \left(\log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right) + \log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;x - \frac{\mathsf{fma}\left(y, z \cdot \mathsf{fma}\left(z, 0.5, 1.0\right), \log 1.0\right)}{t}\\

\end{array}
double f(double x, double y, double z, double t) {
        double r15069656 = x;
        double r15069657 = 1.0;
        double r15069658 = y;
        double r15069659 = r15069657 - r15069658;
        double r15069660 = z;
        double r15069661 = exp(r15069660);
        double r15069662 = r15069658 * r15069661;
        double r15069663 = r15069659 + r15069662;
        double r15069664 = log(r15069663);
        double r15069665 = t;
        double r15069666 = r15069664 / r15069665;
        double r15069667 = r15069656 - r15069666;
        return r15069667;
}

double f(double x, double y, double z, double t) {
        double r15069668 = z;
        double r15069669 = -1.200391987755555e-81;
        bool r15069670 = r15069668 <= r15069669;
        double r15069671 = x;
        double r15069672 = 1.0;
        double r15069673 = t;
        double r15069674 = r15069672 / r15069673;
        double r15069675 = expm1(r15069668);
        double r15069676 = y;
        double r15069677 = 1.0;
        double r15069678 = fma(r15069675, r15069676, r15069677);
        double r15069679 = cbrt(r15069678);
        double r15069680 = log(r15069679);
        double r15069681 = r15069679 * r15069679;
        double r15069682 = log(r15069681);
        double r15069683 = r15069680 + r15069682;
        double r15069684 = r15069674 * r15069683;
        double r15069685 = r15069671 - r15069684;
        double r15069686 = 1.9712400723203086e-138;
        bool r15069687 = r15069668 <= r15069686;
        double r15069688 = r15069668 / r15069673;
        double r15069689 = r15069676 * r15069677;
        double r15069690 = 0.5;
        double r15069691 = r15069668 * r15069668;
        double r15069692 = r15069691 * r15069676;
        double r15069693 = r15069692 / r15069673;
        double r15069694 = log(r15069677);
        double r15069695 = r15069694 / r15069673;
        double r15069696 = fma(r15069690, r15069693, r15069695);
        double r15069697 = fma(r15069688, r15069689, r15069696);
        double r15069698 = r15069671 - r15069697;
        double r15069699 = 8.16242381116947e-121;
        bool r15069700 = r15069668 <= r15069699;
        double r15069701 = fma(r15069668, r15069690, r15069677);
        double r15069702 = r15069668 * r15069701;
        double r15069703 = fma(r15069676, r15069702, r15069694);
        double r15069704 = r15069703 / r15069673;
        double r15069705 = r15069671 - r15069704;
        double r15069706 = r15069700 ? r15069685 : r15069705;
        double r15069707 = r15069687 ? r15069698 : r15069706;
        double r15069708 = r15069670 ? r15069685 : r15069707;
        return r15069708;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original24.2
Target15.9
Herbie7.6
\[\begin{array}{l} \mathbf{if}\;z \lt -2.8874623088207947 \cdot 10^{+119}:\\ \;\;\;\;\left(x - \frac{\frac{-0.5}{y \cdot t}}{z \cdot z}\right) - \frac{-0.5}{y \cdot t} \cdot \frac{\frac{2.0}{z}}{z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\log \left(1.0 + z \cdot y\right)}{t}\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if z < -1.200391987755555e-81 or 1.9712400723203086e-138 < z < 8.16242381116947e-121

    1. Initial program 15.4

      \[x - \frac{\log \left(\left(1.0 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Simplified10.7

      \[\leadsto \color{blue}{x - \frac{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)\right)}{t}}\]
    3. Using strategy rm
    4. Applied div-inv10.8

      \[\leadsto x - \color{blue}{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)\right) \cdot \frac{1}{t}}\]
    5. Using strategy rm
    6. Applied add-cube-cbrt10.8

      \[\leadsto x - \log \color{blue}{\left(\left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right)} \cdot \frac{1}{t}\]
    7. Applied log-prod10.8

      \[\leadsto x - \color{blue}{\left(\log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right) + \log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right)\right)} \cdot \frac{1}{t}\]

    if -1.200391987755555e-81 < z < 1.9712400723203086e-138

    1. Initial program 29.8

      \[x - \frac{\log \left(\left(1.0 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Simplified10.6

      \[\leadsto \color{blue}{x - \frac{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)\right)}{t}}\]
    3. Using strategy rm
    4. Applied div-inv10.7

      \[\leadsto x - \color{blue}{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)\right) \cdot \frac{1}{t}}\]
    5. Taylor expanded around 0 4.7

      \[\leadsto x - \color{blue}{\left(1.0 \cdot \frac{z \cdot y}{t} + \left(0.5 \cdot \frac{{z}^{2} \cdot y}{t} + \frac{\log 1.0}{t}\right)\right)}\]
    6. Simplified4.0

      \[\leadsto x - \color{blue}{\mathsf{fma}\left(\frac{z}{t}, y \cdot 1.0, \mathsf{fma}\left(0.5, \frac{\left(z \cdot z\right) \cdot y}{t}, \frac{\log 1.0}{t}\right)\right)}\]

    if 8.16242381116947e-121 < z

    1. Initial program 29.4

      \[x - \frac{\log \left(\left(1.0 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Simplified13.9

      \[\leadsto \color{blue}{x - \frac{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)\right)}{t}}\]
    3. Taylor expanded around 0 11.7

      \[\leadsto x - \frac{\color{blue}{\log 1.0 + \left(1.0 \cdot \left(z \cdot y\right) + 0.5 \cdot \left({z}^{2} \cdot y\right)\right)}}{t}\]
    4. Simplified11.7

      \[\leadsto x - \frac{\color{blue}{\mathsf{fma}\left(y, z \cdot \mathsf{fma}\left(z, 0.5, 1.0\right), \log 1.0\right)}}{t}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification7.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -1.200391987755555 \cdot 10^{-81}:\\ \;\;\;\;x - \frac{1}{t} \cdot \left(\log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right) + \log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right)\right)\\ \mathbf{elif}\;z \le 1.9712400723203086 \cdot 10^{-138}:\\ \;\;\;\;x - \mathsf{fma}\left(\frac{z}{t}, y \cdot 1.0, \mathsf{fma}\left(0.5, \frac{\left(z \cdot z\right) \cdot y}{t}, \frac{\log 1.0}{t}\right)\right)\\ \mathbf{elif}\;z \le 8.16242381116947 \cdot 10^{-121}:\\ \;\;\;\;x - \frac{1}{t} \cdot \left(\log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right) + \log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\mathsf{fma}\left(y, z \cdot \mathsf{fma}\left(z, 0.5, 1.0\right), \log 1.0\right)}{t}\\ \end{array}\]

Reproduce

herbie shell --seed 2019163 +o rules:numerics
(FPCore (x y z t)
  :name "System.Random.MWC.Distributions:truncatedExp from mwc-random-0.13.3.2"

  :herbie-target
  (if (< z -2.8874623088207947e+119) (- (- x (/ (/ (- 0.5) (* y t)) (* z z))) (* (/ (- 0.5) (* y t)) (/ (/ 2.0 z) (* z z)))) (- x (/ (log (+ 1.0 (* z y))) t)))

  (- x (/ (log (+ (- 1.0 y) (* y (exp z)))) t)))