Average Error: 24.9 → 8.3
Time: 20.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 -13944249.30924102:\\ \;\;\;\;x - \log \left(e^{z} \cdot y + \left(1.0 - y\right)\right) \cdot \frac{1}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \left(1.0 \cdot \left(\frac{z}{t} \cdot y\right) + \frac{\log 1.0}{t}\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 -13944249.30924102:\\
\;\;\;\;x - \log \left(e^{z} \cdot y + \left(1.0 - y\right)\right) \cdot \frac{1}{t}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r5933830 = x;
        double r5933831 = 1.0;
        double r5933832 = y;
        double r5933833 = r5933831 - r5933832;
        double r5933834 = z;
        double r5933835 = exp(r5933834);
        double r5933836 = r5933832 * r5933835;
        double r5933837 = r5933833 + r5933836;
        double r5933838 = log(r5933837);
        double r5933839 = t;
        double r5933840 = r5933838 / r5933839;
        double r5933841 = r5933830 - r5933840;
        return r5933841;
}

double f(double x, double y, double z, double t) {
        double r5933842 = z;
        double r5933843 = -13944249.30924102;
        bool r5933844 = r5933842 <= r5933843;
        double r5933845 = x;
        double r5933846 = exp(r5933842);
        double r5933847 = y;
        double r5933848 = r5933846 * r5933847;
        double r5933849 = 1.0;
        double r5933850 = r5933849 - r5933847;
        double r5933851 = r5933848 + r5933850;
        double r5933852 = log(r5933851);
        double r5933853 = 1.0;
        double r5933854 = t;
        double r5933855 = r5933853 / r5933854;
        double r5933856 = r5933852 * r5933855;
        double r5933857 = r5933845 - r5933856;
        double r5933858 = r5933842 / r5933854;
        double r5933859 = r5933858 * r5933847;
        double r5933860 = r5933849 * r5933859;
        double r5933861 = log(r5933849);
        double r5933862 = r5933861 / r5933854;
        double r5933863 = r5933860 + r5933862;
        double r5933864 = r5933845 - r5933863;
        double r5933865 = r5933844 ? r5933857 : r5933864;
        return r5933865;
}

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

Original24.9
Target16.5
Herbie8.3
\[\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 2 regimes
  2. if z < -13944249.30924102

    1. Initial program 12.5

      \[x - \frac{\log \left(\left(1.0 - y\right) + y \cdot e^{z}\right)}{t}\]
    2. Using strategy rm
    3. Applied div-inv12.5

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

    if -13944249.30924102 < z

    1. Initial program 29.9

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

      \[\leadsto \color{blue}{x - \left(1.0 \cdot \frac{z \cdot y}{t} + \frac{\log 1.0}{t}\right)}\]
    3. Using strategy rm
    4. Applied associate-/l*9.0

      \[\leadsto x - \left(1.0 \cdot \color{blue}{\frac{z}{\frac{t}{y}}} + \frac{\log 1.0}{t}\right)\]
    5. Using strategy rm
    6. Applied associate-/r/6.6

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

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

Reproduce

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