Average Error: 26.6 → 23.1
Time: 11.3s
Precision: 64
\[\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} \mathbf{if}\;a \le -1.323428910747886 \cdot 10^{109}:\\ \;\;\;\;a\\ \mathbf{elif}\;a \le 2.5768960874769005 \cdot 10^{-303}:\\ \;\;\;\;\frac{\left(\mathsf{fma}\left(x, z, z \cdot y\right) + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y}\\ \mathbf{elif}\;a \le 1.293616190882518 \cdot 10^{-246}:\\ \;\;\;\;z\\ \mathbf{elif}\;a \le 1.91239495053610424 \cdot 10^{146}:\\ \;\;\;\;\frac{\left(\mathsf{fma}\left(x, z, z \cdot y\right) + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y}\\ \mathbf{else}:\\ \;\;\;\;a\\ \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}
\mathbf{if}\;a \le -1.323428910747886 \cdot 10^{109}:\\
\;\;\;\;a\\

\mathbf{elif}\;a \le 2.5768960874769005 \cdot 10^{-303}:\\
\;\;\;\;\frac{\left(\mathsf{fma}\left(x, z, z \cdot y\right) + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y}\\

\mathbf{elif}\;a \le 1.293616190882518 \cdot 10^{-246}:\\
\;\;\;\;z\\

\mathbf{elif}\;a \le 1.91239495053610424 \cdot 10^{146}:\\
\;\;\;\;\frac{\left(\mathsf{fma}\left(x, z, z \cdot y\right) + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y}\\

\mathbf{else}:\\
\;\;\;\;a\\

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r890541 = x;
        double r890542 = y;
        double r890543 = r890541 + r890542;
        double r890544 = z;
        double r890545 = r890543 * r890544;
        double r890546 = t;
        double r890547 = r890546 + r890542;
        double r890548 = a;
        double r890549 = r890547 * r890548;
        double r890550 = r890545 + r890549;
        double r890551 = b;
        double r890552 = r890542 * r890551;
        double r890553 = r890550 - r890552;
        double r890554 = r890541 + r890546;
        double r890555 = r890554 + r890542;
        double r890556 = r890553 / r890555;
        return r890556;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r890557 = a;
        double r890558 = -1.323428910747886e+109;
        bool r890559 = r890557 <= r890558;
        double r890560 = 2.5768960874769005e-303;
        bool r890561 = r890557 <= r890560;
        double r890562 = x;
        double r890563 = z;
        double r890564 = y;
        double r890565 = r890563 * r890564;
        double r890566 = fma(r890562, r890563, r890565);
        double r890567 = t;
        double r890568 = r890567 + r890564;
        double r890569 = r890568 * r890557;
        double r890570 = r890566 + r890569;
        double r890571 = b;
        double r890572 = r890564 * r890571;
        double r890573 = r890570 - r890572;
        double r890574 = r890562 + r890567;
        double r890575 = r890574 + r890564;
        double r890576 = r890573 / r890575;
        double r890577 = 1.293616190882518e-246;
        bool r890578 = r890557 <= r890577;
        double r890579 = 1.9123949505361042e+146;
        bool r890580 = r890557 <= r890579;
        double r890581 = r890580 ? r890576 : r890557;
        double r890582 = r890578 ? r890563 : r890581;
        double r890583 = r890561 ? r890576 : r890582;
        double r890584 = r890559 ? r890557 : r890583;
        return r890584;
}

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.6
Target11.0
Herbie23.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} \lt -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} \lt 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 a < -1.323428910747886e+109 or 1.9123949505361042e+146 < a

    1. Initial program 42.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 around 0 28.0

      \[\leadsto \color{blue}{a}\]

    if -1.323428910747886e+109 < a < 2.5768960874769005e-303 or 1.293616190882518e-246 < a < 1.9123949505361042e+146

    1. Initial program 20.1

      \[\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 around inf 20.1

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

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

    if 2.5768960874769005e-303 < a < 1.293616190882518e-246

    1. Initial program 22.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 around inf 35.0

      \[\leadsto \color{blue}{z}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification23.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \le -1.323428910747886 \cdot 10^{109}:\\ \;\;\;\;a\\ \mathbf{elif}\;a \le 2.5768960874769005 \cdot 10^{-303}:\\ \;\;\;\;\frac{\left(\mathsf{fma}\left(x, z, z \cdot y\right) + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y}\\ \mathbf{elif}\;a \le 1.293616190882518 \cdot 10^{-246}:\\ \;\;\;\;z\\ \mathbf{elif}\;a \le 1.91239495053610424 \cdot 10^{146}:\\ \;\;\;\;\frac{\left(\mathsf{fma}\left(x, z, z \cdot y\right) + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y}\\ \mathbf{else}:\\ \;\;\;\;a\\ \end{array}\]

Reproduce

herbie shell --seed 2020100 +o rules:numerics
(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 (/ (+ (+ 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)))