Average Error: 26.4 → 8.3
Time: 11.2s
Precision: binary64
Cost: 4168
\[\frac{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y} \]
\[\begin{array}{l} t_1 := y + \left(x + t\right)\\ t_2 := \frac{\left(\left(x + y\right) \cdot z + a \cdot \left(y + t\right)\right) - y \cdot b}{t_1}\\ t_3 := z + a \cdot \left(\frac{y}{t_1} + \frac{t}{t_1}\right)\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_2 \leq 2 \cdot 10^{+206}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (/ (- (+ (* (+ x y) z) (* (+ t y) a)) (* y b)) (+ (+ x t) y)))
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (+ y (+ x t)))
        (t_2 (/ (- (+ (* (+ x y) z) (* a (+ y t))) (* y b)) t_1))
        (t_3 (+ z (* a (+ (/ y t_1) (/ t t_1))))))
   (if (<= t_2 (- INFINITY)) t_3 (if (<= t_2 2e+206) t_2 t_3))))
double code(double x, double y, double z, double t, double a, double b) {
	return ((((x + y) * z) + ((t + y) * a)) - (y * b)) / ((x + t) + y);
}
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = y + (x + t);
	double t_2 = ((((x + y) * z) + (a * (y + t))) - (y * b)) / t_1;
	double t_3 = z + (a * ((y / t_1) + (t / t_1)));
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = t_3;
	} else if (t_2 <= 2e+206) {
		tmp = t_2;
	} else {
		tmp = t_3;
	}
	return tmp;
}
public static double code(double x, double y, double z, double t, double a, double b) {
	return ((((x + y) * z) + ((t + y) * a)) - (y * b)) / ((x + t) + y);
}
public static double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = y + (x + t);
	double t_2 = ((((x + y) * z) + (a * (y + t))) - (y * b)) / t_1;
	double t_3 = z + (a * ((y / t_1) + (t / t_1)));
	double tmp;
	if (t_2 <= -Double.POSITIVE_INFINITY) {
		tmp = t_3;
	} else if (t_2 <= 2e+206) {
		tmp = t_2;
	} else {
		tmp = t_3;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	return ((((x + y) * z) + ((t + y) * a)) - (y * b)) / ((x + t) + y)
def code(x, y, z, t, a, b):
	t_1 = y + (x + t)
	t_2 = ((((x + y) * z) + (a * (y + t))) - (y * b)) / t_1
	t_3 = z + (a * ((y / t_1) + (t / t_1)))
	tmp = 0
	if t_2 <= -math.inf:
		tmp = t_3
	elif t_2 <= 2e+206:
		tmp = t_2
	else:
		tmp = t_3
	return tmp
function code(x, y, z, t, a, b)
	return Float64(Float64(Float64(Float64(Float64(x + y) * z) + Float64(Float64(t + y) * a)) - Float64(y * b)) / Float64(Float64(x + t) + y))
end
function code(x, y, z, t, a, b)
	t_1 = Float64(y + Float64(x + t))
	t_2 = Float64(Float64(Float64(Float64(Float64(x + y) * z) + Float64(a * Float64(y + t))) - Float64(y * b)) / t_1)
	t_3 = Float64(z + Float64(a * Float64(Float64(y / t_1) + Float64(t / t_1))))
	tmp = 0.0
	if (t_2 <= Float64(-Inf))
		tmp = t_3;
	elseif (t_2 <= 2e+206)
		tmp = t_2;
	else
		tmp = t_3;
	end
	return tmp
end
function tmp = code(x, y, z, t, a, b)
	tmp = ((((x + y) * z) + ((t + y) * a)) - (y * b)) / ((x + t) + y);
end
function tmp_2 = code(x, y, z, t, a, b)
	t_1 = y + (x + t);
	t_2 = ((((x + y) * z) + (a * (y + t))) - (y * b)) / t_1;
	t_3 = z + (a * ((y / t_1) + (t / t_1)));
	tmp = 0.0;
	if (t_2 <= -Inf)
		tmp = t_3;
	elseif (t_2 <= 2e+206)
		tmp = t_2;
	else
		tmp = t_3;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(N[(N[(x + y), $MachinePrecision] * z), $MachinePrecision] + N[(N[(t + y), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] - N[(y * b), $MachinePrecision]), $MachinePrecision] / N[(N[(x + t), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(y + N[(x + t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(N[(N[(x + y), $MachinePrecision] * z), $MachinePrecision] + N[(a * N[(y + t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(y * b), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(z + N[(a * N[(N[(y / t$95$1), $MachinePrecision] + N[(t / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], t$95$3, If[LessEqual[t$95$2, 2e+206], t$95$2, t$95$3]]]]]
\frac{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y}
\begin{array}{l}
t_1 := y + \left(x + t\right)\\
t_2 := \frac{\left(\left(x + y\right) \cdot z + a \cdot \left(y + t\right)\right) - y \cdot b}{t_1}\\
t_3 := z + a \cdot \left(\frac{y}{t_1} + \frac{t}{t_1}\right)\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;t_3\\

\mathbf{elif}\;t_2 \leq 2 \cdot 10^{+206}:\\
\;\;\;\;t_2\\

\mathbf{else}:\\
\;\;\;\;t_3\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original26.4
Target11.3
Herbie8.3
\[\begin{array}{l} \mathbf{if}\;\frac{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y} < -3.5813117084150564 \cdot 10^{+153}:\\ \;\;\;\;\left(z + a\right) - b\\ \mathbf{elif}\;\frac{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y} < 1.2285964308315609 \cdot 10^{+82}:\\ \;\;\;\;\frac{1}{\frac{\left(x + t\right) + y}{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) - y \cdot b}}\\ \mathbf{else}:\\ \;\;\;\;\left(z + a\right) - b\\ \end{array} \]

Derivation

  1. Split input into 2 regimes
  2. if (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) < -inf.0 or 2.0000000000000001e206 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y))

    1. Initial program 59.4

      \[\frac{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y} \]
    2. Taylor expanded in a around 0 41.5

      \[\leadsto \color{blue}{\left(\frac{\left(y + x\right) \cdot z}{y + \left(t + x\right)} + a \cdot \left(\frac{y}{y + \left(t + x\right)} + \frac{t}{y + \left(t + x\right)}\right)\right) - \frac{y \cdot b}{y + \left(t + x\right)}} \]
    3. Simplified41.5

      \[\leadsto \color{blue}{a \cdot \left(\frac{y}{y + \left(t + x\right)} + \frac{t}{y + \left(t + x\right)}\right) + \frac{z \cdot \left(y + x\right) - y \cdot b}{y + \left(t + x\right)}} \]
      Proof
      (+.f64 (*.f64 a (+.f64 (/.f64 y (+.f64 y (+.f64 t x))) (/.f64 t (+.f64 y (+.f64 t x))))) (/.f64 (-.f64 (*.f64 z (+.f64 y x)) (*.f64 y b)) (+.f64 y (+.f64 t x)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 a (+.f64 (/.f64 y (+.f64 y (+.f64 t x))) (/.f64 t (+.f64 y (+.f64 t x))))) (/.f64 (-.f64 (Rewrite<= *-commutative_binary64 (*.f64 (+.f64 y x) z)) (*.f64 y b)) (+.f64 y (+.f64 t x)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 a (+.f64 (/.f64 y (+.f64 y (+.f64 t x))) (/.f64 t (+.f64 y (+.f64 t x))))) (Rewrite=> div-sub_binary64 (-.f64 (/.f64 (*.f64 (+.f64 y x) z) (+.f64 y (+.f64 t x))) (/.f64 (*.f64 y b) (+.f64 y (+.f64 t x)))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate--l+_binary64 (-.f64 (+.f64 (*.f64 a (+.f64 (/.f64 y (+.f64 y (+.f64 t x))) (/.f64 t (+.f64 y (+.f64 t x))))) (/.f64 (*.f64 (+.f64 y x) z) (+.f64 y (+.f64 t x)))) (/.f64 (*.f64 y b) (+.f64 y (+.f64 t x))))): 0 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= +-commutative_binary64 (+.f64 (/.f64 (*.f64 (+.f64 y x) z) (+.f64 y (+.f64 t x))) (*.f64 a (+.f64 (/.f64 y (+.f64 y (+.f64 t x))) (/.f64 t (+.f64 y (+.f64 t x))))))) (/.f64 (*.f64 y b) (+.f64 y (+.f64 t x)))): 0 points increase in error, 0 points decrease in error
    4. Taylor expanded in x around inf 18.4

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

    if -inf.0 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) < 2.0000000000000001e206

    1. Initial program 0.4

      \[\frac{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification8.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(\left(x + y\right) \cdot z + a \cdot \left(y + t\right)\right) - y \cdot b}{y + \left(x + t\right)} \leq -\infty:\\ \;\;\;\;z + a \cdot \left(\frac{y}{y + \left(x + t\right)} + \frac{t}{y + \left(x + t\right)}\right)\\ \mathbf{elif}\;\frac{\left(\left(x + y\right) \cdot z + a \cdot \left(y + t\right)\right) - y \cdot b}{y + \left(x + t\right)} \leq 2 \cdot 10^{+206}:\\ \;\;\;\;\frac{\left(\left(x + y\right) \cdot z + a \cdot \left(y + t\right)\right) - y \cdot b}{y + \left(x + t\right)}\\ \mathbf{else}:\\ \;\;\;\;z + a \cdot \left(\frac{y}{y + \left(x + t\right)} + \frac{t}{y + \left(x + t\right)}\right)\\ \end{array} \]

Alternatives

Alternative 1
Error22.5
Cost1744
\[\begin{array}{l} t_1 := y + \left(x + t\right)\\ t_2 := z + a \cdot \left(\frac{y}{t_1} + \frac{t}{t_1}\right)\\ \mathbf{if}\;b \leq -5.6 \cdot 10^{+284}:\\ \;\;\;\;b \cdot \frac{-y}{t_1}\\ \mathbf{elif}\;b \leq 9 \cdot 10^{+139}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq 3.95 \cdot 10^{+195}:\\ \;\;\;\;\frac{a \cdot \left(y + t\right) + y \cdot \left(z - b\right)}{y + t}\\ \mathbf{elif}\;b \leq 4.1 \cdot 10^{+265}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\frac{-y}{\frac{y + t}{b}}\\ \end{array} \]
Alternative 2
Error24.2
Cost1236
\[\begin{array}{l} t_1 := z + \frac{t}{\frac{x + t}{a}}\\ t_2 := a + \frac{z - b}{\frac{t}{y}}\\ t_3 := \left(z + a\right) - b\\ \mathbf{if}\;t \leq -1.85 \cdot 10^{+222}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -7.4 \cdot 10^{-90}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 2.65 \cdot 10^{-111}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 6.5 \cdot 10^{+58}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 6.2 \cdot 10^{+109}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error24.9
Cost1236
\[\begin{array}{l} t_1 := a + \frac{z - b}{\frac{t}{y}}\\ \mathbf{if}\;t \leq -1.36 \cdot 10^{+222}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -5.9 \cdot 10^{+144}:\\ \;\;\;\;z + \frac{t}{\frac{x + t}{a}}\\ \mathbf{elif}\;t \leq -3.6 \cdot 10^{+122}:\\ \;\;\;\;a\\ \mathbf{elif}\;t \leq -3.8 \cdot 10^{-276}:\\ \;\;\;\;z + \frac{y}{\frac{x + y}{a}}\\ \mathbf{elif}\;t \leq 10^{+110}:\\ \;\;\;\;\left(z + a\right) - b\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error26.1
Cost1112
\[\begin{array}{l} t_1 := \left(z + a\right) - b\\ \mathbf{if}\;y \leq -1 \cdot 10^{+48}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3.1 \cdot 10^{-300}:\\ \;\;\;\;z + a\\ \mathbf{elif}\;y \leq 1.7 \cdot 10^{-250}:\\ \;\;\;\;z + \frac{t}{\frac{x}{a}}\\ \mathbf{elif}\;y \leq 4.3 \cdot 10^{+15}:\\ \;\;\;\;z + a\\ \mathbf{elif}\;y \leq 1.46 \cdot 10^{+79}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.8 \cdot 10^{+155}:\\ \;\;\;\;z + a\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error26.1
Cost848
\[\begin{array}{l} t_1 := \left(z + a\right) - b\\ \mathbf{if}\;y \leq -2.8 \cdot 10^{+48}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4.25 \cdot 10^{+15}:\\ \;\;\;\;z + a\\ \mathbf{elif}\;y \leq 6.5 \cdot 10^{+80}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3 \cdot 10^{+155}:\\ \;\;\;\;z + a\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error35.7
Cost592
\[\begin{array}{l} \mathbf{if}\;z \leq -1.45 \cdot 10^{-6}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq -2 \cdot 10^{-244}:\\ \;\;\;\;a\\ \mathbf{elif}\;z \leq -4.8 \cdot 10^{-272}:\\ \;\;\;\;-b\\ \mathbf{elif}\;z \leq 2.35 \cdot 10^{+82}:\\ \;\;\;\;a\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 7
Error31.2
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -2 \cdot 10^{-244}:\\ \;\;\;\;z + a\\ \mathbf{elif}\;z \leq -5.2 \cdot 10^{-272}:\\ \;\;\;\;-b\\ \mathbf{else}:\\ \;\;\;\;z + a\\ \end{array} \]
Alternative 8
Error35.4
Cost328
\[\begin{array}{l} \mathbf{if}\;z \leq -0.00195:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 4.7 \cdot 10^{+82}:\\ \;\;\;\;a\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 9
Error43.1
Cost64
\[a \]

Error

Reproduce

herbie shell --seed 2022332 
(FPCore (x y z t a b)
  :name "AI.Clustering.Hierarchical.Internal:ward from clustering-0.2.1"
  :precision binary64

  :herbie-target
  (if (< (/ (- (+ (* (+ x y) z) (* (+ t y) a)) (* y b)) (+ (+ x t) y)) -3.5813117084150564e+153) (- (+ z a) b) (if (< (/ (- (+ (* (+ x y) z) (* (+ t y) a)) (* y b)) (+ (+ x t) y)) 1.2285964308315609e+82) (/ 1.0 (/ (+ (+ x t) y) (- (+ (* (+ x y) z) (* (+ t y) a)) (* y b)))) (- (+ z a) b)))

  (/ (- (+ (* (+ x y) z) (* (+ t y) a)) (* y b)) (+ (+ x t) y)))