Average Error: 24.9 → 8.7
Time: 9.9s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -7.43421758733702914 \cdot 10^{-102} \lor \neg \left(z \le 7.6182349927606628 \cdot 10^{-115}\right):\\ \;\;\;\;x - \frac{\sqrt[3]{{\left(\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)\right)}^{3}}}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \left(1 \cdot \frac{z \cdot y}{t} + \frac{\log 1}{t}\right)\\ \end{array}\]
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
\mathbf{if}\;z \le -7.43421758733702914 \cdot 10^{-102} \lor \neg \left(z \le 7.6182349927606628 \cdot 10^{-115}\right):\\
\;\;\;\;x - \frac{\sqrt[3]{{\left(\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)\right)}^{3}}}{t}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r365385 = x;
        double r365386 = 1.0;
        double r365387 = y;
        double r365388 = r365386 - r365387;
        double r365389 = z;
        double r365390 = exp(r365389);
        double r365391 = r365387 * r365390;
        double r365392 = r365388 + r365391;
        double r365393 = log(r365392);
        double r365394 = t;
        double r365395 = r365393 / r365394;
        double r365396 = r365385 - r365395;
        return r365396;
}

double f(double x, double y, double z, double t) {
        double r365397 = z;
        double r365398 = -7.434217587337029e-102;
        bool r365399 = r365397 <= r365398;
        double r365400 = 7.618234992760663e-115;
        bool r365401 = r365397 <= r365400;
        double r365402 = !r365401;
        bool r365403 = r365399 || r365402;
        double r365404 = x;
        double r365405 = expm1(r365397);
        double r365406 = y;
        double r365407 = 1.0;
        double r365408 = fma(r365405, r365406, r365407);
        double r365409 = log(r365408);
        double r365410 = 3.0;
        double r365411 = pow(r365409, r365410);
        double r365412 = cbrt(r365411);
        double r365413 = t;
        double r365414 = r365412 / r365413;
        double r365415 = r365404 - r365414;
        double r365416 = r365397 * r365406;
        double r365417 = r365416 / r365413;
        double r365418 = r365407 * r365417;
        double r365419 = log(r365407);
        double r365420 = r365419 / r365413;
        double r365421 = r365418 + r365420;
        double r365422 = r365404 - r365421;
        double r365423 = r365403 ? r365415 : r365422;
        return r365423;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original24.9
Target16.0
Herbie8.7
\[\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 < -7.434217587337029e-102 or 7.618234992760663e-115 < z

    1. Initial program 19.4

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

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

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

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

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

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

    if -7.434217587337029e-102 < z < 7.618234992760663e-115

    1. Initial program 31.2

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

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

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

      \[\leadsto x - \frac{\log \left(1 + \color{blue}{y \cdot \mathsf{expm1}\left(z\right)}\right)}{t}\]
    6. Taylor expanded around 0 5.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -7.43421758733702914 \cdot 10^{-102} \lor \neg \left(z \le 7.6182349927606628 \cdot 10^{-115}\right):\\ \;\;\;\;x - \frac{\sqrt[3]{{\left(\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)\right)}^{3}}}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \left(1 \cdot \frac{z \cdot y}{t} + \frac{\log 1}{t}\right)\\ \end{array}\]

Reproduce

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