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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r14751995 = x;
        double r14751996 = 1.0;
        double r14751997 = y;
        double r14751998 = r14751996 - r14751997;
        double r14751999 = z;
        double r14752000 = exp(r14751999);
        double r14752001 = r14751997 * r14752000;
        double r14752002 = r14751998 + r14752001;
        double r14752003 = log(r14752002);
        double r14752004 = t;
        double r14752005 = r14752003 / r14752004;
        double r14752006 = r14751995 - r14752005;
        return r14752006;
}

double f(double x, double y, double z, double t) {
        double r14752007 = z;
        double r14752008 = -5.561499858875619e-112;
        bool r14752009 = r14752007 <= r14752008;
        double r14752010 = x;
        double r14752011 = expm1(r14752007);
        double r14752012 = y;
        double r14752013 = 1.0;
        double r14752014 = fma(r14752011, r14752012, r14752013);
        double r14752015 = sqrt(r14752014);
        double r14752016 = log(r14752015);
        double r14752017 = cbrt(r14752014);
        double r14752018 = sqrt(r14752017);
        double r14752019 = r14752017 * r14752017;
        double r14752020 = sqrt(r14752019);
        double r14752021 = r14752018 * r14752020;
        double r14752022 = log(r14752021);
        double r14752023 = r14752016 + r14752022;
        double r14752024 = t;
        double r14752025 = r14752023 / r14752024;
        double r14752026 = r14752010 - r14752025;
        double r14752027 = r14752007 * r14752007;
        double r14752028 = r14752027 / r14752024;
        double r14752029 = 0.5;
        double r14752030 = r14752012 / r14752013;
        double r14752031 = r14752029 * r14752030;
        double r14752032 = r14752007 / r14752024;
        double r14752033 = sqrt(r14752013);
        double r14752034 = log(r14752033);
        double r14752035 = 2.0;
        double r14752036 = r14752034 * r14752035;
        double r14752037 = r14752036 / r14752024;
        double r14752038 = fma(r14752032, r14752030, r14752037);
        double r14752039 = fma(r14752028, r14752031, r14752038);
        double r14752040 = r14752010 - r14752039;
        double r14752041 = r14752009 ? r14752026 : r14752040;
        return r14752041;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.0
Target16.4
Herbie7.8
\[\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 < -5.561499858875619e-112

    1. Initial program 16.3

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

      \[\leadsto x - \frac{\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)}}{t}\]
    5. Applied log-prod11.1

      \[\leadsto x - \frac{\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)}}{t}\]
    6. Using strategy rm
    7. Applied add-cube-cbrt11.1

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

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

    if -5.561499858875619e-112 < z

    1. Initial program 31.1

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

      \[\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-sqr-sqrt11.8

      \[\leadsto x - \frac{\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)}}{t}\]
    5. Applied log-prod11.8

      \[\leadsto x - \frac{\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)}}{t}\]
    6. Taylor expanded around 0 6.6

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

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

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

Reproduce

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