Average Error: 25.4 → 9.2
Time: 8.8s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -3.01636886352055915 \cdot 10^{-9} \lor \neg \left(z \le 1.5428240745310809 \cdot 10^{-172} \lor \neg \left(z \le 6.2911074889713222 \cdot 10^{-55}\right)\right):\\ \;\;\;\;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 -3.01636886352055915 \cdot 10^{-9} \lor \neg \left(z \le 1.5428240745310809 \cdot 10^{-172} \lor \neg \left(z \le 6.2911074889713222 \cdot 10^{-55}\right)\right):\\
\;\;\;\;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 r231023 = x;
        double r231024 = 1.0;
        double r231025 = y;
        double r231026 = r231024 - r231025;
        double r231027 = z;
        double r231028 = exp(r231027);
        double r231029 = r231025 * r231028;
        double r231030 = r231026 + r231029;
        double r231031 = log(r231030);
        double r231032 = t;
        double r231033 = r231031 / r231032;
        double r231034 = r231023 - r231033;
        return r231034;
}

double f(double x, double y, double z, double t) {
        double r231035 = z;
        double r231036 = -3.016368863520559e-09;
        bool r231037 = r231035 <= r231036;
        double r231038 = 1.542824074531081e-172;
        bool r231039 = r231035 <= r231038;
        double r231040 = 6.291107488971322e-55;
        bool r231041 = r231035 <= r231040;
        double r231042 = !r231041;
        bool r231043 = r231039 || r231042;
        double r231044 = !r231043;
        bool r231045 = r231037 || r231044;
        double r231046 = x;
        double r231047 = 1.0;
        double r231048 = y;
        double r231049 = expm1(r231035);
        double r231050 = r231048 * r231049;
        double r231051 = r231047 + r231050;
        double r231052 = log(r231051);
        double r231053 = t;
        double r231054 = r231052 / r231053;
        double r231055 = r231046 - r231054;
        double r231056 = r231035 * r231048;
        double r231057 = r231056 / r231053;
        double r231058 = 0.5;
        double r231059 = 2.0;
        double r231060 = pow(r231035, r231059);
        double r231061 = r231060 * r231048;
        double r231062 = r231061 / r231053;
        double r231063 = log(r231047);
        double r231064 = r231063 / r231053;
        double r231065 = fma(r231058, r231062, r231064);
        double r231066 = fma(r231057, r231047, r231065);
        double r231067 = r231046 - r231066;
        double r231068 = r231045 ? r231055 : r231067;
        return r231068;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.4
Target16.5
Herbie9.2
\[\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 < -3.016368863520559e-09 or 1.542824074531081e-172 < z < 6.291107488971322e-55

    1. Initial program 18.4

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

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

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

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

    if -3.016368863520559e-09 < z < 1.542824074531081e-172 or 6.291107488971322e-55 < z

    1. Initial program 30.9

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

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

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

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

      \[\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)}\]
    7. Simplified6.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -3.01636886352055915 \cdot 10^{-9} \lor \neg \left(z \le 1.5428240745310809 \cdot 10^{-172} \lor \neg \left(z \le 6.2911074889713222 \cdot 10^{-55}\right)\right):\\ \;\;\;\;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 2020089 +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)))