Average Error: 26.2 → 0.9
Time: 7.2s
Precision: binary64
\[\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 := x + \left(t + y\right)\\ t_2 := \frac{y}{t_1}\\ a \cdot \frac{t}{t_1} + \mathsf{fma}\left(z, t_2 + \frac{x}{t_1}, t_2 \cdot \left(a - b\right)\right) \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 (+ x (+ t y))) (t_2 (/ y t_1)))
   (+ (* a (/ t t_1)) (fma z (+ t_2 (/ x t_1)) (* t_2 (- a b))))))
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 = x + (t + y);
	double t_2 = y / t_1;
	return (a * (t / t_1)) + fma(z, (t_2 + (x / t_1)), (t_2 * (a - b)));
}
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(x + Float64(t + y))
	t_2 = Float64(y / t_1)
	return Float64(Float64(a * Float64(t / t_1)) + fma(z, Float64(t_2 + Float64(x / t_1)), Float64(t_2 * Float64(a - b))))
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[(x + N[(t + y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(y / t$95$1), $MachinePrecision]}, N[(N[(a * N[(t / t$95$1), $MachinePrecision]), $MachinePrecision] + N[(z * N[(t$95$2 + N[(x / t$95$1), $MachinePrecision]), $MachinePrecision] + N[(t$95$2 * N[(a - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\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 := x + \left(t + y\right)\\
t_2 := \frac{y}{t_1}\\
a \cdot \frac{t}{t_1} + \mathsf{fma}\left(z, t_2 + \frac{x}{t_1}, t_2 \cdot \left(a - b\right)\right)
\end{array}

Error

Target

Original26.2
Target11.8
Herbie0.9
\[\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. Initial program 26.2

    \[\frac{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y} \]
  2. Simplified26.2

    \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(t, a, \mathsf{fma}\left(y, \left(z + a\right) - b, x \cdot z\right)\right)}{x + \left(y + t\right)}} \]
  3. Taylor expanded in z around 0 18.4

    \[\leadsto \color{blue}{\left(\frac{x}{y + \left(t + x\right)} + \frac{y}{y + \left(t + x\right)}\right) \cdot z + \left(\frac{y \cdot \left(a - b\right)}{y + \left(t + x\right)} + \frac{a \cdot t}{y + \left(t + x\right)}\right)} \]
  4. Simplified0.9

    \[\leadsto \color{blue}{a \cdot \frac{t}{x + \left(y + t\right)} + \mathsf{fma}\left(z, \frac{y}{x + \left(y + t\right)} + \frac{x}{x + \left(y + t\right)}, \frac{y}{x + \left(y + t\right)} \cdot \left(a - b\right)\right)} \]
  5. Final simplification0.9

    \[\leadsto a \cdot \frac{t}{x + \left(t + y\right)} + \mathsf{fma}\left(z, \frac{y}{x + \left(t + y\right)} + \frac{x}{x + \left(t + y\right)}, \frac{y}{x + \left(t + y\right)} \cdot \left(a - b\right)\right) \]

Reproduce

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