Average Error: 24.9 → 8.7
Time: 21.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 -3.001899740921049 \cdot 10^{-81}:\\ \;\;\;\;x - \frac{\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)}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{fma}\left(\frac{y \cdot z}{t}, 1.0, \frac{\log 1.0}{t}\right)\\ \end{array}\]
x - \frac{\log \left(\left(1.0 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
\mathbf{if}\;z \le -3.001899740921049 \cdot 10^{-81}:\\
\;\;\;\;x - \frac{\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)}{t}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r5422396 = x;
        double r5422397 = 1.0;
        double r5422398 = y;
        double r5422399 = r5422397 - r5422398;
        double r5422400 = z;
        double r5422401 = exp(r5422400);
        double r5422402 = r5422398 * r5422401;
        double r5422403 = r5422399 + r5422402;
        double r5422404 = log(r5422403);
        double r5422405 = t;
        double r5422406 = r5422404 / r5422405;
        double r5422407 = r5422396 - r5422406;
        return r5422407;
}

double f(double x, double y, double z, double t) {
        double r5422408 = z;
        double r5422409 = -3.001899740921049e-81;
        bool r5422410 = r5422408 <= r5422409;
        double r5422411 = x;
        double r5422412 = expm1(r5422408);
        double r5422413 = y;
        double r5422414 = 1.0;
        double r5422415 = fma(r5422412, r5422413, r5422414);
        double r5422416 = cbrt(r5422415);
        double r5422417 = log(r5422416);
        double r5422418 = r5422416 * r5422416;
        double r5422419 = log(r5422418);
        double r5422420 = r5422417 + r5422419;
        double r5422421 = t;
        double r5422422 = r5422420 / r5422421;
        double r5422423 = r5422411 - r5422422;
        double r5422424 = r5422413 * r5422408;
        double r5422425 = r5422424 / r5422421;
        double r5422426 = log(r5422414);
        double r5422427 = r5422426 / r5422421;
        double r5422428 = fma(r5422425, r5422414, r5422427);
        double r5422429 = r5422411 - r5422428;
        double r5422430 = r5422410 ? r5422423 : r5422429;
        return r5422430;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original24.9
Target16.5
Herbie8.7
\[\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 2 regimes
  2. if z < -3.001899740921049e-81

    1. Initial program 15.5

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

      \[\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 add-cube-cbrt12.2

      \[\leadsto x - \frac{\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)}}{t}\]
    5. Applied log-prod12.2

      \[\leadsto x - \frac{\color{blue}{\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)}}{t}\]

    if -3.001899740921049e-81 < z

    1. Initial program 30.6

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

      \[\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 6.6

      \[\leadsto \color{blue}{x - \left(1.0 \cdot \frac{z \cdot y}{t} + \frac{\log 1.0}{t}\right)}\]
    4. Simplified6.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -3.001899740921049 \cdot 10^{-81}:\\ \;\;\;\;x - \frac{\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)}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{fma}\left(\frac{y \cdot z}{t}, 1.0, \frac{\log 1.0}{t}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019156 +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)))