Average Error: 24.7 → 8.5
Time: 13.2s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -2.30675114307191926 \cdot 10^{-79}:\\ \;\;\;\;x - \left(2 \cdot \left(\frac{1}{3} \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)\right) + \left(\log \left(\sqrt[3]{e^{2 \cdot \log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right)}}\right) + \log \left(\sqrt[3]{\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)\right)\right) \cdot \frac{1}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\mathsf{fma}\left(0.5, {z}^{2} \cdot y, \mathsf{fma}\left(1, z \cdot y, \log 1\right)\right)}{t}\\ \end{array}\]
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
\mathbf{if}\;z \le -2.30675114307191926 \cdot 10^{-79}:\\
\;\;\;\;x - \left(2 \cdot \left(\frac{1}{3} \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)\right) + \left(\log \left(\sqrt[3]{e^{2 \cdot \log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right)}}\right) + \log \left(\sqrt[3]{\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)\right)\right) \cdot \frac{1}{t}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r250466 = x;
        double r250467 = 1.0;
        double r250468 = y;
        double r250469 = r250467 - r250468;
        double r250470 = z;
        double r250471 = exp(r250470);
        double r250472 = r250468 * r250471;
        double r250473 = r250469 + r250472;
        double r250474 = log(r250473);
        double r250475 = t;
        double r250476 = r250474 / r250475;
        double r250477 = r250466 - r250476;
        return r250477;
}

double f(double x, double y, double z, double t) {
        double r250478 = z;
        double r250479 = -2.3067511430719193e-79;
        bool r250480 = r250478 <= r250479;
        double r250481 = x;
        double r250482 = 2.0;
        double r250483 = 0.3333333333333333;
        double r250484 = expm1(r250478);
        double r250485 = y;
        double r250486 = 1.0;
        double r250487 = fma(r250484, r250485, r250486);
        double r250488 = log(r250487);
        double r250489 = r250483 * r250488;
        double r250490 = r250482 * r250489;
        double r250491 = cbrt(r250487);
        double r250492 = log(r250491);
        double r250493 = r250482 * r250492;
        double r250494 = exp(r250493);
        double r250495 = cbrt(r250494);
        double r250496 = log(r250495);
        double r250497 = cbrt(r250491);
        double r250498 = log(r250497);
        double r250499 = r250496 + r250498;
        double r250500 = r250490 + r250499;
        double r250501 = 1.0;
        double r250502 = t;
        double r250503 = r250501 / r250502;
        double r250504 = r250500 * r250503;
        double r250505 = r250481 - r250504;
        double r250506 = 0.5;
        double r250507 = pow(r250478, r250482);
        double r250508 = r250507 * r250485;
        double r250509 = r250478 * r250485;
        double r250510 = log(r250486);
        double r250511 = fma(r250486, r250509, r250510);
        double r250512 = fma(r250506, r250508, r250511);
        double r250513 = r250512 / r250502;
        double r250514 = r250481 - r250513;
        double r250515 = r250480 ? r250505 : r250514;
        return r250515;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original24.7
Target16.3
Herbie8.5
\[\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.3067511430719193e-79

    1. Initial program 14.9

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

      \[\leadsto \color{blue}{x - \frac{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}{t}}\]
    3. Using strategy rm
    4. Applied div-inv11.6

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

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

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

      \[\leadsto x - \left(\color{blue}{2 \cdot \log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right)} + \log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right)\right) \cdot \frac{1}{t}\]
    9. Using strategy rm
    10. Applied pow1/311.6

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

      \[\leadsto x - \left(2 \cdot \color{blue}{\left(\frac{1}{3} \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)\right)} + \log \left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right)\right) \cdot \frac{1}{t}\]
    12. Using strategy rm
    13. Applied add-cube-cbrt11.6

      \[\leadsto x - \left(2 \cdot \left(\frac{1}{3} \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)\right) + \log \left(\sqrt[3]{\color{blue}{\left(\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}}\right)\right) \cdot \frac{1}{t}\]
    14. Applied cbrt-prod11.6

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

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

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

    if -2.3067511430719193e-79 < z

    1. Initial program 30.9

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

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

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

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

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

Reproduce

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