Average Error: 24.4 → 7.6
Time: 28.5s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -6.358797691452859197803043329522892515885 \cdot 10^{-48}:\\ \;\;\;\;x - \frac{\left(\log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right) + \log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)\right) + \left(\log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right) + \left(\log \left(\sqrt{\left|\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right|}\right) + \log \left(\sqrt{\sqrt{\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}}\right)\right)\right)}{t}\\ \mathbf{elif}\;z \le 5.278878335163116895565645241280298789929 \cdot 10^{-40}:\\ \;\;\;\;x - \mathsf{fma}\left(\frac{z}{t}, \frac{y}{1}, \mathsf{fma}\left(\frac{1}{2}, \frac{\frac{{z}^{2} \cdot y}{1}}{t}, 2 \cdot \frac{\log \left(\sqrt{1}\right)}{t}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\log \left(\mathsf{fma}\left(y, \mathsf{fma}\left(\frac{1}{2}, {z}^{2}, z\right), 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 -6.358797691452859197803043329522892515885 \cdot 10^{-48}:\\
\;\;\;\;x - \frac{\left(\log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right) + \log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)\right) + \left(\log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right) + \left(\log \left(\sqrt{\left|\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right|}\right) + \log \left(\sqrt{\sqrt{\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}}\right)\right)\right)}{t}\\

\mathbf{elif}\;z \le 5.278878335163116895565645241280298789929 \cdot 10^{-40}:\\
\;\;\;\;x - \mathsf{fma}\left(\frac{z}{t}, \frac{y}{1}, \mathsf{fma}\left(\frac{1}{2}, \frac{\frac{{z}^{2} \cdot y}{1}}{t}, 2 \cdot \frac{\log \left(\sqrt{1}\right)}{t}\right)\right)\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r174695 = x;
        double r174696 = 1.0;
        double r174697 = y;
        double r174698 = r174696 - r174697;
        double r174699 = z;
        double r174700 = exp(r174699);
        double r174701 = r174697 * r174700;
        double r174702 = r174698 + r174701;
        double r174703 = log(r174702);
        double r174704 = t;
        double r174705 = r174703 / r174704;
        double r174706 = r174695 - r174705;
        return r174706;
}

double f(double x, double y, double z, double t) {
        double r174707 = z;
        double r174708 = -6.358797691452859e-48;
        bool r174709 = r174707 <= r174708;
        double r174710 = x;
        double r174711 = expm1(r174707);
        double r174712 = y;
        double r174713 = 1.0;
        double r174714 = fma(r174711, r174712, r174713);
        double r174715 = sqrt(r174714);
        double r174716 = sqrt(r174715);
        double r174717 = log(r174716);
        double r174718 = r174717 + r174717;
        double r174719 = cbrt(r174714);
        double r174720 = fabs(r174719);
        double r174721 = sqrt(r174720);
        double r174722 = log(r174721);
        double r174723 = sqrt(r174719);
        double r174724 = sqrt(r174723);
        double r174725 = log(r174724);
        double r174726 = r174722 + r174725;
        double r174727 = r174717 + r174726;
        double r174728 = r174718 + r174727;
        double r174729 = t;
        double r174730 = r174728 / r174729;
        double r174731 = r174710 - r174730;
        double r174732 = 5.278878335163117e-40;
        bool r174733 = r174707 <= r174732;
        double r174734 = r174707 / r174729;
        double r174735 = r174712 / r174713;
        double r174736 = 0.5;
        double r174737 = 2.0;
        double r174738 = pow(r174707, r174737);
        double r174739 = r174738 * r174712;
        double r174740 = r174739 / r174713;
        double r174741 = r174740 / r174729;
        double r174742 = sqrt(r174713);
        double r174743 = log(r174742);
        double r174744 = r174743 / r174729;
        double r174745 = r174737 * r174744;
        double r174746 = fma(r174736, r174741, r174745);
        double r174747 = fma(r174734, r174735, r174746);
        double r174748 = r174710 - r174747;
        double r174749 = fma(r174736, r174738, r174707);
        double r174750 = fma(r174712, r174749, r174713);
        double r174751 = log(r174750);
        double r174752 = r174751 / r174729;
        double r174753 = r174710 - r174752;
        double r174754 = r174733 ? r174748 : r174753;
        double r174755 = r174709 ? r174731 : r174754;
        return r174755;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original24.4
Target16.5
Herbie7.6
\[\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 3 regimes
  2. if z < -6.358797691452859e-48

    1. Initial program 13.2

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

      \[\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.2

      \[\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.1

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

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

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

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

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

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

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

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

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

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

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

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

    if -6.358797691452859e-48 < z < 5.278878335163117e-40

    1. Initial program 30.6

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

      \[\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.3

      \[\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.3

      \[\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. Taylor expanded around 0 6.3

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

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

    if 5.278878335163117e-40 < z

    1. Initial program 25.6

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

      \[\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 11.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -6.358797691452859197803043329522892515885 \cdot 10^{-48}:\\ \;\;\;\;x - \frac{\left(\log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right) + \log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right)\right) + \left(\log \left(\sqrt{\sqrt{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}\right) + \left(\log \left(\sqrt{\left|\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}\right|}\right) + \log \left(\sqrt{\sqrt{\sqrt[3]{\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)}}}\right)\right)\right)}{t}\\ \mathbf{elif}\;z \le 5.278878335163116895565645241280298789929 \cdot 10^{-40}:\\ \;\;\;\;x - \mathsf{fma}\left(\frac{z}{t}, \frac{y}{1}, \mathsf{fma}\left(\frac{1}{2}, \frac{\frac{{z}^{2} \cdot y}{1}}{t}, 2 \cdot \frac{\log \left(\sqrt{1}\right)}{t}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\log \left(\mathsf{fma}\left(y, \mathsf{fma}\left(\frac{1}{2}, {z}^{2}, z\right), 1\right)\right)}{t}\\ \end{array}\]

Reproduce

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