Average Error: 24.2 → 7.5
Time: 34.1s
Precision: 64
\[x - \frac{\log \left(\left(1.0 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -8.129712844584067 \cdot 10^{-48}:\\ \;\;\;\;x - \frac{1}{t} \cdot \left(\log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right) + \log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right)\right)\\ \mathbf{elif}\;z \le 2.2704556920605612 \cdot 10^{-138}:\\ \;\;\;\;x - \mathsf{fma}\left(1.0, y \cdot \frac{z}{t}, \mathsf{fma}\left(\left(y \cdot \frac{z}{t}\right) \cdot z, 0.5, \frac{\log 1.0}{t}\right)\right)\\ \mathbf{elif}\;z \le 1.5179641018211793 \cdot 10^{-121}:\\ \;\;\;\;x - \frac{1}{t} \cdot \left(\log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right) + \log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{fma}\left(1.0, y \cdot \frac{z}{t}, \mathsf{fma}\left(\left(y \cdot \frac{z}{t}\right) \cdot z, 0.5, \frac{\log 1.0}{t}\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 -8.129712844584067 \cdot 10^{-48}:\\
\;\;\;\;x - \frac{1}{t} \cdot \left(\log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right) + \log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right)\right)\\

\mathbf{elif}\;z \le 2.2704556920605612 \cdot 10^{-138}:\\
\;\;\;\;x - \mathsf{fma}\left(1.0, y \cdot \frac{z}{t}, \mathsf{fma}\left(\left(y \cdot \frac{z}{t}\right) \cdot z, 0.5, \frac{\log 1.0}{t}\right)\right)\\

\mathbf{elif}\;z \le 1.5179641018211793 \cdot 10^{-121}:\\
\;\;\;\;x - \frac{1}{t} \cdot \left(\log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right) + \log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right)\right)\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r14725861 = x;
        double r14725862 = 1.0;
        double r14725863 = y;
        double r14725864 = r14725862 - r14725863;
        double r14725865 = z;
        double r14725866 = exp(r14725865);
        double r14725867 = r14725863 * r14725866;
        double r14725868 = r14725864 + r14725867;
        double r14725869 = log(r14725868);
        double r14725870 = t;
        double r14725871 = r14725869 / r14725870;
        double r14725872 = r14725861 - r14725871;
        return r14725872;
}

double f(double x, double y, double z, double t) {
        double r14725873 = z;
        double r14725874 = -8.129712844584067e-48;
        bool r14725875 = r14725873 <= r14725874;
        double r14725876 = x;
        double r14725877 = 1.0;
        double r14725878 = t;
        double r14725879 = r14725877 / r14725878;
        double r14725880 = expm1(r14725873);
        double r14725881 = y;
        double r14725882 = 1.0;
        double r14725883 = fma(r14725880, r14725881, r14725882);
        double r14725884 = cbrt(r14725883);
        double r14725885 = log(r14725884);
        double r14725886 = r14725884 * r14725884;
        double r14725887 = log(r14725886);
        double r14725888 = r14725885 + r14725887;
        double r14725889 = r14725879 * r14725888;
        double r14725890 = r14725876 - r14725889;
        double r14725891 = 2.2704556920605612e-138;
        bool r14725892 = r14725873 <= r14725891;
        double r14725893 = r14725873 / r14725878;
        double r14725894 = r14725881 * r14725893;
        double r14725895 = r14725894 * r14725873;
        double r14725896 = 0.5;
        double r14725897 = log(r14725882);
        double r14725898 = r14725897 / r14725878;
        double r14725899 = fma(r14725895, r14725896, r14725898);
        double r14725900 = fma(r14725882, r14725894, r14725899);
        double r14725901 = r14725876 - r14725900;
        double r14725902 = 1.5179641018211793e-121;
        bool r14725903 = r14725873 <= r14725902;
        double r14725904 = r14725903 ? r14725890 : r14725901;
        double r14725905 = r14725892 ? r14725901 : r14725904;
        double r14725906 = r14725875 ? r14725890 : r14725905;
        return r14725906;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original24.2
Target15.9
Herbie7.5
\[\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 < -8.129712844584067e-48 or 2.2704556920605612e-138 < z < 1.5179641018211793e-121

    1. Initial program 14.0

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

      \[\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 div-inv10.8

      \[\leadsto x - \color{blue}{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)\right) \cdot \frac{1}{t}}\]
    5. Using strategy rm
    6. Applied add-cube-cbrt10.8

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

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

    if -8.129712844584067e-48 < z < 2.2704556920605612e-138 or 1.5179641018211793e-121 < z

    1. Initial program 29.7

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -8.129712844584067 \cdot 10^{-48}:\\ \;\;\;\;x - \frac{1}{t} \cdot \left(\log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right) + \log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right)\right)\\ \mathbf{elif}\;z \le 2.2704556920605612 \cdot 10^{-138}:\\ \;\;\;\;x - \mathsf{fma}\left(1.0, y \cdot \frac{z}{t}, \mathsf{fma}\left(\left(y \cdot \frac{z}{t}\right) \cdot z, 0.5, \frac{\log 1.0}{t}\right)\right)\\ \mathbf{elif}\;z \le 1.5179641018211793 \cdot 10^{-121}:\\ \;\;\;\;x - \frac{1}{t} \cdot \left(\log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right) + \log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{fma}\left(1.0, y \cdot \frac{z}{t}, \mathsf{fma}\left(\left(y \cdot \frac{z}{t}\right) \cdot z, 0.5, \frac{\log 1.0}{t}\right)\right)\\ \end{array}\]

Reproduce

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