Average Error: 24.9 → 8.6
Time: 7.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.1255354070387358 \cdot 10^{-69}:\\ \;\;\;\;x - \frac{\sqrt[3]{{\left(\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)\right)}^{3}}}{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.1255354070387358 \cdot 10^{-69}:\\
\;\;\;\;x - \frac{\sqrt[3]{{\left(\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)\right)}^{3}}}{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 r243694 = x;
        double r243695 = 1.0;
        double r243696 = y;
        double r243697 = r243695 - r243696;
        double r243698 = z;
        double r243699 = exp(r243698);
        double r243700 = r243696 * r243699;
        double r243701 = r243697 + r243700;
        double r243702 = log(r243701);
        double r243703 = t;
        double r243704 = r243702 / r243703;
        double r243705 = r243694 - r243704;
        return r243705;
}

double f(double x, double y, double z, double t) {
        double r243706 = z;
        double r243707 = -2.1255354070387358e-69;
        bool r243708 = r243706 <= r243707;
        double r243709 = x;
        double r243710 = expm1(r243706);
        double r243711 = y;
        double r243712 = 1.0;
        double r243713 = fma(r243710, r243711, r243712);
        double r243714 = log(r243713);
        double r243715 = 3.0;
        double r243716 = pow(r243714, r243715);
        double r243717 = cbrt(r243716);
        double r243718 = t;
        double r243719 = r243717 / r243718;
        double r243720 = r243709 - r243719;
        double r243721 = 0.5;
        double r243722 = 2.0;
        double r243723 = pow(r243706, r243722);
        double r243724 = r243723 * r243711;
        double r243725 = r243706 * r243711;
        double r243726 = log(r243712);
        double r243727 = fma(r243712, r243725, r243726);
        double r243728 = fma(r243721, r243724, r243727);
        double r243729 = r243728 / r243718;
        double r243730 = r243709 - r243729;
        double r243731 = r243708 ? r243720 : r243730;
        return r243731;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original24.9
Target16.0
Herbie8.6
\[\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.1255354070387358e-69

    1. Initial program 14.9

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Using strategy rm
    3. Applied sub-neg14.9

      \[\leadsto x - \frac{\log \left(\color{blue}{\left(1 + \left(-y\right)\right)} + y \cdot e^{z}\right)}{t}\]
    4. Applied associate-+l+13.3

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

      \[\leadsto x - \frac{\log \left(1 + \color{blue}{y \cdot \mathsf{expm1}\left(z\right)}\right)}{t}\]
    6. Using strategy rm
    7. Applied add-cbrt-cube11.9

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

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

    if -2.1255354070387358e-69 < z

    1. Initial program 30.7

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Using strategy rm
    3. Applied sub-neg30.7

      \[\leadsto x - \frac{\log \left(\color{blue}{\left(1 + \left(-y\right)\right)} + y \cdot e^{z}\right)}{t}\]
    4. Applied associate-+l+15.0

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

      \[\leadsto x - \frac{\log \left(1 + \color{blue}{y \cdot \mathsf{expm1}\left(z\right)}\right)}{t}\]
    6. Using strategy rm
    7. Applied add-cbrt-cube10.9

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

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

      \[\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}\]
    10. Simplified6.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -2.1255354070387358 \cdot 10^{-69}:\\ \;\;\;\;x - \frac{\sqrt[3]{{\left(\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)\right)}^{3}}}{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 2020039 +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)))