Average Error: 25.1 → 0.6
Time: 17.2s
Precision: binary64
Cost: 13512
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \]
\[\begin{array}{l} t_1 := \mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)\\ \mathbf{if}\;y \leq -5 \cdot 10^{-34}:\\ \;\;\;\;x + t_1 \cdot \frac{-1}{t}\\ \mathbf{elif}\;y \leq 4 \cdot 10^{-212}:\\ \;\;\;\;x - \mathsf{expm1}\left(z\right) \cdot \frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{t_1}{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
 (let* ((t_1 (log1p (* y (expm1 z)))))
   (if (<= y -5e-34)
     (+ x (* t_1 (/ -1.0 t)))
     (if (<= y 4e-212) (- x (* (expm1 z) (/ y t))) (- x (/ t_1 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 t_1 = log1p((y * expm1(z)));
	double tmp;
	if (y <= -5e-34) {
		tmp = x + (t_1 * (-1.0 / t));
	} else if (y <= 4e-212) {
		tmp = x - (expm1(z) * (y / t));
	} else {
		tmp = x - (t_1 / t);
	}
	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 = Math.log1p((y * Math.expm1(z)));
	double tmp;
	if (y <= -5e-34) {
		tmp = x + (t_1 * (-1.0 / t));
	} else if (y <= 4e-212) {
		tmp = x - (Math.expm1(z) * (y / t));
	} else {
		tmp = x - (t_1 / t);
	}
	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 = math.log1p((y * math.expm1(z)))
	tmp = 0
	if y <= -5e-34:
		tmp = x + (t_1 * (-1.0 / t))
	elif y <= 4e-212:
		tmp = x - (math.expm1(z) * (y / t))
	else:
		tmp = x - (t_1 / t)
	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 = log1p(Float64(y * expm1(z)))
	tmp = 0.0
	if (y <= -5e-34)
		tmp = Float64(x + Float64(t_1 * Float64(-1.0 / t)));
	elseif (y <= 4e-212)
		tmp = Float64(x - Float64(expm1(z) * Float64(y / t)));
	else
		tmp = Float64(x - Float64(t_1 / t));
	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[Log[1 + N[(y * N[(Exp[z] - 1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[y, -5e-34], N[(x + N[(t$95$1 * N[(-1.0 / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4e-212], N[(x - N[(N[(Exp[z] - 1), $MachinePrecision] * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(t$95$1 / t), $MachinePrecision]), $MachinePrecision]]]]
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
t_1 := \mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)\\
\mathbf{if}\;y \leq -5 \cdot 10^{-34}:\\
\;\;\;\;x + t_1 \cdot \frac{-1}{t}\\

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

\mathbf{else}:\\
\;\;\;\;x - \frac{t_1}{t}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original25.1
Target16.6
Herbie0.6
\[\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 3 regimes
  2. if y < -5.0000000000000003e-34

    1. Initial program 33.8

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

      \[\leadsto \color{blue}{x - \frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}} \]
      Proof
      (-.f64 x (/.f64 (log1p.f64 (*.f64 y (expm1.f64 z))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (*.f64 y (Rewrite<= expm1-def_binary64 (-.f64 (exp.f64 z) 1)))) t)): 37 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (*.f64 y (Rewrite=> sub-neg_binary64 (+.f64 (exp.f64 z) (neg.f64 1))))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (*.f64 y (+.f64 (exp.f64 z) (Rewrite=> metadata-eval -1)))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (*.f64 y (Rewrite<= +-commutative_binary64 (+.f64 -1 (exp.f64 z))))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (Rewrite<= distribute-lft-out_binary64 (+.f64 (*.f64 y -1) (*.f64 y (exp.f64 z))))) t)): 2 points increase in error, 1 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 -1 y)) (*.f64 y (exp.f64 z)))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (+.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 y)) (*.f64 y (exp.f64 z)))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (+.f64 (Rewrite=> neg-sub0_binary64 (-.f64 0 y)) (*.f64 y (exp.f64 z)))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (Rewrite=> associate-+l-_binary64 (-.f64 0 (-.f64 y (*.f64 y (exp.f64 z)))))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (Rewrite<= neg-sub0_binary64 (neg.f64 (-.f64 y (*.f64 y (exp.f64 z)))))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (Rewrite<= log1p-def_binary64 (log.f64 (+.f64 1 (neg.f64 (-.f64 y (*.f64 y (exp.f64 z))))))) t)): 21 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log.f64 (Rewrite<= sub-neg_binary64 (-.f64 1 (-.f64 y (*.f64 y (exp.f64 z)))))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log.f64 (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 1 y) (*.f64 y (exp.f64 z))))) t)): 57 points increase in error, 0 points decrease in error
    3. Applied egg-rr0.2

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

    if -5.0000000000000003e-34 < y < 3.99999999999999982e-212

    1. Initial program 9.6

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

      \[\leadsto \color{blue}{x - \frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}} \]
      Proof
      (-.f64 x (/.f64 (log1p.f64 (*.f64 y (expm1.f64 z))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (*.f64 y (Rewrite<= expm1-def_binary64 (-.f64 (exp.f64 z) 1)))) t)): 37 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (*.f64 y (Rewrite=> sub-neg_binary64 (+.f64 (exp.f64 z) (neg.f64 1))))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (*.f64 y (+.f64 (exp.f64 z) (Rewrite=> metadata-eval -1)))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (*.f64 y (Rewrite<= +-commutative_binary64 (+.f64 -1 (exp.f64 z))))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (Rewrite<= distribute-lft-out_binary64 (+.f64 (*.f64 y -1) (*.f64 y (exp.f64 z))))) t)): 2 points increase in error, 1 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 -1 y)) (*.f64 y (exp.f64 z)))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (+.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 y)) (*.f64 y (exp.f64 z)))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (+.f64 (Rewrite=> neg-sub0_binary64 (-.f64 0 y)) (*.f64 y (exp.f64 z)))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (Rewrite=> associate-+l-_binary64 (-.f64 0 (-.f64 y (*.f64 y (exp.f64 z)))))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (Rewrite<= neg-sub0_binary64 (neg.f64 (-.f64 y (*.f64 y (exp.f64 z)))))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (Rewrite<= log1p-def_binary64 (log.f64 (+.f64 1 (neg.f64 (-.f64 y (*.f64 y (exp.f64 z))))))) t)): 21 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log.f64 (Rewrite<= sub-neg_binary64 (-.f64 1 (-.f64 y (*.f64 y (exp.f64 z)))))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log.f64 (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 1 y) (*.f64 y (exp.f64 z))))) t)): 57 points increase in error, 0 points decrease in error
    3. Taylor expanded in y around 0 4.5

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

      \[\leadsto x - \color{blue}{\frac{\mathsf{expm1}\left(z\right)}{\frac{t}{y}}} \]
      Proof
      (/.f64 (expm1.f64 z) (/.f64 t y)): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= expm1-def_binary64 (-.f64 (exp.f64 z) 1)) (/.f64 t y)): 39 points increase in error, 73 points decrease in error
      (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 (-.f64 (exp.f64 z) 1) y) t)): 13 points increase in error, 23 points decrease in error
    5. Applied egg-rr0.0

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

    if 3.99999999999999982e-212 < y

    1. Initial program 33.9

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

      \[\leadsto \color{blue}{x - \frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}} \]
      Proof
      (-.f64 x (/.f64 (log1p.f64 (*.f64 y (expm1.f64 z))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (*.f64 y (Rewrite<= expm1-def_binary64 (-.f64 (exp.f64 z) 1)))) t)): 37 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (*.f64 y (Rewrite=> sub-neg_binary64 (+.f64 (exp.f64 z) (neg.f64 1))))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (*.f64 y (+.f64 (exp.f64 z) (Rewrite=> metadata-eval -1)))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (*.f64 y (Rewrite<= +-commutative_binary64 (+.f64 -1 (exp.f64 z))))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (Rewrite<= distribute-lft-out_binary64 (+.f64 (*.f64 y -1) (*.f64 y (exp.f64 z))))) t)): 2 points increase in error, 1 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 -1 y)) (*.f64 y (exp.f64 z)))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (+.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 y)) (*.f64 y (exp.f64 z)))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (+.f64 (Rewrite=> neg-sub0_binary64 (-.f64 0 y)) (*.f64 y (exp.f64 z)))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (Rewrite=> associate-+l-_binary64 (-.f64 0 (-.f64 y (*.f64 y (exp.f64 z)))))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (Rewrite<= neg-sub0_binary64 (neg.f64 (-.f64 y (*.f64 y (exp.f64 z)))))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (Rewrite<= log1p-def_binary64 (log.f64 (+.f64 1 (neg.f64 (-.f64 y (*.f64 y (exp.f64 z))))))) t)): 21 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log.f64 (Rewrite<= sub-neg_binary64 (-.f64 1 (-.f64 y (*.f64 y (exp.f64 z)))))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log.f64 (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 1 y) (*.f64 y (exp.f64 z))))) t)): 57 points increase in error, 0 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification0.6

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

