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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r267040 = x;
        double r267041 = 1.0;
        double r267042 = y;
        double r267043 = r267041 - r267042;
        double r267044 = z;
        double r267045 = exp(r267044);
        double r267046 = r267042 * r267045;
        double r267047 = r267043 + r267046;
        double r267048 = log(r267047);
        double r267049 = t;
        double r267050 = r267048 / r267049;
        double r267051 = r267040 - r267050;
        return r267051;
}

double f(double x, double y, double z, double t) {
        double r267052 = z;
        double r267053 = exp(r267052);
        double r267054 = 2.461902045552825e-25;
        bool r267055 = r267053 <= r267054;
        double r267056 = x;
        double r267057 = 2.0;
        double r267058 = y;
        double r267059 = 1.0;
        double r267060 = r267059 - r267058;
        double r267061 = fma(r267058, r267053, r267060);
        double r267062 = cbrt(r267061);
        double r267063 = log(r267062);
        double r267064 = r267057 * r267063;
        double r267065 = r267064 + r267063;
        double r267066 = t;
        double r267067 = r267065 / r267066;
        double r267068 = r267056 - r267067;
        double r267069 = r267052 / r267066;
        double r267070 = r267058 * r267069;
        double r267071 = r267052 * r267058;
        double r267072 = 3.0;
        double r267073 = pow(r267071, r267072);
        double r267074 = pow(r267052, r267072);
        double r267075 = r267073 * r267074;
        double r267076 = cbrt(r267075);
        double r267077 = r267076 / r267066;
        double r267078 = 0.5;
        double r267079 = log(r267059);
        double r267080 = r267079 / r267066;
        double r267081 = fma(r267077, r267078, r267080);
        double r267082 = fma(r267059, r267070, r267081);
        double r267083 = r267056 - r267082;
        double r267084 = r267055 ? r267068 : r267083;
        return r267084;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.1
Target16.6
Herbie8.9
\[\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 (exp z) < 2.461902045552825e-25

    1. Initial program 11.8

      \[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(y, e^{z}, 1 - y\right)\right)}{t}}\]
    3. Using strategy rm
    4. Applied add-cube-cbrt11.8

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

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

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

    if 2.461902045552825e-25 < (exp z)

    1. Initial program 30.8

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

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

      \[\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. Simplified6.5

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

      \[\leadsto x - \mathsf{fma}\left(1, \frac{z}{t} \cdot y, \mathsf{fma}\left(\frac{\left(y \cdot z\right) \cdot \color{blue}{\sqrt[3]{\left(z \cdot z\right) \cdot z}}}{t}, 0.5, \frac{\log 1}{t}\right)\right)\]
    7. Applied add-cbrt-cube7.7

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

      \[\leadsto x - \mathsf{fma}\left(1, \frac{z}{t} \cdot y, \mathsf{fma}\left(\frac{\color{blue}{\sqrt[3]{\left(\left(\left(y \cdot z\right) \cdot \left(y \cdot z\right)\right) \cdot \left(y \cdot z\right)\right) \cdot \left(\left(z \cdot z\right) \cdot z\right)}}}{t}, 0.5, \frac{\log 1}{t}\right)\right)\]
    9. Simplified7.7

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

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

Reproduce

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