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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r343572 = x;
        double r343573 = 1.0;
        double r343574 = y;
        double r343575 = r343573 - r343574;
        double r343576 = z;
        double r343577 = exp(r343576);
        double r343578 = r343574 * r343577;
        double r343579 = r343575 + r343578;
        double r343580 = log(r343579);
        double r343581 = t;
        double r343582 = r343580 / r343581;
        double r343583 = r343572 - r343582;
        return r343583;
}

double f(double x, double y, double z, double t) {
        double r343584 = z;
        double r343585 = -2.3067511430719193e-79;
        bool r343586 = r343584 <= r343585;
        double r343587 = x;
        double r343588 = 2.0;
        double r343589 = 0.3333333333333333;
        double r343590 = y;
        double r343591 = expm1(r343584);
        double r343592 = 1.0;
        double r343593 = fma(r343590, r343591, r343592);
        double r343594 = log(r343593);
        double r343595 = r343589 * r343594;
        double r343596 = r343588 * r343595;
        double r343597 = cbrt(r343593);
        double r343598 = log(r343597);
        double r343599 = r343588 * r343598;
        double r343600 = exp(r343599);
        double r343601 = cbrt(r343600);
        double r343602 = log(r343601);
        double r343603 = cbrt(r343597);
        double r343604 = log(r343603);
        double r343605 = r343602 + r343604;
        double r343606 = r343596 + r343605;
        double r343607 = 1.0;
        double r343608 = t;
        double r343609 = r343607 / r343608;
        double r343610 = r343606 * r343609;
        double r343611 = r343587 - r343610;
        double r343612 = 0.5;
        double r343613 = pow(r343584, r343588);
        double r343614 = r343613 * r343590;
        double r343615 = r343584 * r343590;
        double r343616 = log(r343592);
        double r343617 = fma(r343592, r343615, r343616);
        double r343618 = fma(r343612, r343614, r343617);
        double r343619 = r343618 / r343608;
        double r343620 = r343587 - r343619;
        double r343621 = r343586 ? r343611 : r343620;
        return r343621;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original24.7
Target16.3
Herbie8.5
\[\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 < -2.3067511430719193e-79

    1. Initial program 14.9

      \[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(y, \mathsf{expm1}\left(z\right), 1\right)\right)}{t}}\]
    3. Using strategy rm
    4. Applied div-inv11.6

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

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

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

      \[\leadsto x - \left(\color{blue}{2 \cdot \log \left(\sqrt[3]{\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)}\right)} + \log \left(\sqrt[3]{\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)}\right)\right) \cdot \frac{1}{t}\]
    9. Using strategy rm
    10. Applied pow1/311.6

      \[\leadsto x - \left(2 \cdot \log \color{blue}{\left({\left(\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)\right)}^{\frac{1}{3}}\right)} + \log \left(\sqrt[3]{\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)}\right)\right) \cdot \frac{1}{t}\]
    11. Applied log-pow11.6

      \[\leadsto x - \left(2 \cdot \color{blue}{\left(\frac{1}{3} \cdot \log \left(\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)\right)\right)} + \log \left(\sqrt[3]{\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)}\right)\right) \cdot \frac{1}{t}\]
    12. Using strategy rm
    13. Applied add-cube-cbrt11.6

      \[\leadsto x - \left(2 \cdot \left(\frac{1}{3} \cdot \log \left(\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)\right)\right) + \log \left(\sqrt[3]{\color{blue}{\left(\sqrt[3]{\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)} \cdot \sqrt[3]{\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)}}}\right)\right) \cdot \frac{1}{t}\]
    14. Applied cbrt-prod11.6

      \[\leadsto x - \left(2 \cdot \left(\frac{1}{3} \cdot \log \left(\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)\right)\right) + \log \color{blue}{\left(\sqrt[3]{\sqrt[3]{\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)} \cdot \sqrt[3]{\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)}} \cdot \sqrt[3]{\sqrt[3]{\mathsf{fma}\left(y, \mathsf{expm1}\left(z\right), 1\right)}}\right)}\right) \cdot \frac{1}{t}\]
    15. Applied log-prod11.6

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

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

    if -2.3067511430719193e-79 < z

    1. Initial program 30.9

      \[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(y, \mathsf{expm1}\left(z\right), 1\right)\right)}{t}}\]
    3. Taylor expanded around 0 6.5

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

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

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

Reproduce

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