Average Error: 25.3 → 11.1
Time: 14.7s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;y \le -1.445356193171678517860867392617449029982 \cdot 10^{74}:\\ \;\;\;\;x - \frac{\frac{1}{t}}{\frac{1}{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}}\\ \mathbf{elif}\;y \le 2.41694478692490587181194748533869565474 \cdot 10^{225}:\\ \;\;\;\;x - \mathsf{fma}\left(1, \frac{z \cdot y}{t}, \frac{\log 1}{t}\right)\\ \mathbf{else}:\\ \;\;\;\;x - \frac{1}{\frac{t}{2 \cdot \log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right) + \left(\sqrt[3]{\log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right)} \cdot \sqrt[3]{\log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right)}\right) \cdot \sqrt[3]{\log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right)}}}\\ \end{array}\]
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
\mathbf{if}\;y \le -1.445356193171678517860867392617449029982 \cdot 10^{74}:\\
\;\;\;\;x - \frac{\frac{1}{t}}{\frac{1}{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}}\\

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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r325384 = x;
        double r325385 = 1.0;
        double r325386 = y;
        double r325387 = r325385 - r325386;
        double r325388 = z;
        double r325389 = exp(r325388);
        double r325390 = r325386 * r325389;
        double r325391 = r325387 + r325390;
        double r325392 = log(r325391);
        double r325393 = t;
        double r325394 = r325392 / r325393;
        double r325395 = r325384 - r325394;
        return r325395;
}

double f(double x, double y, double z, double t) {
        double r325396 = y;
        double r325397 = -1.4453561931716785e+74;
        bool r325398 = r325396 <= r325397;
        double r325399 = x;
        double r325400 = 1.0;
        double r325401 = t;
        double r325402 = r325400 / r325401;
        double r325403 = z;
        double r325404 = expm1(r325403);
        double r325405 = 1.0;
        double r325406 = fma(r325404, r325396, r325405);
        double r325407 = log(r325406);
        double r325408 = r325400 / r325407;
        double r325409 = r325402 / r325408;
        double r325410 = r325399 - r325409;
        double r325411 = 2.416944786924906e+225;
        bool r325412 = r325396 <= r325411;
        double r325413 = r325403 * r325396;
        double r325414 = r325413 / r325401;
        double r325415 = log(r325405);
        double r325416 = r325415 / r325401;
        double r325417 = fma(r325405, r325414, r325416);
        double r325418 = r325399 - r325417;
        double r325419 = 2.0;
        double r325420 = cbrt(r325406);
        double r325421 = log(r325420);
        double r325422 = r325419 * r325421;
        double r325423 = cbrt(r325421);
        double r325424 = r325423 * r325423;
        double r325425 = r325424 * r325423;
        double r325426 = r325422 + r325425;
        double r325427 = r325401 / r325426;
        double r325428 = r325400 / r325427;
        double r325429 = r325399 - r325428;
        double r325430 = r325412 ? r325418 : r325429;
        double r325431 = r325398 ? r325410 : r325430;
        return r325431;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.3
Target16.7
Herbie11.1
\[\begin{array}{l} \mathbf{if}\;z \lt -2.887462308820794658905265984545350618896 \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 y < -1.4453561931716785e+74

    1. Initial program 34.9

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

      \[\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 clear-num7.3

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

      \[\leadsto x - \frac{1}{\color{blue}{t \cdot \frac{1}{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}}}\]
    7. Applied associate-/r*7.3

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

    if -1.4453561931716785e+74 < y < 2.416944786924906e+225

    1. Initial program 21.7

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

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

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

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

    if 2.416944786924906e+225 < y

    1. Initial program 61.8

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Simplified7.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 clear-num7.4

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

      \[\leadsto x - \frac{1}{\frac{t}{\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)}}}\]
    7. Applied log-prod7.6

      \[\leadsto x - \frac{1}{\frac{t}{\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)}}}\]
    8. Simplified7.6

      \[\leadsto x - \frac{1}{\frac{t}{\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)}}\]
    9. Using strategy rm
    10. Applied add-cube-cbrt7.7

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

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

Reproduce

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