Average Error: 25.1 → 0.4
Time: 14.6s
Precision: binary64
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \]
\[\begin{array}{l} t_1 := x - \frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}\\ \mathbf{if}\;y \leq -2.139802579946953 \cdot 10^{-122}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.776953096329963 \cdot 10^{-34}:\\ \;\;\;\;x - y \cdot \frac{\mathsf{expm1}\left(z\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \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
 (let* ((t_1 (- x (/ (log1p (* y (expm1 z))) t))))
   (if (<= y -2.139802579946953e-122)
     t_1
     (if (<= y 1.776953096329963e-34) (- x (* y (/ (expm1 z) t))) t_1))))
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 t_1 = x - (log1p((y * expm1(z))) / t);
	double tmp;
	if (y <= -2.139802579946953e-122) {
		tmp = t_1;
	} else if (y <= 1.776953096329963e-34) {
		tmp = x - (y * (expm1(z) / t));
	} else {
		tmp = t_1;
	}
	return tmp;
}
public static double code(double x, double y, double z, double t) {
	return x - (Math.log(((1.0 - y) + (y * Math.exp(z)))) / t);
}
public static double code(double x, double y, double z, double t) {
	double t_1 = x - (Math.log1p((y * Math.expm1(z))) / t);
	double tmp;
	if (y <= -2.139802579946953e-122) {
		tmp = t_1;
	} else if (y <= 1.776953096329963e-34) {
		tmp = x - (y * (Math.expm1(z) / t));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z, t):
	return x - (math.log(((1.0 - y) + (y * math.exp(z)))) / t)
def code(x, y, z, t):
	t_1 = x - (math.log1p((y * math.expm1(z))) / t)
	tmp = 0
	if y <= -2.139802579946953e-122:
		tmp = t_1
	elif y <= 1.776953096329963e-34:
		tmp = x - (y * (math.expm1(z) / t))
	else:
		tmp = t_1
	return tmp
function code(x, y, z, t)
	return Float64(x - Float64(log(Float64(Float64(1.0 - y) + Float64(y * exp(z)))) / t))
end
function code(x, y, z, t)
	t_1 = Float64(x - Float64(log1p(Float64(y * expm1(z))) / t))
	tmp = 0.0
	if (y <= -2.139802579946953e-122)
		tmp = t_1;
	elseif (y <= 1.776953096329963e-34)
		tmp = Float64(x - Float64(y * Float64(expm1(z) / t)));
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_, t_] := N[(x - N[(N[Log[N[(N[(1.0 - y), $MachinePrecision] + N[(y * N[Exp[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x - N[(N[Log[1 + N[(y * N[(Exp[z] - 1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.139802579946953e-122], t$95$1, If[LessEqual[y, 1.776953096329963e-34], N[(x - N[(y * N[(N[(Exp[z] - 1), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
t_1 := x - \frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}\\
\mathbf{if}\;y \leq -2.139802579946953 \cdot 10^{-122}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y \leq 1.776953096329963 \cdot 10^{-34}:\\
\;\;\;\;x - y \cdot \frac{\mathsf{expm1}\left(z\right)}{t}\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

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.1
Target16.6
Herbie0.4
\[\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 y < -2.13980257994695287e-122 or 1.7769530963299629e-34 < y

    1. Initial program 37.2

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \]
    2. Simplified0.4

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

    if -2.13980257994695287e-122 < y < 1.7769530963299629e-34

    1. Initial program 10.7

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \]
    2. Simplified1.8

      \[\leadsto \color{blue}{x - \frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}} \]
    3. Applied egg-rr1.8

      \[\leadsto x - \color{blue}{{\left(\frac{t}{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}\right)}^{-1}} \]
    4. Taylor expanded in y around 0 5.2

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

      \[\leadsto x - \color{blue}{\frac{\mathsf{expm1}\left(z\right)}{\frac{t}{y}}} \]
    6. Applied egg-rr0.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.139802579946953 \cdot 10^{-122}:\\ \;\;\;\;x - \frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}\\ \mathbf{elif}\;y \leq 1.776953096329963 \cdot 10^{-34}:\\ \;\;\;\;x - y \cdot \frac{\mathsf{expm1}\left(z\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}\\ \end{array} \]

Reproduce

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