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

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

\mathbf{else}:\\
\;\;\;\;t_4 + \left(t_5 - b \cdot t_3\right)\\


\end{array}

Error

Target

Original26.8
Target11.0
Herbie0.7
\[\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 3 regimes
  2. if (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) < -5e5

    1. Initial program 32.9

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

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

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

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

      \[\leadsto a \cdot \left(\frac{y}{y + \left(t + x\right)} + \frac{t}{y + \left(t + x\right)}\right) + \color{blue}{\left(\frac{z}{\frac{y + \left(t + x\right)}{y + x}} - \frac{y}{y + \left(t + x\right)} \cdot b\right)} \]
    6. Applied egg-rr1.0

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

    if -5e5 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) < 4.99999999999999972e193

    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} \]
    2. Taylor expanded in a around 0 0.8

      \[\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. Simplified0.8

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

    if 4.99999999999999972e193 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y))

    1. Initial program 56.7

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

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

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

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

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

    \[\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 -500000:\\ \;\;\;\;a \cdot \left(\frac{y}{y + \left(x + t\right)} + \frac{t}{y + \left(x + t\right)}\right) + \left(\frac{z}{\frac{y + \left(x + t\right)}{x + y}} - \frac{y}{\frac{x + \left(y + t\right)}{b}}\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 5 \cdot 10^{+193}:\\ \;\;\;\;a \cdot \left(\frac{y}{y + \left(x + t\right)} + \frac{t}{y + \left(x + t\right)}\right) + \frac{\mathsf{fma}\left(z, x + y, y \cdot \left(-b\right)\right)}{y + \left(x + t\right)}\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(\frac{y}{y + \left(x + t\right)} + \frac{t}{y + \left(x + t\right)}\right) + \left(\frac{z}{\frac{y + \left(x + t\right)}{x + y}} - b \cdot \frac{y}{y + \left(x + t\right)}\right)\\ \end{array} \]

Reproduce

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