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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r14030869 = x;
        double r14030870 = 1.0;
        double r14030871 = y;
        double r14030872 = r14030870 - r14030871;
        double r14030873 = z;
        double r14030874 = exp(r14030873);
        double r14030875 = r14030871 * r14030874;
        double r14030876 = r14030872 + r14030875;
        double r14030877 = log(r14030876);
        double r14030878 = t;
        double r14030879 = r14030877 / r14030878;
        double r14030880 = r14030869 - r14030879;
        return r14030880;
}

double f(double x, double y, double z, double t) {
        double r14030881 = z;
        double r14030882 = -2.6516919137036032e-24;
        bool r14030883 = r14030881 <= r14030882;
        double r14030884 = x;
        double r14030885 = 0.5;
        double r14030886 = expm1(r14030881);
        double r14030887 = y;
        double r14030888 = 1.0;
        double r14030889 = fma(r14030886, r14030887, r14030888);
        double r14030890 = log(r14030889);
        double r14030891 = r14030885 * r14030890;
        double r14030892 = sqrt(r14030889);
        double r14030893 = log(r14030892);
        double r14030894 = r14030891 + r14030893;
        double r14030895 = r14030893 + r14030893;
        double r14030896 = r14030894 * r14030895;
        double r14030897 = r14030896 * r14030890;
        double r14030898 = cbrt(r14030897);
        double r14030899 = t;
        double r14030900 = r14030898 / r14030899;
        double r14030901 = r14030884 - r14030900;
        double r14030902 = r14030887 * r14030881;
        double r14030903 = r14030902 / r14030899;
        double r14030904 = 0.5;
        double r14030905 = r14030902 * r14030881;
        double r14030906 = r14030905 / r14030899;
        double r14030907 = log(r14030888);
        double r14030908 = r14030907 / r14030899;
        double r14030909 = fma(r14030904, r14030906, r14030908);
        double r14030910 = fma(r14030888, r14030903, r14030909);
        double r14030911 = r14030884 - r14030910;
        double r14030912 = r14030883 ? r14030901 : r14030911;
        return r14030912;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.3
Target16.3
Herbie8.6
\[\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 < -2.6516919137036032e-24

    1. Initial program 12.1

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

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

      \[\leadsto x - \frac{\sqrt[3]{\left(\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right) \cdot \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)}\right) \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}}{t}\]
    7. Applied log-prod11.7

      \[\leadsto x - \frac{\sqrt[3]{\left(\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right) \cdot \color{blue}{\left(\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)\right)}\right) \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}}{t}\]
    8. Using strategy rm
    9. Applied pow1/211.7

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

      \[\leadsto x - \frac{\sqrt[3]{\left(\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right) \cdot \left(\color{blue}{\frac{1}{2} \cdot \log \left(\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)\right)\right) \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}}{t}\]
    11. Using strategy rm
    12. Applied add-sqr-sqrt11.7

      \[\leadsto x - \frac{\sqrt[3]{\left(\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 \left(\frac{1}{2} \cdot \log \left(\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)\right)\right) \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}}{t}\]
    13. Applied log-prod11.7

      \[\leadsto x - \frac{\sqrt[3]{\left(\color{blue}{\left(\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)\right)} \cdot \left(\frac{1}{2} \cdot \log \left(\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)\right)\right) \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}}{t}\]

    if -2.6516919137036032e-24 < z

    1. Initial program 31.4

      \[x - \frac{\log \left(\left(1 - 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\right)\right)}{t}}\]
    3. Taylor expanded around 0 7.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -2.651691913703603211150672208558212938576 \cdot 10^{-24}:\\ \;\;\;\;x - \frac{\sqrt[3]{\left(\left(\frac{1}{2} \cdot \log \left(\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)\right) \cdot \left(\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)\right)\right) \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{fma}\left(1, \frac{y \cdot z}{t}, \mathsf{fma}\left(0.5, \frac{\left(y \cdot z\right) \cdot z}{t}, \frac{\log 1}{t}\right)\right)\\ \end{array}\]

Reproduce

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