Average Error: 23.9 → 5.8
Time: 7.2s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -3.1198126899025023 \cdot 10^{-4}:\\ \;\;\;\;x - \frac{\log \left(1 + \mathsf{expm1}\left(\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)\right)\right)}{t}\\ \mathbf{elif}\;z \le 1.8293353697925934 \cdot 10^{-33}:\\ \;\;\;\;x - \mathsf{fma}\left(\frac{z \cdot y}{t}, 1, \mathsf{fma}\left(0.5, \frac{{z}^{2} \cdot y}{t}, \frac{\log 1}{t}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x - \frac{2 \cdot \log \left(\sqrt[3]{1 + y \cdot \mathsf{expm1}\left(z\right)}\right) + \log \left(\sqrt[3]{1 + y \cdot \mathsf{expm1}\left(z\right)}\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.1198126899025023 \cdot 10^{-4}:\\
\;\;\;\;x - \frac{\log \left(1 + \mathsf{expm1}\left(\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)\right)\right)}{t}\\

\mathbf{elif}\;z \le 1.8293353697925934 \cdot 10^{-33}:\\
\;\;\;\;x - \mathsf{fma}\left(\frac{z \cdot y}{t}, 1, \mathsf{fma}\left(0.5, \frac{{z}^{2} \cdot y}{t}, \frac{\log 1}{t}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;x - \frac{2 \cdot \log \left(\sqrt[3]{1 + y \cdot \mathsf{expm1}\left(z\right)}\right) + \log \left(\sqrt[3]{1 + y \cdot \mathsf{expm1}\left(z\right)}\right)}{t}\\

\end{array}
double f(double x, double y, double z, double t) {
        double r376425 = x;
        double r376426 = 1.0;
        double r376427 = y;
        double r376428 = r376426 - r376427;
        double r376429 = z;
        double r376430 = exp(r376429);
        double r376431 = r376427 * r376430;
        double r376432 = r376428 + r376431;
        double r376433 = log(r376432);
        double r376434 = t;
        double r376435 = r376433 / r376434;
        double r376436 = r376425 - r376435;
        return r376436;
}

double f(double x, double y, double z, double t) {
        double r376437 = z;
        double r376438 = -0.00031198126899025023;
        bool r376439 = r376437 <= r376438;
        double r376440 = x;
        double r376441 = 1.0;
        double r376442 = y;
        double r376443 = expm1(r376437);
        double r376444 = r376442 * r376443;
        double r376445 = log1p(r376444);
        double r376446 = expm1(r376445);
        double r376447 = r376441 + r376446;
        double r376448 = log(r376447);
        double r376449 = t;
        double r376450 = r376448 / r376449;
        double r376451 = r376440 - r376450;
        double r376452 = 1.8293353697925934e-33;
        bool r376453 = r376437 <= r376452;
        double r376454 = r376437 * r376442;
        double r376455 = r376454 / r376449;
        double r376456 = 0.5;
        double r376457 = 2.0;
        double r376458 = pow(r376437, r376457);
        double r376459 = r376458 * r376442;
        double r376460 = r376459 / r376449;
        double r376461 = log(r376441);
        double r376462 = r376461 / r376449;
        double r376463 = fma(r376456, r376460, r376462);
        double r376464 = fma(r376455, r376441, r376463);
        double r376465 = r376440 - r376464;
        double r376466 = r376441 + r376444;
        double r376467 = cbrt(r376466);
        double r376468 = log(r376467);
        double r376469 = r376457 * r376468;
        double r376470 = r376469 + r376468;
        double r376471 = r376470 / r376449;
        double r376472 = r376440 - r376471;
        double r376473 = r376453 ? r376465 : r376472;
        double r376474 = r376439 ? r376451 : r376473;
        return r376474;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original23.9
Target13.1
Herbie5.8
\[\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 3 regimes
  2. if z < -0.00031198126899025023

    1. Initial program 0.9

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Using strategy rm
    3. Applied sub-neg0.9

      \[\leadsto x - \frac{\log \left(\color{blue}{\left(1 + \left(-y\right)\right)} + y \cdot e^{z}\right)}{t}\]
    4. Applied associate-+l+0.9

      \[\leadsto x - \frac{\log \color{blue}{\left(1 + \left(\left(-y\right) + y \cdot e^{z}\right)\right)}}{t}\]
    5. Simplified0.9

      \[\leadsto x - \frac{\log \left(1 + \color{blue}{y \cdot \mathsf{expm1}\left(z\right)}\right)}{t}\]
    6. Using strategy rm
    7. Applied expm1-log1p-u0.9

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

    if -0.00031198126899025023 < z < 1.8293353697925934e-33

    1. Initial program 31.1

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Taylor expanded around 0 6.8

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

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

    if 1.8293353697925934e-33 < z

    1. Initial program 27.1

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Using strategy rm
    3. Applied sub-neg27.1

      \[\leadsto x - \frac{\log \left(\color{blue}{\left(1 + \left(-y\right)\right)} + y \cdot e^{z}\right)}{t}\]
    4. Applied associate-+l+21.7

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

      \[\leadsto x - \frac{\log \left(1 + \color{blue}{y \cdot \mathsf{expm1}\left(z\right)}\right)}{t}\]
    6. Using strategy rm
    7. Applied add-cube-cbrt16.3

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

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

      \[\leadsto x - \frac{\color{blue}{2 \cdot \log \left(\sqrt[3]{1 + y \cdot \mathsf{expm1}\left(z\right)}\right)} + \log \left(\sqrt[3]{1 + y \cdot \mathsf{expm1}\left(z\right)}\right)}{t}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification5.8

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

Reproduce

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