Alternatives

Alternative 1
Error0.6
Cost13512
\[\begin{array}{l} t_1 := x - \frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}\\ \mathbf{if}\;y \leq -1.36 \cdot 10^{-14}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4.2 \cdot 10^{-212}:\\ \;\;\;\;x - \mathsf{expm1}\left(z\right) \cdot \frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error11.1
Cost6980
\[\begin{array}{l} \mathbf{if}\;x \leq 4.5 \cdot 10^{-14}:\\ \;\;\;\;x - \mathsf{expm1}\left(z\right) \cdot \frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error9.6
Cost6980
\[\begin{array}{l} \mathbf{if}\;x \leq 4.5 \cdot 10^{-14}:\\ \;\;\;\;x - y \cdot \frac{\mathsf{expm1}\left(z\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error11.5
Cost1092
\[\begin{array}{l} \mathbf{if}\;z \leq -20000:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(z \cdot \left(\frac{z}{t} \cdot -0.5\right) - \frac{z}{t}\right)\\ \end{array} \]
Alternative 5
Error13.8
Cost580
\[\begin{array}{l} \mathbf{if}\;z \leq -2.05 \cdot 10^{+44}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x - z \cdot \frac{y}{t}\\ \end{array} \]
Alternative 6
Error11.7
Cost580
\[\begin{array}{l} \mathbf{if}\;z \leq -1.32 \cdot 10^{+44}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x - \frac{y}{\frac{t}{z}}\\ \end{array} \]
Alternative 7
Error18.4
Cost64
\[x \]

Error

Reproduce

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