Average Error: 24.9 → 8.5
Time: 33.5s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -3.93535345747879 \cdot 10^{-11}:\\ \;\;\;\;x - \frac{2 \cdot \left(\frac{1}{3} \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)\right) + \left(\left(\log \left(\sqrt[3]{\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}}\right) + \log \left(\sqrt[3]{\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}}\right)\right) + \log \left(\sqrt[3]{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\mathsf{fma}\left(y, z \cdot \left(0.5 \cdot z + 1\right), \log 1\right)}{t}\\ \end{array}\]
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
\mathbf{if}\;z \le -3.93535345747879 \cdot 10^{-11}:\\
\;\;\;\;x - \frac{2 \cdot \left(\frac{1}{3} \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)\right) + \left(\left(\log \left(\sqrt[3]{\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}}\right) + \log \left(\sqrt[3]{\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}}\right)\right) + \log \left(\sqrt[3]{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)\right)}{t}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r293488 = x;
        double r293489 = 1.0;
        double r293490 = y;
        double r293491 = r293489 - r293490;
        double r293492 = z;
        double r293493 = exp(r293492);
        double r293494 = r293490 * r293493;
        double r293495 = r293491 + r293494;
        double r293496 = log(r293495);
        double r293497 = t;
        double r293498 = r293496 / r293497;
        double r293499 = r293488 - r293498;
        return r293499;
}

double f(double x, double y, double z, double t) {
        double r293500 = z;
        double r293501 = -3.93535345747879e-11;
        bool r293502 = r293500 <= r293501;
        double r293503 = x;
        double r293504 = 2.0;
        double r293505 = 0.3333333333333333;
        double r293506 = expm1(r293500);
        double r293507 = y;
        double r293508 = 1.0;
        double r293509 = fma(r293506, r293507, r293508);
        double r293510 = log(r293509);
        double r293511 = r293505 * r293510;
        double r293512 = r293504 * r293511;
        double r293513 = sqrt(r293509);
        double r293514 = sqrt(r293513);
        double r293515 = cbrt(r293514);
        double r293516 = log(r293515);
        double r293517 = r293516 + r293516;
        double r293518 = cbrt(r293513);
        double r293519 = log(r293518);
        double r293520 = r293517 + r293519;
        double r293521 = r293512 + r293520;
        double r293522 = t;
        double r293523 = r293521 / r293522;
        double r293524 = r293503 - r293523;
        double r293525 = 0.5;
        double r293526 = r293525 * r293500;
        double r293527 = r293526 + r293508;
        double r293528 = r293500 * r293527;
        double r293529 = log(r293508);
        double r293530 = fma(r293507, r293528, r293529);
        double r293531 = r293530 / r293522;
        double r293532 = r293503 - r293531;
        double r293533 = r293502 ? r293524 : r293532;
        return r293533;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original24.9
Target16.2
Herbie8.5
\[\begin{array}{l} \mathbf{if}\;z \lt -2.88746230882079466 \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}{z}}{z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\log \left(1 + z \cdot y\right)}{t}\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if z < -3.93535345747879e-11

    1. Initial program 11.5

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Simplified11.4

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

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

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

      \[\leadsto x - \frac{\color{blue}{2 \cdot \log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right)} + \log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right)}{t}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt11.5

      \[\leadsto x - \frac{2 \cdot \log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right) + \log \left(\sqrt[3]{\color{blue}{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)} \cdot \sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}}\right)}{t}\]
    9. Applied cbrt-prod11.5

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

      \[\leadsto x - \frac{2 \cdot \log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right) + \color{blue}{\left(\log \left(\sqrt[3]{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right) + \log \left(\sqrt[3]{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)\right)}}{t}\]
    11. Using strategy rm
    12. Applied pow1/311.5

      \[\leadsto x - \frac{2 \cdot \log \color{blue}{\left({\left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}^{\frac{1}{3}}\right)} + \left(\log \left(\sqrt[3]{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right) + \log \left(\sqrt[3]{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)\right)}{t}\]
    13. Applied log-pow11.5

      \[\leadsto x - \frac{2 \cdot \color{blue}{\left(\frac{1}{3} \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)\right)} + \left(\log \left(\sqrt[3]{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right) + \log \left(\sqrt[3]{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)\right)}{t}\]
    14. Using strategy rm
    15. Applied add-sqr-sqrt11.5

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

      \[\leadsto x - \frac{2 \cdot \left(\frac{1}{3} \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)\right) + \left(\log \left(\sqrt[3]{\color{blue}{\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}}}\right) + \log \left(\sqrt[3]{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)\right)}{t}\]
    17. Applied cbrt-prod11.5

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

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

    if -3.93535345747879e-11 < z

    1. Initial program 30.9

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Simplified11.5

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -3.93535345747879 \cdot 10^{-11}:\\ \;\;\;\;x - \frac{2 \cdot \left(\frac{1}{3} \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)\right) + \left(\left(\log \left(\sqrt[3]{\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}}\right) + \log \left(\sqrt[3]{\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}}\right)\right) + \log \left(\sqrt[3]{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\mathsf{fma}\left(y, z \cdot \left(0.5 \cdot z + 1\right), \log 1\right)}{t}\\ \end{array}\]

Reproduce

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

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

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