Average Error: 25.3 → 8.8
Time: 21.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.2941783122131654 \cdot 10^{-7}:\\ \;\;\;\;x - \frac{\log \left(1 + \left(y \cdot e^{z} - y\right)\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{y \cdot \left(0.5 \cdot {z}^{2} + 1 \cdot z\right) + \log 1}{t}\\ \end{array}\]
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
\mathbf{if}\;z \le -3.2941783122131654 \cdot 10^{-7}:\\
\;\;\;\;x - \frac{\log \left(1 + \left(y \cdot e^{z} - y\right)\right)}{t}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r256875 = x;
        double r256876 = 1.0;
        double r256877 = y;
        double r256878 = r256876 - r256877;
        double r256879 = z;
        double r256880 = exp(r256879);
        double r256881 = r256877 * r256880;
        double r256882 = r256878 + r256881;
        double r256883 = log(r256882);
        double r256884 = t;
        double r256885 = r256883 / r256884;
        double r256886 = r256875 - r256885;
        return r256886;
}

double f(double x, double y, double z, double t) {
        double r256887 = z;
        double r256888 = -3.2941783122131654e-07;
        bool r256889 = r256887 <= r256888;
        double r256890 = x;
        double r256891 = 1.0;
        double r256892 = y;
        double r256893 = exp(r256887);
        double r256894 = r256892 * r256893;
        double r256895 = r256894 - r256892;
        double r256896 = r256891 + r256895;
        double r256897 = log(r256896);
        double r256898 = t;
        double r256899 = r256897 / r256898;
        double r256900 = r256890 - r256899;
        double r256901 = 0.5;
        double r256902 = 2.0;
        double r256903 = pow(r256887, r256902);
        double r256904 = r256901 * r256903;
        double r256905 = r256891 * r256887;
        double r256906 = r256904 + r256905;
        double r256907 = r256892 * r256906;
        double r256908 = log(r256891);
        double r256909 = r256907 + r256908;
        double r256910 = r256909 / r256898;
        double r256911 = r256890 - r256910;
        double r256912 = r256889 ? r256900 : r256911;
        return r256912;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original25.3
Target16.6
Herbie8.8
\[\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.2941783122131654e-07

    1. Initial program 11.8

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

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

      \[\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}{\left(y \cdot e^{z} - y\right)}\right)}{t}\]

    if -3.2941783122131654e-07 < z

    1. Initial program 31.2

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Taylor expanded around 0 7.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -3.2941783122131654 \cdot 10^{-7}:\\ \;\;\;\;x - \frac{\log \left(1 + \left(y \cdot e^{z} - y\right)\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{y \cdot \left(0.5 \cdot {z}^{2} + 1 \cdot z\right) + \log 1}{t}\\ \end{array}\]

Reproduce

herbie shell --seed 2019198 
(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)))