Average Error: 25.1 → 9.4
Time: 7.8s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -3.7048441154199694 \cdot 10^{-33} \lor \neg \left(z \le 1.10443579609046836 \cdot 10^{-185}\right):\\ \;\;\;\;x - \frac{\log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;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)\\ \end{array}\]
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
\mathbf{if}\;z \le -3.7048441154199694 \cdot 10^{-33} \lor \neg \left(z \le 1.10443579609046836 \cdot 10^{-185}\right):\\
\;\;\;\;x - \frac{\log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right)}{t}\\

\mathbf{else}:\\
\;\;\;\;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)\\

\end{array}
double f(double x, double y, double z, double t) {
        double r322451 = x;
        double r322452 = 1.0;
        double r322453 = y;
        double r322454 = r322452 - r322453;
        double r322455 = z;
        double r322456 = exp(r322455);
        double r322457 = r322453 * r322456;
        double r322458 = r322454 + r322457;
        double r322459 = log(r322458);
        double r322460 = t;
        double r322461 = r322459 / r322460;
        double r322462 = r322451 - r322461;
        return r322462;
}

double f(double x, double y, double z, double t) {
        double r322463 = z;
        double r322464 = -3.7048441154199694e-33;
        bool r322465 = r322463 <= r322464;
        double r322466 = 1.1044357960904684e-185;
        bool r322467 = r322463 <= r322466;
        double r322468 = !r322467;
        bool r322469 = r322465 || r322468;
        double r322470 = x;
        double r322471 = 1.0;
        double r322472 = y;
        double r322473 = expm1(r322463);
        double r322474 = r322472 * r322473;
        double r322475 = r322471 + r322474;
        double r322476 = log(r322475);
        double r322477 = t;
        double r322478 = r322476 / r322477;
        double r322479 = r322470 - r322478;
        double r322480 = r322463 * r322472;
        double r322481 = r322480 / r322477;
        double r322482 = 0.5;
        double r322483 = 2.0;
        double r322484 = pow(r322463, r322483);
        double r322485 = r322484 * r322472;
        double r322486 = r322485 / r322477;
        double r322487 = log(r322471);
        double r322488 = r322487 / r322477;
        double r322489 = fma(r322482, r322486, r322488);
        double r322490 = fma(r322481, r322471, r322489);
        double r322491 = r322470 - r322490;
        double r322492 = r322469 ? r322479 : r322491;
        return r322492;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.1
Target16.8
Herbie9.4
\[\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.7048441154199694e-33 or 1.1044357960904684e-185 < z

    1. Initial program 19.9

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

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

      \[\leadsto x - \frac{\log \left(\left(1 - y\right) + \color{blue}{\left(\sqrt[3]{y} \cdot \sqrt[3]{y}\right) \cdot \left(\sqrt[3]{y} \cdot e^{z}\right)}\right)}{t}\]
    5. Using strategy rm
    6. Applied sub-neg18.1

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

      \[\leadsto x - \frac{\log \color{blue}{\left(1 + \left(\left(-y\right) + \left(\sqrt[3]{y} \cdot \sqrt[3]{y}\right) \cdot \left(\sqrt[3]{y} \cdot e^{z}\right)\right)\right)}}{t}\]
    8. Simplified12.6

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

    if -3.7048441154199694e-33 < z < 1.1044357960904684e-185

    1. Initial program 31.1

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

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

      \[\leadsto x - \frac{\log \left(\left(1 - y\right) + \color{blue}{\left(\sqrt[3]{y} \cdot \sqrt[3]{y}\right) \cdot \left(\sqrt[3]{y} \cdot e^{z}\right)}\right)}{t}\]
    5. Using strategy rm
    6. Applied sub-neg26.2

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

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

      \[\leadsto x - \frac{\log \left(1 + \color{blue}{y \cdot \mathsf{expm1}\left(z\right)}\right)}{t}\]
    9. Taylor expanded around 0 5.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)}\]
    10. Simplified5.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)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification9.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -3.7048441154199694 \cdot 10^{-33} \lor \neg \left(z \le 1.10443579609046836 \cdot 10^{-185}\right):\\ \;\;\;\;x - \frac{\log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;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)\\ \end{array}\]

Reproduce

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