Average Error: 24.7 → 8.6
Time: 23.7s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -1.483213486755813962924358643924524789497 \cdot 10^{-38}:\\ \;\;\;\;x - \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right) \cdot \frac{1}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{fma}\left(\frac{z \cdot y}{t}, 1, \mathsf{fma}\left(\frac{{z}^{2} \cdot y}{t}, 0.5, \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 -1.483213486755813962924358643924524789497 \cdot 10^{-38}:\\
\;\;\;\;x - \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right) \cdot \frac{1}{t}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r226445 = x;
        double r226446 = 1.0;
        double r226447 = y;
        double r226448 = r226446 - r226447;
        double r226449 = z;
        double r226450 = exp(r226449);
        double r226451 = r226447 * r226450;
        double r226452 = r226448 + r226451;
        double r226453 = log(r226452);
        double r226454 = t;
        double r226455 = r226453 / r226454;
        double r226456 = r226445 - r226455;
        return r226456;
}

double f(double x, double y, double z, double t) {
        double r226457 = z;
        double r226458 = -1.483213486755814e-38;
        bool r226459 = r226457 <= r226458;
        double r226460 = x;
        double r226461 = expm1(r226457);
        double r226462 = y;
        double r226463 = 1.0;
        double r226464 = fma(r226461, r226462, r226463);
        double r226465 = log(r226464);
        double r226466 = 1.0;
        double r226467 = t;
        double r226468 = r226466 / r226467;
        double r226469 = r226465 * r226468;
        double r226470 = r226460 - r226469;
        double r226471 = r226457 * r226462;
        double r226472 = r226471 / r226467;
        double r226473 = 2.0;
        double r226474 = pow(r226457, r226473);
        double r226475 = r226474 * r226462;
        double r226476 = r226475 / r226467;
        double r226477 = 0.5;
        double r226478 = log(r226463);
        double r226479 = r226478 / r226467;
        double r226480 = fma(r226476, r226477, r226479);
        double r226481 = fma(r226472, r226463, r226480);
        double r226482 = r226460 - r226481;
        double r226483 = r226459 ? r226470 : r226482;
        return r226483;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original24.7
Target16.3
Herbie8.6
\[\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 2 regimes
  2. if z < -1.483213486755814e-38

    1. Initial program 13.0

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

      \[\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 div-inv11.5

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

    if -1.483213486755814e-38 < z

    1. Initial program 30.5

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

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

      \[\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)}\]
    6. Simplified7.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -1.483213486755813962924358643924524789497 \cdot 10^{-38}:\\ \;\;\;\;x - \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right) \cdot \frac{1}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{fma}\left(\frac{z \cdot y}{t}, 1, \mathsf{fma}\left(\frac{{z}^{2} \cdot y}{t}, 0.5, \frac{\log 1}{t}\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019306 +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.88746230882079466e119) (- (- 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)))