Average Error: 24.4 → 8.4
Time: 43.0s
Precision: 64
\[x - \frac{\log \left(\left(1.0 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -1.7774096754001219 \cdot 10^{-84}:\\ \;\;\;\;x - \frac{\sqrt[3]{\log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right) + \log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right)} \cdot \sqrt[3]{\log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right) + \log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right)}}{\frac{t}{\sqrt[3]{\log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right) + \log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right)}}}\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{fma}\left(\frac{\log \left(\sqrt{1.0}\right)}{t}, 2, \mathsf{fma}\left(\frac{z}{t}, \frac{y}{1.0}, \left(\frac{z \cdot z}{t} \cdot \frac{1}{2}\right) \cdot \frac{y}{1.0}\right)\right)\\ \end{array}\]
x - \frac{\log \left(\left(1.0 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
\mathbf{if}\;z \le -1.7774096754001219 \cdot 10^{-84}:\\
\;\;\;\;x - \frac{\sqrt[3]{\log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right) + \log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right)} \cdot \sqrt[3]{\log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right) + \log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right)}}{\frac{t}{\sqrt[3]{\log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right) + \log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right)}}}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r11736205 = x;
        double r11736206 = 1.0;
        double r11736207 = y;
        double r11736208 = r11736206 - r11736207;
        double r11736209 = z;
        double r11736210 = exp(r11736209);
        double r11736211 = r11736207 * r11736210;
        double r11736212 = r11736208 + r11736211;
        double r11736213 = log(r11736212);
        double r11736214 = t;
        double r11736215 = r11736213 / r11736214;
        double r11736216 = r11736205 - r11736215;
        return r11736216;
}

double f(double x, double y, double z, double t) {
        double r11736217 = z;
        double r11736218 = -1.7774096754001219e-84;
        bool r11736219 = r11736217 <= r11736218;
        double r11736220 = x;
        double r11736221 = expm1(r11736217);
        double r11736222 = y;
        double r11736223 = 1.0;
        double r11736224 = fma(r11736221, r11736222, r11736223);
        double r11736225 = sqrt(r11736224);
        double r11736226 = log(r11736225);
        double r11736227 = r11736226 + r11736226;
        double r11736228 = cbrt(r11736227);
        double r11736229 = r11736228 * r11736228;
        double r11736230 = t;
        double r11736231 = r11736230 / r11736228;
        double r11736232 = r11736229 / r11736231;
        double r11736233 = r11736220 - r11736232;
        double r11736234 = sqrt(r11736223);
        double r11736235 = log(r11736234);
        double r11736236 = r11736235 / r11736230;
        double r11736237 = 2.0;
        double r11736238 = r11736217 / r11736230;
        double r11736239 = r11736222 / r11736223;
        double r11736240 = r11736217 * r11736217;
        double r11736241 = r11736240 / r11736230;
        double r11736242 = 0.5;
        double r11736243 = r11736241 * r11736242;
        double r11736244 = r11736243 * r11736239;
        double r11736245 = fma(r11736238, r11736239, r11736244);
        double r11736246 = fma(r11736236, r11736237, r11736245);
        double r11736247 = r11736220 - r11736246;
        double r11736248 = r11736219 ? r11736233 : r11736247;
        return r11736248;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original24.4
Target16.6
Herbie8.4
\[\begin{array}{l} \mathbf{if}\;z \lt -2.8874623088207947 \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.0}{z}}{z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\log \left(1.0 + z \cdot y\right)}{t}\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if z < -1.7774096754001219e-84

    1. Initial program 15.2

      \[x - \frac{\log \left(\left(1.0 - 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.0\right)\right)}{t}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt12.1

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

      \[\leadsto x - \frac{\color{blue}{\log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right) + \log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right)}}{t}\]
    6. Using strategy rm
    7. Applied add-cube-cbrt12.3

      \[\leadsto x - \frac{\color{blue}{\left(\sqrt[3]{\log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right) + \log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right)} \cdot \sqrt[3]{\log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right) + \log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right)}\right) \cdot \sqrt[3]{\log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right) + \log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right)}}}{t}\]
    8. Applied associate-/l*12.3

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

    if -1.7774096754001219e-84 < z

    1. Initial program 30.3

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

      \[\leadsto \color{blue}{x - \frac{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)\right)}{t}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt11.7

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

      \[\leadsto x - \frac{\color{blue}{\log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right) + \log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right)}}{t}\]
    6. Taylor expanded around 0 7.0

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

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

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

Reproduce

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