Average Error: 25.8 → 10.1
Time: 7.1s
Precision: binary64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \leq -2.9637753977712162 \cdot 10^{-58}:\\ \;\;\;\;x - \frac{\log \left(1 + \left(y \cdot e^{z} - y\right)\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{z \cdot y + \left(0.5 \cdot \left(y \cdot \left(z \cdot z\right)\right)\right) \cdot \left(1 - y\right)}{t}\\ \end{array}\]
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
\mathbf{if}\;z \leq -2.9637753977712162 \cdot 10^{-58}:\\
\;\;\;\;x - \frac{\log \left(1 + \left(y \cdot e^{z} - y\right)\right)}{t}\\

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

\end{array}
(FPCore (x y z t)
 :precision binary64
 (- x (/ (log (+ (- 1.0 y) (* y (exp z)))) t)))
(FPCore (x y z t)
 :precision binary64
 (if (<= z -2.9637753977712162e-58)
   (- x (/ (log (+ 1.0 (- (* y (exp z)) y))) t))
   (- x (/ (+ (* z y) (* (* 0.5 (* y (* z z))) (- 1.0 y))) t))))
double code(double x, double y, double z, double t) {
	return x - (log((1.0 - y) + (y * exp(z))) / t);
}
double code(double x, double y, double z, double t) {
	double tmp;
	if (z <= -2.9637753977712162e-58) {
		tmp = x - (log(1.0 + ((y * exp(z)) - y)) / t);
	} else {
		tmp = x - (((z * y) + ((0.5 * (y * (z * z))) * (1.0 - y))) / t);
	}
	return tmp;
}

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.8
Target16.6
Herbie10.1
\[\begin{array}{l} \mathbf{if}\;z < -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}{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 < -2.96377539777121624e-58

    1. Initial program 14.7

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

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

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

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

    if -2.96377539777121624e-58 < z

    1. Initial program 32.1

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

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

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

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

Reproduce

herbie shell --seed 2020220 
(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.0 z) (* z z)))) (- x (/ (log (+ 1.0 (* z y))) t)))

  (- x (/ (log (+ (- 1.0 y) (* y (exp z)))) t)))