Average Error: 24.7 → 8.4
Time: 14.6s
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.35121526181544394:\\ \;\;\;\;x - \frac{\frac{1}{2} \cdot \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]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right)\right) + \log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{fma}\left(\frac{\frac{z \cdot y}{1}}{t}, \frac{1}{2}, \mathsf{fma}\left(\frac{z \cdot y}{t}, 0.5, \mathsf{fma}\left(\frac{1}{2}, \frac{\log 1}{t}, \mathsf{fma}\left(\frac{1}{4}, \frac{\frac{{z}^{2} \cdot y}{t}}{1}, \mathsf{fma}\left(0.25, \frac{{z}^{2} \cdot y}{t}, \frac{\log \left(\sqrt{1}\right)}{t}\right)\right)\right)\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.35121526181544394:\\
\;\;\;\;x - \frac{\frac{1}{2} \cdot \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]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right)\right) + \log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right)}{t}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r338554 = x;
        double r338555 = 1.0;
        double r338556 = y;
        double r338557 = r338555 - r338556;
        double r338558 = z;
        double r338559 = exp(r338558);
        double r338560 = r338556 * r338559;
        double r338561 = r338557 + r338560;
        double r338562 = log(r338561);
        double r338563 = t;
        double r338564 = r338562 / r338563;
        double r338565 = r338554 - r338564;
        return r338565;
}

double f(double x, double y, double z, double t) {
        double r338566 = z;
        double r338567 = exp(r338566);
        double r338568 = 0.35121526181544394;
        bool r338569 = r338567 <= r338568;
        double r338570 = x;
        double r338571 = 0.5;
        double r338572 = 2.0;
        double r338573 = 0.3333333333333333;
        double r338574 = expm1(r338566);
        double r338575 = y;
        double r338576 = 1.0;
        double r338577 = fma(r338574, r338575, r338576);
        double r338578 = log(r338577);
        double r338579 = r338573 * r338578;
        double r338580 = r338572 * r338579;
        double r338581 = cbrt(r338577);
        double r338582 = log(r338581);
        double r338583 = r338580 + r338582;
        double r338584 = r338571 * r338583;
        double r338585 = sqrt(r338577);
        double r338586 = log(r338585);
        double r338587 = r338584 + r338586;
        double r338588 = t;
        double r338589 = r338587 / r338588;
        double r338590 = r338570 - r338589;
        double r338591 = r338566 * r338575;
        double r338592 = r338591 / r338576;
        double r338593 = r338592 / r338588;
        double r338594 = r338591 / r338588;
        double r338595 = 0.5;
        double r338596 = log(r338576);
        double r338597 = r338596 / r338588;
        double r338598 = 0.25;
        double r338599 = pow(r338566, r338572);
        double r338600 = r338599 * r338575;
        double r338601 = r338600 / r338588;
        double r338602 = r338601 / r338576;
        double r338603 = 0.25;
        double r338604 = sqrt(r338576);
        double r338605 = log(r338604);
        double r338606 = r338605 / r338588;
        double r338607 = fma(r338603, r338601, r338606);
        double r338608 = fma(r338598, r338602, r338607);
        double r338609 = fma(r338571, r338597, r338608);
        double r338610 = fma(r338594, r338595, r338609);
        double r338611 = fma(r338593, r338571, r338610);
        double r338612 = r338570 - r338611;
        double r338613 = r338569 ? r338590 : r338612;
        return r338613;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original24.7
Target15.9
Herbie8.4
\[\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.35121526181544394

    1. Initial program 10.8

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

      \[\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 add-sqr-sqrt10.8

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

      \[\leadsto x - \frac{\color{blue}{\log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right) + \log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right)}}{t}\]
    6. Using strategy rm
    7. Applied pow1/210.8

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

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

      \[\leadsto x - \frac{\frac{1}{2} \cdot \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)} + \log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right)}{t}\]
    11. Applied log-prod10.8

      \[\leadsto x - \frac{\frac{1}{2} \cdot \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)} + \log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right)}{t}\]
    12. Simplified10.8

      \[\leadsto x - \frac{\frac{1}{2} \cdot \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) + \log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right)}{t}\]
    13. Using strategy rm
    14. Applied pow1/310.8

      \[\leadsto x - \frac{\frac{1}{2} \cdot \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) + \log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right)}{t}\]
    15. Applied log-pow10.8

      \[\leadsto x - \frac{\frac{1}{2} \cdot \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) + \log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right)}{t}\]

    if 0.35121526181544394 < (exp z)

    1. Initial program 30.7

      \[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 add-sqr-sqrt11.5

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

      \[\leadsto x - \frac{\color{blue}{\log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right) + \log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right)}}{t}\]
    6. Using strategy rm
    7. Applied pow1/211.5

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

      \[\leadsto x - \frac{\color{blue}{\frac{1}{2} \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)} + \log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right)}{t}\]
    9. Taylor expanded around 0 7.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{z} \le 0.35121526181544394:\\ \;\;\;\;x - \frac{\frac{1}{2} \cdot \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]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right)\right) + \log \left(\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{fma}\left(\frac{\frac{z \cdot y}{1}}{t}, \frac{1}{2}, \mathsf{fma}\left(\frac{z \cdot y}{t}, 0.5, \mathsf{fma}\left(\frac{1}{2}, \frac{\log 1}{t}, \mathsf{fma}\left(\frac{1}{4}, \frac{\frac{{z}^{2} \cdot y}{t}}{1}, \mathsf{fma}\left(0.25, \frac{{z}^{2} \cdot y}{t}, \frac{\log \left(\sqrt{1}\right)}{t}\right)\right)\right)\right)\right)\\ \end{array}\]

Reproduce

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