Average Error: 26.9 → 6.1
Time: 38.5s
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 := \left(y + t\right) \cdot a\\ t_2 := \frac{\left(\left(x + y\right) \cdot z + t_1\right) - y \cdot b}{y + \left(x + t\right)}\\ t_3 := x + \left(y + t\right)\\ t_4 := \frac{y}{t_3}\\ t_5 := b \cdot t_4\\ t_6 := \mathsf{fma}\left(1, z + a, -t_5\right)\\ t_7 := -t_4\\ \mathbf{if}\;t_2 \leq -1.8770167269899472 \cdot 10^{+236}:\\ \;\;\;\;t_6 + \mathsf{fma}\left(y \cdot \frac{-1}{t_3}, b, t_5\right)\\ \mathbf{elif}\;t_2 \leq 8.371234403385252 \cdot 10^{+216}:\\ \;\;\;\;\mathsf{fma}\left(1, \frac{\mathsf{fma}\left(x + y, z, t_1\right)}{t_3}, -\frac{b}{\frac{t_3}{y}}\right) + \mathsf{fma}\left(t_7, b, t_5\right)\\ \mathbf{else}:\\ \;\;\;\;t_6 + \mathsf{fma}\left(t_7, b, \frac{1}{\frac{1}{t_5}}\right)\\ \end{array} \]
\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 := \left(y + t\right) \cdot a\\
t_2 := \frac{\left(\left(x + y\right) \cdot z + t_1\right) - y \cdot b}{y + \left(x + t\right)}\\
t_3 := x + \left(y + t\right)\\
t_4 := \frac{y}{t_3}\\
t_5 := b \cdot t_4\\
t_6 := \mathsf{fma}\left(1, z + a, -t_5\right)\\
t_7 := -t_4\\
\mathbf{if}\;t_2 \leq -1.8770167269899472 \cdot 10^{+236}:\\
\;\;\;\;t_6 + \mathsf{fma}\left(y \cdot \frac{-1}{t_3}, b, t_5\right)\\

\mathbf{elif}\;t_2 \leq 8.371234403385252 \cdot 10^{+216}:\\
\;\;\;\;\mathsf{fma}\left(1, \frac{\mathsf{fma}\left(x + y, z, t_1\right)}{t_3}, -\frac{b}{\frac{t_3}{y}}\right) + \mathsf{fma}\left(t_7, b, t_5\right)\\

\mathbf{else}:\\
\;\;\;\;t_6 + \mathsf{fma}\left(t_7, b, \frac{1}{\frac{1}{t_5}}\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 t) a))
        (t_2 (/ (- (+ (* (+ x y) z) t_1) (* y b)) (+ y (+ x t))))
        (t_3 (+ x (+ y t)))
        (t_4 (/ y t_3))
        (t_5 (* b t_4))
        (t_6 (fma 1.0 (+ z a) (- t_5)))
        (t_7 (- t_4)))
   (if (<= t_2 -1.8770167269899472e+236)
     (+ t_6 (fma (* y (/ -1.0 t_3)) b t_5))
     (if (<= t_2 8.371234403385252e+216)
       (+
        (fma 1.0 (/ (fma (+ x y) z t_1) t_3) (- (/ b (/ t_3 y))))
        (fma t_7 b t_5))
       (+ t_6 (fma t_7 b (/ 1.0 (/ 1.0 t_5))))))))
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 + t) * a;
	double t_2 = ((((x + y) * z) + t_1) - (y * b)) / (y + (x + t));
	double t_3 = x + (y + t);
	double t_4 = y / t_3;
	double t_5 = b * t_4;
	double t_6 = fma(1.0, (z + a), -t_5);
	double t_7 = -t_4;
	double tmp;
	if (t_2 <= -1.8770167269899472e+236) {
		tmp = t_6 + fma((y * (-1.0 / t_3)), b, t_5);
	} else if (t_2 <= 8.371234403385252e+216) {
		tmp = fma(1.0, (fma((x + y), z, t_1) / t_3), -(b / (t_3 / y))) + fma(t_7, b, t_5);
	} else {
		tmp = t_6 + fma(t_7, b, (1.0 / (1.0 / t_5)));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Bits error versus b

Target

Original26.9
Target11.8
Herbie6.1
\[\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)) < -1.8770167269899472e236

    1. Initial program 57.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. Applied egg-rr49.3

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

      \[\leadsto \mathsf{fma}\left(1, \color{blue}{a + z}, -\frac{y}{x + \left(y + t\right)} \cdot \frac{b}{1}\right) + \mathsf{fma}\left(-\frac{y}{x + \left(y + t\right)}, \frac{b}{1}, \frac{y}{x + \left(y + t\right)} \cdot \frac{b}{1}\right) \]
    4. Applied egg-rr10.9

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

    if -1.8770167269899472e236 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) < 8.37123440338525229e216

    1. Initial program 0.3

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, \frac{\mathsf{fma}\left(x + y, z, \left(y + t\right) \cdot a\right)}{x + \left(y + t\right)}, -\frac{y}{x + \left(y + t\right)} \cdot \frac{b}{1}\right) + \mathsf{fma}\left(-\frac{y}{x + \left(y + t\right)}, \frac{b}{1}, \frac{y}{x + \left(y + t\right)} \cdot \frac{b}{1}\right)} \]
    3. Applied egg-rr1.2

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

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

    1. Initial program 57.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. Applied egg-rr51.6

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

      \[\leadsto \mathsf{fma}\left(1, \color{blue}{a + z}, -\frac{y}{x + \left(y + t\right)} \cdot \frac{b}{1}\right) + \mathsf{fma}\left(-\frac{y}{x + \left(y + t\right)}, \frac{b}{1}, \frac{y}{x + \left(y + t\right)} \cdot \frac{b}{1}\right) \]
    4. Applied egg-rr12.2

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

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

Reproduce

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