Average Error: 24.2 → 7.6
Time: 40.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 -1.200391987755555 \cdot 10^{-81}:\\ \;\;\;\;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 1.9712400723203086 \cdot 10^{-138}:\\ \;\;\;\;x - \mathsf{fma}\left(\frac{z}{t}, y \cdot 1.0, \mathsf{fma}\left(0.5, \frac{\left(z \cdot z\right) \cdot y}{t}, \frac{\log 1.0}{t}\right)\right)\\ \mathbf{elif}\;z \le 8.16242381116947 \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 - \frac{\mathsf{fma}\left(y, z \cdot \mathsf{fma}\left(z, 0.5, 1.0\right), \log 1.0\right)}{t}\\ \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.200391987755555 \cdot 10^{-81}:\\
\;\;\;\;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 1.9712400723203086 \cdot 10^{-138}:\\
\;\;\;\;x - \mathsf{fma}\left(\frac{z}{t}, y \cdot 1.0, \mathsf{fma}\left(0.5, \frac{\left(z \cdot z\right) \cdot y}{t}, \frac{\log 1.0}{t}\right)\right)\\

\mathbf{elif}\;z \le 8.16242381116947 \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 - \frac{\mathsf{fma}\left(y, z \cdot \mathsf{fma}\left(z, 0.5, 1.0\right), \log 1.0\right)}{t}\\

\end{array}
double f(double x, double y, double z, double t) {
        double r12936881 = x;
        double r12936882 = 1.0;
        double r12936883 = y;
        double r12936884 = r12936882 - r12936883;
        double r12936885 = z;
        double r12936886 = exp(r12936885);
        double r12936887 = r12936883 * r12936886;
        double r12936888 = r12936884 + r12936887;
        double r12936889 = log(r12936888);
        double r12936890 = t;
        double r12936891 = r12936889 / r12936890;
        double r12936892 = r12936881 - r12936891;
        return r12936892;
}

double f(double x, double y, double z, double t) {
        double r12936893 = z;
        double r12936894 = -1.200391987755555e-81;
        bool r12936895 = r12936893 <= r12936894;
        double r12936896 = x;
        double r12936897 = 1.0;
        double r12936898 = t;
        double r12936899 = r12936897 / r12936898;
        double r12936900 = expm1(r12936893);
        double r12936901 = y;
        double r12936902 = 1.0;
        double r12936903 = fma(r12936900, r12936901, r12936902);
        double r12936904 = cbrt(r12936903);
        double r12936905 = log(r12936904);
        double r12936906 = r12936904 * r12936904;
        double r12936907 = log(r12936906);
        double r12936908 = r12936905 + r12936907;
        double r12936909 = r12936899 * r12936908;
        double r12936910 = r12936896 - r12936909;
        double r12936911 = 1.9712400723203086e-138;
        bool r12936912 = r12936893 <= r12936911;
        double r12936913 = r12936893 / r12936898;
        double r12936914 = r12936901 * r12936902;
        double r12936915 = 0.5;
        double r12936916 = r12936893 * r12936893;
        double r12936917 = r12936916 * r12936901;
        double r12936918 = r12936917 / r12936898;
        double r12936919 = log(r12936902);
        double r12936920 = r12936919 / r12936898;
        double r12936921 = fma(r12936915, r12936918, r12936920);
        double r12936922 = fma(r12936913, r12936914, r12936921);
        double r12936923 = r12936896 - r12936922;
        double r12936924 = 8.16242381116947e-121;
        bool r12936925 = r12936893 <= r12936924;
        double r12936926 = fma(r12936893, r12936915, r12936902);
        double r12936927 = r12936893 * r12936926;
        double r12936928 = fma(r12936901, r12936927, r12936919);
        double r12936929 = r12936928 / r12936898;
        double r12936930 = r12936896 - r12936929;
        double r12936931 = r12936925 ? r12936910 : r12936930;
        double r12936932 = r12936912 ? r12936923 : r12936931;
        double r12936933 = r12936895 ? r12936910 : r12936932;
        return r12936933;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original24.2
Target15.9
Herbie7.6
\[\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 3 regimes
  2. if z < -1.200391987755555e-81 or 1.9712400723203086e-138 < z < 8.16242381116947e-121

    1. Initial program 15.4

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

      \[\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 -1.200391987755555e-81 < z < 1.9712400723203086e-138

    1. Initial program 29.8

      \[x - \frac{\log \left(\left(1.0 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Simplified10.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 div-inv10.7

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

      \[\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)}\]
    6. Simplified4.0

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

    if 8.16242381116947e-121 < z

    1. Initial program 29.4

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

      \[\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 11.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -1.200391987755555 \cdot 10^{-81}:\\ \;\;\;\;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 1.9712400723203086 \cdot 10^{-138}:\\ \;\;\;\;x - \mathsf{fma}\left(\frac{z}{t}, y \cdot 1.0, \mathsf{fma}\left(0.5, \frac{\left(z \cdot z\right) \cdot y}{t}, \frac{\log 1.0}{t}\right)\right)\\ \mathbf{elif}\;z \le 8.16242381116947 \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 - \frac{\mathsf{fma}\left(y, z \cdot \mathsf{fma}\left(z, 0.5, 1.0\right), \log 1.0\right)}{t}\\ \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)))