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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r307374 = x;
        double r307375 = 1.0;
        double r307376 = y;
        double r307377 = r307375 - r307376;
        double r307378 = z;
        double r307379 = exp(r307378);
        double r307380 = r307376 * r307379;
        double r307381 = r307377 + r307380;
        double r307382 = log(r307381);
        double r307383 = t;
        double r307384 = r307382 / r307383;
        double r307385 = r307374 - r307384;
        return r307385;
}

double f(double x, double y, double z, double t) {
        double r307386 = z;
        double r307387 = exp(r307386);
        double r307388 = 0.9985612528813593;
        bool r307389 = r307387 <= r307388;
        double r307390 = x;
        double r307391 = 1.0;
        double r307392 = t;
        double r307393 = 1.0;
        double r307394 = y;
        double r307395 = expm1(r307386);
        double r307396 = r307394 * r307395;
        double r307397 = r307393 + r307396;
        double r307398 = log(r307397);
        double r307399 = r307392 / r307398;
        double r307400 = r307391 / r307399;
        double r307401 = r307390 - r307400;
        double r307402 = 0.5;
        double r307403 = 2.0;
        double r307404 = pow(r307386, r307403);
        double r307405 = r307404 * r307394;
        double r307406 = r307386 * r307394;
        double r307407 = log(r307393);
        double r307408 = fma(r307393, r307406, r307407);
        double r307409 = fma(r307402, r307405, r307408);
        double r307410 = r307392 / r307409;
        double r307411 = r307391 / r307410;
        double r307412 = r307390 - r307411;
        double r307413 = r307389 ? r307401 : r307412;
        return r307413;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original23.4
Target13.5
Herbie5.6
\[\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 (exp z) < 0.9985612528813593

    1. Initial program 0.7

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

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

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

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

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

    if 0.9985612528813593 < (exp z)

    1. Initial program 30.5

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

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

      \[\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. Using strategy rm
    7. Applied clear-num11.4

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

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

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

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

Reproduce

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