?

Average Error: 24.3 → 8.5
Time: 22.8s
Precision: binary64
Cost: 67280

?

\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \]
\[\begin{array}{l} t_1 := \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\\ t_2 := \left(e^{z} - 1\right) \cdot y\\ t_3 := x - \frac{\log \left(1 + t_2\right)}{t}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;x - \frac{\log \left(y \cdot z + 1\right)}{t}\\ \mathbf{elif}\;t_1 \leq -1 \cdot 10^{-186}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_1 \leq 0:\\ \;\;\;\;x - \frac{t_2}{t}\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+210}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;x - \frac{z}{t} \cdot y\\ \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 (/ (log (+ (- 1.0 y) (* y (exp z)))) t))
        (t_2 (* (- (exp z) 1.0) y))
        (t_3 (- x (/ (log (+ 1.0 t_2)) t))))
   (if (<= t_1 (- INFINITY))
     (- x (/ (log (+ (* y z) 1.0)) t))
     (if (<= t_1 -1e-186)
       t_3
       (if (<= t_1 0.0)
         (- x (/ t_2 t))
         (if (<= t_1 2e+210) t_3 (- x (* (/ z t) y))))))))
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 = log(((1.0 - y) + (y * exp(z)))) / t;
	double t_2 = (exp(z) - 1.0) * y;
	double t_3 = x - (log((1.0 + t_2)) / t);
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = x - (log(((y * z) + 1.0)) / t);
	} else if (t_1 <= -1e-186) {
		tmp = t_3;
	} else if (t_1 <= 0.0) {
		tmp = x - (t_2 / t);
	} else if (t_1 <= 2e+210) {
		tmp = t_3;
	} else {
		tmp = x - ((z / t) * y);
	}
	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.log(((1.0 - y) + (y * Math.exp(z)))) / t;
	double t_2 = (Math.exp(z) - 1.0) * y;
	double t_3 = x - (Math.log((1.0 + t_2)) / t);
	double tmp;
	if (t_1 <= -Double.POSITIVE_INFINITY) {
		tmp = x - (Math.log(((y * z) + 1.0)) / t);
	} else if (t_1 <= -1e-186) {
		tmp = t_3;
	} else if (t_1 <= 0.0) {
		tmp = x - (t_2 / t);
	} else if (t_1 <= 2e+210) {
		tmp = t_3;
	} else {
		tmp = x - ((z / t) * y);
	}
	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.log(((1.0 - y) + (y * math.exp(z)))) / t
	t_2 = (math.exp(z) - 1.0) * y
	t_3 = x - (math.log((1.0 + t_2)) / t)
	tmp = 0
	if t_1 <= -math.inf:
		tmp = x - (math.log(((y * z) + 1.0)) / t)
	elif t_1 <= -1e-186:
		tmp = t_3
	elif t_1 <= 0.0:
		tmp = x - (t_2 / t)
	elif t_1 <= 2e+210:
		tmp = t_3
	else:
		tmp = x - ((z / t) * y)
	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(log(Float64(Float64(1.0 - y) + Float64(y * exp(z)))) / t)
	t_2 = Float64(Float64(exp(z) - 1.0) * y)
	t_3 = Float64(x - Float64(log(Float64(1.0 + t_2)) / t))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(x - Float64(log(Float64(Float64(y * z) + 1.0)) / t));
	elseif (t_1 <= -1e-186)
		tmp = t_3;
	elseif (t_1 <= 0.0)
		tmp = Float64(x - Float64(t_2 / t));
	elseif (t_1 <= 2e+210)
		tmp = t_3;
	else
		tmp = Float64(x - Float64(Float64(z / t) * y));
	end
	return tmp
end
function tmp = code(x, y, z, t)
	tmp = x - (log(((1.0 - y) + (y * exp(z)))) / t);
