Average Error: 25.1 → 8.4
Time: 7.1s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -1.63783683020029204 \cdot 10^{-19}:\\ \;\;\;\;x - \frac{\log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{fma}\left(\frac{z \cdot y}{t}, 1, \mathsf{fma}\left(0.5, \frac{{z}^{2} \cdot y}{t}, \frac{\log 1}{t}\right)\right)\\ \end{array}\]
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
\mathbf{if}\;z \le -1.63783683020029204 \cdot 10^{-19}:\\
\;\;\;\;x - \frac{\log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right)}{t}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r284791 = x;
        double r284792 = 1.0;
        double r284793 = y;
        double r284794 = r284792 - r284793;
        double r284795 = z;
        double r284796 = exp(r284795);
        double r284797 = r284793 * r284796;
        double r284798 = r284794 + r284797;
        double r284799 = log(r284798);
        double r284800 = t;
        double r284801 = r284799 / r284800;
        double r284802 = r284791 - r284801;
        return r284802;
}

double f(double x, double y, double z, double t) {
        double r284803 = z;
        double r284804 = -1.637836830200292e-19;
        bool r284805 = r284803 <= r284804;
        double r284806 = x;
        double r284807 = 1.0;
        double r284808 = y;
        double r284809 = expm1(r284803);
        double r284810 = r284808 * r284809;
        double r284811 = r284807 + r284810;
        double r284812 = log(r284811);
        double r284813 = t;
        double r284814 = r284812 / r284813;
        double r284815 = r284806 - r284814;
        double r284816 = r284803 * r284808;
        double r284817 = r284816 / r284813;
        double r284818 = 0.5;
        double r284819 = 2.0;
        double r284820 = pow(r284803, r284819);
        double r284821 = r284820 * r284808;
        double r284822 = r284821 / r284813;
        double r284823 = log(r284807);
        double r284824 = r284823 / r284813;
        double r284825 = fma(r284818, r284822, r284824);
        double r284826 = fma(r284817, r284807, r284825);
        double r284827 = r284806 - r284826;
        double r284828 = r284805 ? r284815 : r284827;
        return r284828;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.1
Target16.3
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 z < -1.637836830200292e-19

    1. Initial program 11.6

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

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

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

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

    if -1.637836830200292e-19 < z

    1. Initial program 31.4

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

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

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

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

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

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

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

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

Reproduce

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