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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r185750 = x;
        double r185751 = 1.0;
        double r185752 = y;
        double r185753 = r185751 - r185752;
        double r185754 = z;
        double r185755 = exp(r185754);
        double r185756 = r185752 * r185755;
        double r185757 = r185753 + r185756;
        double r185758 = log(r185757);
        double r185759 = t;
        double r185760 = r185758 / r185759;
        double r185761 = r185750 - r185760;
        return r185761;
}

double f(double x, double y, double z, double t) {
        double r185762 = z;
        double r185763 = -1.1486240881917044e-69;
        bool r185764 = r185762 <= r185763;
        double r185765 = x;
        double r185766 = expm1(r185762);
        double r185767 = y;
        double r185768 = 1.0;
        double r185769 = fma(r185766, r185767, r185768);
        double r185770 = sqrt(r185769);
        double r185771 = log(r185770);
        double r185772 = r185771 + r185771;
        double r185773 = cbrt(r185772);
        double r185774 = log(r185769);
        double r185775 = cbrt(r185774);
        double r185776 = r185773 * r185775;
        double r185777 = log1p(r185775);
        double r185778 = expm1(r185777);
        double r185779 = r185776 * r185778;
        double r185780 = t;
        double r185781 = r185779 / r185780;
        double r185782 = r185765 - r185781;
        double r185783 = 2.0;
        double r185784 = pow(r185762, r185783);
        double r185785 = 0.5;
        double r185786 = r185768 * r185762;
        double r185787 = fma(r185784, r185785, r185786);
        double r185788 = log(r185768);
        double r185789 = fma(r185767, r185787, r185788);
        double r185790 = r185789 / r185780;
        double r185791 = r185765 - r185790;
        double r185792 = r185764 ? r185782 : r185791;
        return r185792;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.2
Target16.4
Herbie8.9
\[\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.1486240881917044e-69

    1. Initial program 15.2

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Simplified12.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 add-cube-cbrt12.5

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

      \[\leadsto x - \frac{\left(\sqrt[3]{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)} \cdot \sqrt[3]{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}\right) \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt[3]{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}\right)\right)}}{t}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt12.5

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

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

    if -1.1486240881917044e-69 < z

    1. Initial program 31.0

      \[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. Taylor expanded around 0 6.9

      \[\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.9

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

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

Reproduce

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