Average Error: 26.9 → 0.3
Time: 9.6s
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 := \frac{\left(\left(x + y\right) \cdot z + \left(y + t\right) \cdot a\right) - y \cdot b}{y + \left(x + t\right)}\\ t_2 := x + \left(y + t\right)\\ t_3 := \frac{y}{t_2}\\ t_4 := a \cdot \frac{t}{t_2} + \mathsf{fma}\left(z, t_3 + \frac{x}{t_2}, t_3 \cdot \left(a - b\right)\right)\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{-34}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;t_1 \leq 10^{-42}:\\ \;\;\;\;\frac{\mathsf{fma}\left(t, a, \mathsf{fma}\left(y, \left(z + a\right) - b, x \cdot z\right)\right)}{t_2}\\ \mathbf{else}:\\ \;\;\;\;t_4\\ \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 y) z) (* (+ y t) a)) (* y b)) (+ y (+ x t))))
        (t_2 (+ x (+ y t)))
        (t_3 (/ y t_2))
        (t_4 (+ (* a (/ t t_2)) (fma z (+ t_3 (/ x t_2)) (* t_3 (- a b))))))
   (if (<= t_1 -1e-34)
     t_4
     (if (<= t_1 1e-42) (/ (fma t a (fma y (- (+ z a) b) (* x z))) t_2) t_4))))
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 + y) * z) + ((y + t) * a)) - (y * b)) / (y + (x + t));
	double t_2 = x + (y + t);
	double t_3 = y / t_2;
	double t_4 = (a * (t / t_2)) + fma(z, (t_3 + (x / t_2)), (t_3 * (a - b)));
	double tmp;
	if (t_1 <= -1e-34) {
		tmp = t_4;
	} else if (t_1 <= 1e-42) {
		tmp = fma(t, a, fma(y, ((z + a) - b), (x * z))) / t_2;
	} else {
		tmp = t_4;
	}
	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(Float64(Float64(Float64(Float64(x + y) * z) + Float64(Float64(y + t) * a)) - Float64(y * b)) / Float64(y + Float64(x + t)))
	t_2 = Float64(x + Float64(y + t))
	t_3 = Float64(y / t_2)
	t_4 = Float64(Float64(a * Float64(t / t_2)) + fma(z, Float64(t_3 + Float64(x / t_2)), Float64(t_3 * Float64(a - b))))
	tmp = 0.0
	if (t_1 <= -1e-34)
		tmp = t_4;
	elseif (t_1 <= 1e-42)
		tmp = Float64(fma(t, a, fma(y, Float64(Float64(z + a) - b), Float64(x * z))) / t_2);
	else
		tmp = t_4;
	end
	return 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[(N[(N[(N[(N[(x + y), $MachinePrecision] * z), $MachinePrecision] + N[(N[(y + t), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] - N[(y * b), $MachinePrecision]), $MachinePrecision] / N[(y + N[(x + t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(x + N[(y + t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(y / t$95$2), $MachinePrecision]}, Block[{t$95$4 = N[(N[(a * N[(t / t$95$2), $MachinePrecision]), $MachinePrecision] + N[(z * N[(t$95$3 + N[(x / t$95$2), $MachinePrecision]), $MachinePrecision] + N[(t$95$3 * N[(a - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1e-34], t$95$4, If[LessEqual[t$95$1, 1e-42], N[(N[(t * a + N[(y * N[(N[(z + a), $MachinePrecision] - b), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / t$95$2), $MachinePrecision], t$95$4]]]]]]
\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 := \frac{\left(\left(x + y\right) \cdot z + \left(y + t\right) \cdot a\right) - y \cdot b}{y + \left(x + t\right)}\\
t_2 := x + \left(y + t\right)\\
t_3 := \frac{y}{t_2}\\
t_4 := a \cdot \frac{t}{t_2} + \mathsf{fma}\left(z, t_3 + \frac{x}{t_2}, t_3 \cdot \left(a - b\right)\right)\\
\mathbf{if}\;t_1 \leq -1 \cdot 10^{-34}:\\
\;\;\;\;t_4\\

\mathbf{elif}\;t_1 \leq 10^{-42}:\\
\;\;\;\;\frac{\mathsf{fma}\left(t, a, \mathsf{fma}\left(y, \left(z + a\right) - b, x \cdot z\right)\right)}{t_2}\\

\mathbf{else}:\\
\;\;\;\;t_4\\


\end{array}

Error

Target

Original26.9
Target11.5
Herbie0.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)) < -9.99999999999999928e-35 or 1.00000000000000004e-42 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y))

    1. Initial program 33.0

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

      \[\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 23.5

      \[\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.1

      \[\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)} \]

    if -9.99999999999999928e-35 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) < 1.00000000000000004e-42

    1. Initial program 0.8

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

      \[\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. Recombined 2 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(\left(x + y\right) \cdot z + \left(y + t\right) \cdot a\right) - y \cdot b}{y + \left(x + t\right)} \leq -1 \cdot 10^{-34}:\\ \;\;\;\;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)\\ \mathbf{elif}\;\frac{\left(\left(x + y\right) \cdot z + \left(y + t\right) \cdot a\right) - y \cdot b}{y + \left(x + t\right)} \leq 10^{-42}:\\ \;\;\;\;\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)}\\ \mathbf{else}:\\ \;\;\;\;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)\\ \end{array} \]

Reproduce

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