Average Error: 25.5 → 9.3
Time: 8.6s
Precision: 64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -3.61247754966531634 \cdot 10^{-6}:\\ \;\;\;\;x - \log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right) \cdot \frac{1}{t}\\ \mathbf{elif}\;z \le 3.44462763878247732 \cdot 10^{-225}:\\ \;\;\;\;x - \mathsf{fma}\left(0.5, {z}^{2} \cdot y, \mathsf{fma}\left(1, z \cdot y, \log 1\right)\right) \cdot \frac{1}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{1}{\frac{t}{\log \left(1 + y \cdot \mathsf{expm1}\left(z\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.61247754966531634 \cdot 10^{-6}:\\
\;\;\;\;x - \log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right) \cdot \frac{1}{t}\\

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

\mathbf{else}:\\
\;\;\;\;x - \frac{1}{\frac{t}{\log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right)}}\\

\end{array}
double f(double x, double y, double z, double t) {
        double r348934 = x;
        double r348935 = 1.0;
        double r348936 = y;
        double r348937 = r348935 - r348936;
        double r348938 = z;
        double r348939 = exp(r348938);
        double r348940 = r348936 * r348939;
        double r348941 = r348937 + r348940;
        double r348942 = log(r348941);
        double r348943 = t;
        double r348944 = r348942 / r348943;
        double r348945 = r348934 - r348944;
        return r348945;
}

double f(double x, double y, double z, double t) {
        double r348946 = z;
        double r348947 = -3.6124775496653163e-06;
        bool r348948 = r348946 <= r348947;
        double r348949 = x;
        double r348950 = 1.0;
        double r348951 = y;
        double r348952 = expm1(r348946);
        double r348953 = r348951 * r348952;
        double r348954 = r348950 + r348953;
        double r348955 = log(r348954);
        double r348956 = 1.0;
        double r348957 = t;
        double r348958 = r348956 / r348957;
        double r348959 = r348955 * r348958;
        double r348960 = r348949 - r348959;
        double r348961 = 3.4446276387824773e-225;
        bool r348962 = r348946 <= r348961;
        double r348963 = 0.5;
        double r348964 = 2.0;
        double r348965 = pow(r348946, r348964);
        double r348966 = r348965 * r348951;
        double r348967 = r348946 * r348951;
        double r348968 = log(r348950);
        double r348969 = fma(r348950, r348967, r348968);
        double r348970 = fma(r348963, r348966, r348969);
        double r348971 = r348970 * r348958;
        double r348972 = r348949 - r348971;
        double r348973 = r348957 / r348955;
        double r348974 = r348956 / r348973;
        double r348975 = r348949 - r348974;
        double r348976 = r348962 ? r348972 : r348975;
        double r348977 = r348948 ? r348960 : r348976;
        return r348977;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original25.5
Target16.5
Herbie9.3
\[\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 3 regimes
  2. if z < -3.6124775496653163e-06

    1. Initial program 11.9

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

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

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

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

    if -3.6124775496653163e-06 < z < 3.4446276387824773e-225

    1. Initial program 31.7

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

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

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

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

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

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

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

    if 3.4446276387824773e-225 < z

    1. Initial program 31.1

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

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

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

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

      \[\leadsto x - \color{blue}{\frac{1}{\frac{t}{\log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right)}}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification9.3

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

Reproduce

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