Average Error: 25.1 → 8.0
Time: 40.7s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -3.887828973606995727415374643534540792962 \cdot 10^{-55}:\\ \;\;\;\;x - \frac{\sqrt[3]{\left(\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right) \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)\right) \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}}{t}\\ \mathbf{elif}\;z \le 2.844709799284159283840952968270939896437 \cdot 10^{-88}:\\ \;\;\;\;x - \mathsf{fma}\left(y \cdot \frac{z}{t}, 1, \mathsf{fma}\left(\frac{z \cdot \left(y \cdot z\right)}{t}, 0.5, \frac{\log 1}{t}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\sqrt[3]{\left(\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right) \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)\right) \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\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.887828973606995727415374643534540792962 \cdot 10^{-55}:\\
\;\;\;\;x - \frac{\sqrt[3]{\left(\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right) \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)\right) \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}}{t}\\

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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r14774566 = x;
        double r14774567 = 1.0;
        double r14774568 = y;
        double r14774569 = r14774567 - r14774568;
        double r14774570 = z;
        double r14774571 = exp(r14774570);
        double r14774572 = r14774568 * r14774571;
        double r14774573 = r14774569 + r14774572;
        double r14774574 = log(r14774573);
        double r14774575 = t;
        double r14774576 = r14774574 / r14774575;
        double r14774577 = r14774566 - r14774576;
        return r14774577;
}

double f(double x, double y, double z, double t) {
        double r14774578 = z;
        double r14774579 = -3.887828973606996e-55;
        bool r14774580 = r14774578 <= r14774579;
        double r14774581 = x;
        double r14774582 = expm1(r14774578);
        double r14774583 = y;
        double r14774584 = 1.0;
        double r14774585 = fma(r14774582, r14774583, r14774584);
        double r14774586 = log(r14774585);
        double r14774587 = r14774586 * r14774586;
        double r14774588 = r14774587 * r14774586;
        double r14774589 = cbrt(r14774588);
        double r14774590 = t;
        double r14774591 = r14774589 / r14774590;
        double r14774592 = r14774581 - r14774591;
        double r14774593 = 2.8447097992841593e-88;
        bool r14774594 = r14774578 <= r14774593;
        double r14774595 = r14774578 / r14774590;
        double r14774596 = r14774583 * r14774595;
        double r14774597 = r14774583 * r14774578;
        double r14774598 = r14774578 * r14774597;
        double r14774599 = r14774598 / r14774590;
        double r14774600 = 0.5;
        double r14774601 = log(r14774584);
        double r14774602 = r14774601 / r14774590;
        double r14774603 = fma(r14774599, r14774600, r14774602);
        double r14774604 = fma(r14774596, r14774584, r14774603);
        double r14774605 = r14774581 - r14774604;
        double r14774606 = r14774594 ? r14774605 : r14774592;
        double r14774607 = r14774580 ? r14774592 : r14774606;
        return r14774607;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.1
Target16.4
Herbie8.0
\[\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 < -3.887828973606996e-55 or 2.8447097992841593e-88 < z

    1. Initial program 17.5

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

      \[\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 add-cbrt-cube12.2

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

    if -3.887828973606996e-55 < z < 2.8447097992841593e-88

    1. Initial program 31.4

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

      \[\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 *-un-lft-identity11.0

      \[\leadsto x - \frac{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}{\color{blue}{1 \cdot t}}\]
    5. Applied add-sqr-sqrt11.7

      \[\leadsto x - \frac{\color{blue}{\sqrt{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)} \cdot \sqrt{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}}}{1 \cdot t}\]
    6. Applied times-frac11.7

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -3.887828973606995727415374643534540792962 \cdot 10^{-55}:\\ \;\;\;\;x - \frac{\sqrt[3]{\left(\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right) \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)\right) \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}}{t}\\ \mathbf{elif}\;z \le 2.844709799284159283840952968270939896437 \cdot 10^{-88}:\\ \;\;\;\;x - \mathsf{fma}\left(y \cdot \frac{z}{t}, 1, \mathsf{fma}\left(\frac{z \cdot \left(y \cdot z\right)}{t}, 0.5, \frac{\log 1}{t}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\sqrt[3]{\left(\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right) \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)\right) \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}}{t}\\ \end{array}\]

Reproduce

herbie shell --seed 2019169 +o rules:numerics
(FPCore (x y z t)
  :name "System.Random.MWC.Distributions:truncatedExp from mwc-random-0.13.3.2"

  :herbie-target
  (if (< z -2.8874623088207947e+119) (- (- x (/ (/ (- 0.5) (* y t)) (* z z))) (* (/ (- 0.5) (* y t)) (/ (/ 2.0 z) (* z z)))) (- x (/ (log (+ 1.0 (* z y))) t)))

  (- x (/ (log (+ (- 1.0 y) (* y (exp z)))) t)))