Average Error: 25.4 → 9.1
Time: 9.1s
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}:\\ \;\;\;\;x - \frac{1}{\frac{t}{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}}\\ \mathbf{elif}\;z \le 1.5428240745310809 \cdot 10^{-172}:\\ \;\;\;\;x - \left(\log 1 + y \cdot \left(0.5 \cdot {z}^{2} + 1 \cdot z\right)\right) \cdot \frac{1}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\log \left(1 + y \cdot \left(\frac{1}{2} \cdot {z}^{2} + z\right)\right)}{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.01636886352055915 \cdot 10^{-9}:\\
\;\;\;\;x - \frac{1}{\frac{t}{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}}\\

\mathbf{elif}\;z \le 1.5428240745310809 \cdot 10^{-172}:\\
\;\;\;\;x - \left(\log 1 + y \cdot \left(0.5 \cdot {z}^{2} + 1 \cdot z\right)\right) \cdot \frac{1}{t}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r330029 = x;
        double r330030 = 1.0;
        double r330031 = y;
        double r330032 = r330030 - r330031;
        double r330033 = z;
        double r330034 = exp(r330033);
        double r330035 = r330031 * r330034;
        double r330036 = r330032 + r330035;
        double r330037 = log(r330036);
        double r330038 = t;
        double r330039 = r330037 / r330038;
        double r330040 = r330029 - r330039;
        return r330040;
}

double f(double x, double y, double z, double t) {
        double r330041 = z;
        double r330042 = -3.016368863520559e-09;
        bool r330043 = r330041 <= r330042;
        double r330044 = x;
        double r330045 = 1.0;
        double r330046 = t;
        double r330047 = 1.0;
        double r330048 = y;
        double r330049 = r330047 - r330048;
        double r330050 = exp(r330041);
        double r330051 = r330048 * r330050;
        double r330052 = r330049 + r330051;
        double r330053 = log(r330052);
        double r330054 = r330046 / r330053;
        double r330055 = r330045 / r330054;
        double r330056 = r330044 - r330055;
        double r330057 = 1.542824074531081e-172;
        bool r330058 = r330041 <= r330057;
        double r330059 = log(r330047);
        double r330060 = 0.5;
        double r330061 = 2.0;
        double r330062 = pow(r330041, r330061);
        double r330063 = r330060 * r330062;
        double r330064 = r330047 * r330041;
        double r330065 = r330063 + r330064;
        double r330066 = r330048 * r330065;
        double r330067 = r330059 + r330066;
        double r330068 = r330045 / r330046;
        double r330069 = r330067 * r330068;
        double r330070 = r330044 - r330069;
        double r330071 = 0.5;
        double r330072 = r330071 * r330062;
        double r330073 = r330072 + r330041;
        double r330074 = r330048 * r330073;
        double r330075 = r330047 + r330074;
        double r330076 = log(r330075);
        double r330077 = r330076 / r330046;
        double r330078 = r330044 - r330077;
        double r330079 = r330058 ? r330070 : r330078;
        double r330080 = r330043 ? r330056 : r330079;
        return r330080;
}

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.4
Target16.5
Herbie9.1
\[\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.016368863520559e-09

    1. Initial program 11.7

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

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

    if -3.016368863520559e-09 < z < 1.542824074531081e-172

    1. Initial program 31.0

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

      \[\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. Simplified5.8

      \[\leadsto x - \frac{\color{blue}{\log 1 + y \cdot \left(0.5 \cdot {z}^{2} + 1 \cdot z\right)}}{t}\]
    4. Using strategy rm
    5. Applied div-inv5.8

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

    if 1.542824074531081e-172 < z

    1. Initial program 32.9

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

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

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

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

Reproduce

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