Average Error: 24.7 → 8.9
Time: 45.2s
Precision: 64
\[x - \frac{\log \left(\left(1.0 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -4.7684577859561445 \cdot 10^{-93}:\\ \;\;\;\;x - \frac{1}{t} \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)\right)\\ \mathbf{elif}\;z \le 4.604997342483359 \cdot 10^{-106}:\\ \;\;\;\;x - \frac{\mathsf{fma}\left(y, z \cdot \mathsf{fma}\left(z, 0.5, 1.0\right), \log 1.0\right)}{t}\\ \mathbf{elif}\;z \le 1.102266967415444 \cdot 10^{-17}:\\ \;\;\;\;x - \frac{1}{t} \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{fma}\left(\frac{z}{t}, y \cdot 1.0, \mathsf{fma}\left(0.5, \frac{\left(z \cdot z\right) \cdot y}{t}, \frac{\log 1.0}{t}\right)\right)\\ \end{array}\]
x - \frac{\log \left(\left(1.0 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
\mathbf{if}\;z \le -4.7684577859561445 \cdot 10^{-93}:\\
\;\;\;\;x - \frac{1}{t} \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)\right)\\

\mathbf{elif}\;z \le 4.604997342483359 \cdot 10^{-106}:\\
\;\;\;\;x - \frac{\mathsf{fma}\left(y, z \cdot \mathsf{fma}\left(z, 0.5, 1.0\right), \log 1.0\right)}{t}\\

\mathbf{elif}\;z \le 1.102266967415444 \cdot 10^{-17}:\\
\;\;\;\;x - \frac{1}{t} \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)\right)\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r10697756 = x;
        double r10697757 = 1.0;
        double r10697758 = y;
        double r10697759 = r10697757 - r10697758;
        double r10697760 = z;
        double r10697761 = exp(r10697760);
        double r10697762 = r10697758 * r10697761;
        double r10697763 = r10697759 + r10697762;
        double r10697764 = log(r10697763);
        double r10697765 = t;
        double r10697766 = r10697764 / r10697765;
        double r10697767 = r10697756 - r10697766;
        return r10697767;
}

double f(double x, double y, double z, double t) {
        double r10697768 = z;
        double r10697769 = -4.7684577859561445e-93;
        bool r10697770 = r10697768 <= r10697769;
        double r10697771 = x;
        double r10697772 = 1.0;
        double r10697773 = t;
        double r10697774 = r10697772 / r10697773;
        double r10697775 = expm1(r10697768);
        double r10697776 = y;
        double r10697777 = 1.0;
        double r10697778 = fma(r10697775, r10697776, r10697777);
        double r10697779 = log(r10697778);
        double r10697780 = r10697774 * r10697779;
        double r10697781 = r10697771 - r10697780;
        double r10697782 = 4.604997342483359e-106;
        bool r10697783 = r10697768 <= r10697782;
        double r10697784 = 0.5;
        double r10697785 = fma(r10697768, r10697784, r10697777);
        double r10697786 = r10697768 * r10697785;
        double r10697787 = log(r10697777);
        double r10697788 = fma(r10697776, r10697786, r10697787);
        double r10697789 = r10697788 / r10697773;
        double r10697790 = r10697771 - r10697789;
        double r10697791 = 1.102266967415444e-17;
        bool r10697792 = r10697768 <= r10697791;
        double r10697793 = r10697768 / r10697773;
        double r10697794 = r10697776 * r10697777;
        double r10697795 = r10697768 * r10697768;
        double r10697796 = r10697795 * r10697776;
        double r10697797 = r10697796 / r10697773;
        double r10697798 = r10697787 / r10697773;
        double r10697799 = fma(r10697784, r10697797, r10697798);
        double r10697800 = fma(r10697793, r10697794, r10697799);
        double r10697801 = r10697771 - r10697800;
        double r10697802 = r10697792 ? r10697781 : r10697801;
        double r10697803 = r10697783 ? r10697790 : r10697802;
        double r10697804 = r10697770 ? r10697781 : r10697803;
        return r10697804;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original24.7
Target16.5
Herbie8.9
\[\begin{array}{l} \mathbf{if}\;z \lt -2.8874623088207947 \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.0}{z}}{z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\log \left(1.0 + z \cdot y\right)}{t}\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if z < -4.7684577859561445e-93 or 4.604997342483359e-106 < z < 1.102266967415444e-17

    1. Initial program 19.3

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

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

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

    if -4.7684577859561445e-93 < z < 4.604997342483359e-106

    1. Initial program 29.9

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

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

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

      \[\leadsto x - \frac{\color{blue}{\mathsf{fma}\left(y, z \cdot \mathsf{fma}\left(z, 0.5, 1.0\right), \log 1.0\right)}}{t}\]

    if 1.102266967415444e-17 < z

    1. Initial program 27.7

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -4.7684577859561445 \cdot 10^{-93}:\\ \;\;\;\;x - \frac{1}{t} \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)\right)\\ \mathbf{elif}\;z \le 4.604997342483359 \cdot 10^{-106}:\\ \;\;\;\;x - \frac{\mathsf{fma}\left(y, z \cdot \mathsf{fma}\left(z, 0.5, 1.0\right), \log 1.0\right)}{t}\\ \mathbf{elif}\;z \le 1.102266967415444 \cdot 10^{-17}:\\ \;\;\;\;x - \frac{1}{t} \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1.0\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{fma}\left(\frac{z}{t}, y \cdot 1.0, \mathsf{fma}\left(0.5, \frac{\left(z \cdot z\right) \cdot y}{t}, \frac{\log 1.0}{t}\right)\right)\\ \end{array}\]

Reproduce

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

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

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