end
function tmp_2 = code(x, y, z, t)
	t_1 = log(((1.0 - y) + (y * exp(z)))) / t;
	t_2 = (exp(z) - 1.0) * y;
	t_3 = x - (log((1.0 + t_2)) / t);
	tmp = 0.0;
	if (t_1 <= -Inf)
		tmp = x - (log(((y * z) + 1.0)) / t);
	elseif (t_1 <= -1e-186)
		tmp = t_3;
	elseif (t_1 <= 0.0)
		tmp = x - (t_2 / t);
	elseif (t_1 <= 2e+210)
		tmp = t_3;
	else
		tmp = x - ((z / t) * y);
	end
	tmp_2 = 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[(N[Log[N[(N[(1.0 - y), $MachinePrecision] + N[(y * N[Exp[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[Exp[z], $MachinePrecision] - 1.0), $MachinePrecision] * y), $MachinePrecision]}, Block[{t$95$3 = N[(x - N[(N[Log[N[(1.0 + t$95$2), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(x - N[(N[Log[N[(N[(y * z), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, -1e-186], t$95$3, If[LessEqual[t$95$1, 0.0], N[(x - N[(t$95$2 / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e+210], t$95$3, N[(x - N[(N[(z / t), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]]]]]]]]
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
t_1 := \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\\
t_2 := \left(e^{z} - 1\right) \cdot y\\
t_3 := x - \frac{\log \left(1 + t_2\right)}{t}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;x - \frac{\log \left(y \cdot z + 1\right)}{t}\\

\mathbf{elif}\;t_1 \leq -1 \cdot 10^{-186}:\\
\;\;\;\;t_3\\

\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;x - \frac{t_2}{t}\\

\mathbf{elif}\;t_1 \leq 2 \cdot 10^{+210}:\\
\;\;\;\;t_3\\

\mathbf{else}:\\
\;\;\;\;x - \frac{z}{t} \cdot y\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original24.3
Target16.5
Herbie8.5
\[\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 4 regimes
  2. if (/.f64 (log.f64 (+.f64 (-.f64 1 y) (*.f64 y (exp.f64 z)))) t) < -inf.0

    1. Initial program 64.0

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

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

    if -inf.0 < (/.f64 (log.f64 (+.f64 (-.f64 1 y) (*.f64 y (exp.f64 z)))) t) < -9.9999999999999991e-187 or 0.0 < (/.f64 (log.f64 (+.f64 (-.f64 1 y) (*.f64 y (exp.f64 z)))) t) < 1.99999999999999985e210

    1. Initial program 2.3

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

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

    if -9.9999999999999991e-187 < (/.f64 (log.f64 (+.f64 (-.f64 1 y) (*.f64 y (exp.f64 z)))) t) < 0.0

    1. Initial program 12.0

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

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

    if 1.99999999999999985e210 < (/.f64 (log.f64 (+.f64 (-.f64 1 y) (*.f64 y (exp.f64 z)))) t)

    1. Initial program 59.6

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

      \[\leadsto x - \frac{\color{blue}{\left(e^{z} - 1\right) \cdot y}}{t} \]
    3. Taylor expanded in z around 0 17.5

      \[\leadsto x - \color{blue}{\left(\frac{y \cdot z}{t} + 0.5 \cdot \frac{y \cdot {z}^{2}}{t}\right)} \]
    4. Taylor expanded in y around inf 17.8

      \[\leadsto x - \color{blue}{\left(0.5 \cdot \frac{{z}^{2}}{t} + \frac{z}{t}\right) \cdot y} \]
    5. Taylor expanded in z around 0 17.8

      \[\leadsto x - \color{blue}{\frac{z}{t}} \cdot y \]
  3. Recombined 4 regimes into one program.
  4. Final simplification8.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \leq -\infty:\\ \;\;\;\;x - \frac{\log \left(y \cdot z + 1\right)}{t}\\ \mathbf{elif}\;\frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \leq -1 \cdot 10^{-186}:\\ \;\;\;\;x - \frac{\log \left(1 + \left(e^{z} - 1\right) \cdot y\right)}{t}\\ \mathbf{elif}\;\frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \leq 0:\\ \;\;\;\;x - \frac{\left(e^{z} - 1\right) \cdot y}{t}\\ \mathbf{elif}\;\frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \leq 2 \cdot 10^{+210}:\\ \;\;\;\;x - \frac{\log \left(1 + \left(e^{z} - 1\right) \cdot y\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{z}{t} \cdot y\\ \end{array} \]

Alternatives

Alternative 1
Error9.0
Cost13508
\[\begin{array}{l} \mathbf{if}\;e^{z} \leq 0.99999998:\\ \;\;\;\;x - \frac{\left(e^{z} - 1\right) \cdot y}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{z}{t} \cdot y\\ \end{array} \]
Alternative 2
Error9.0
Cost13508
\[\begin{array}{l} \mathbf{if}\;e^{z} \leq 0.99999998:\\ \;\;\;\;x - \frac{e^{z} \cdot y - y}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{z}{t} \cdot y\\ \end{array} \]
Alternative 3
Error9.1
Cost7428
\[\begin{array}{l} \mathbf{if}\;z \leq -1.35 \cdot 10^{+14}:\\ \;\;\;\;x - \frac{\left(e^{z} - 1\right) \cdot y}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \left(0.5 \cdot \frac{{z}^{2}}{t} + \frac{z}{t}\right) \cdot y\\ \end{array} \]
Alternative 4
Error9.1
Cost7300
\[\begin{array}{l} \mathbf{if}\;z \leq -1.35 \cdot 10^{+14}:\\ \;\;\;\;x - \frac{\left(e^{z} - 1\right) \cdot y}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{0.5 \cdot {z}^{2} + z}{t} \cdot y\\ \end{array} \]
Alternative 5
Error18.6
Cost648
\[\begin{array}{l} \mathbf{if}\;x \leq -7.3 \cdot 10^{-199}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3 \cdot 10^{-274}:\\ \;\;\;\;-\frac{y \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error11.4
Cost580
\[\begin{array}{l} \mathbf{if}\;z \leq -2.4:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x - \frac{z}{t} \cdot y\\ \end{array} \]
Alternative 7
Error18.0
Cost64
\[x \]

Error

Reproduce?

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