Average Error: 25.4 → 9.1
Time: 10.3s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -2.4006361517684793 \cdot 10^{-172}:\\ \;\;\;\;x - \frac{\frac{1}{t}}{\frac{1}{\log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{fma}\left(\frac{z \cdot y}{t}, 1, \mathsf{fma}\left(0.5, \frac{{z}^{2} \cdot y}{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.4006361517684793 \cdot 10^{-172}:\\
\;\;\;\;x - \frac{\frac{1}{t}}{\frac{1}{\log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right)}}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r227153 = x;
        double r227154 = 1.0;
        double r227155 = y;
        double r227156 = r227154 - r227155;
        double r227157 = z;
        double r227158 = exp(r227157);
        double r227159 = r227155 * r227158;
        double r227160 = r227156 + r227159;
        double r227161 = log(r227160);
        double r227162 = t;
        double r227163 = r227161 / r227162;
        double r227164 = r227153 - r227163;
        return r227164;
}

double f(double x, double y, double z, double t) {
        double r227165 = z;
        double r227166 = -2.4006361517684793e-172;
        bool r227167 = r227165 <= r227166;
        double r227168 = x;
        double r227169 = 1.0;
        double r227170 = t;
        double r227171 = r227169 / r227170;
        double r227172 = 1.0;
        double r227173 = y;
        double r227174 = expm1(r227165);
        double r227175 = r227173 * r227174;
        double r227176 = r227172 + r227175;
        double r227177 = log(r227176);
        double r227178 = r227169 / r227177;
        double r227179 = r227171 / r227178;
        double r227180 = r227168 - r227179;
        double r227181 = r227165 * r227173;
        double r227182 = r227181 / r227170;
        double r227183 = 0.5;
        double r227184 = 2.0;
        double r227185 = pow(r227165, r227184);
        double r227186 = r227185 * r227173;
        double r227187 = r227186 / r227170;
        double r227188 = log(r227172);
        double r227189 = r227188 / r227170;
        double r227190 = fma(r227183, r227187, r227189);
        double r227191 = fma(r227182, r227172, r227190);
        double r227192 = r227168 - r227191;
        double r227193 = r227167 ? r227180 : r227192;
        return r227193;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.4
Target16.5
Herbie9.1
\[\begin{array}{l} \mathbf{if}\;z \lt -2.88746230882079466 \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.4006361517684793e-172

    1. Initial program 18.9

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Using strategy rm
    3. Applied sub-neg18.9

      \[\leadsto x - \frac{\log \left(\color{blue}{\left(1 + \left(-y\right)\right)} + y \cdot e^{z}\right)}{t}\]
    4. Applied associate-+l+14.8

      \[\leadsto x - \frac{\log \color{blue}{\left(1 + \left(\left(-y\right) + y \cdot e^{z}\right)\right)}}{t}\]
    5. Simplified12.3

      \[\leadsto x - \frac{\log \left(1 + \color{blue}{y \cdot \mathsf{expm1}\left(z\right)}\right)}{t}\]
    6. Using strategy rm
    7. Applied clear-num12.3

      \[\leadsto x - \color{blue}{\frac{1}{\frac{t}{\log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right)}}}\]
    8. Using strategy rm
    9. Applied div-inv12.3

      \[\leadsto x - \frac{1}{\color{blue}{t \cdot \frac{1}{\log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right)}}}\]
    10. Applied associate-/r*12.3

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

    if -2.4006361517684793e-172 < z

    1. Initial program 31.3

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Using strategy rm
    3. Applied sub-neg31.3

      \[\leadsto x - \frac{\log \left(\color{blue}{\left(1 + \left(-y\right)\right)} + y \cdot e^{z}\right)}{t}\]
    4. Applied associate-+l+15.2

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

      \[\leadsto x - \frac{\log \left(1 + \color{blue}{y \cdot \mathsf{expm1}\left(z\right)}\right)}{t}\]
    6. Taylor expanded around 0 6.2

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

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

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

Reproduce

herbie shell --seed 2020034 +o rules:numerics
(FPCore (x y z t)
  :name "System.Random.MWC.Distributions:truncatedExp from mwc-random-0.13.3.2"
  :precision binary64

  :herbie-target
  (if (< z -2.8874623088207947e+119) (- (- x (/ (/ (- 0.5) (* y t)) (* z z))) (* (/ (- 0.5) (* y t)) (/ (/ 2 z) (* z z)))) (- x (/ (log (+ 1 (* z y))) t)))

  (- x (/ (log (+ (- 1 y) (* y (exp z)))) t)))