Average Error: 26.7 → 22.9
Time: 6.2s
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 -2.7556754271139724 \cdot 10^{158}:\\ \;\;\;\;a\\ \mathbf{elif}\;a \le 3.30497639824276263 \cdot 10^{161}:\\ \;\;\;\;\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 -2.7556754271139724 \cdot 10^{158}:\\
\;\;\;\;a\\

\mathbf{elif}\;a \le 3.30497639824276263 \cdot 10^{161}:\\
\;\;\;\;\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 r916405 = x;
        double r916406 = y;
        double r916407 = r916405 + r916406;
        double r916408 = z;
        double r916409 = r916407 * r916408;
        double r916410 = t;
        double r916411 = r916410 + r916406;
        double r916412 = a;
        double r916413 = r916411 * r916412;
        double r916414 = r916409 + r916413;
        double r916415 = b;
        double r916416 = r916406 * r916415;
        double r916417 = r916414 - r916416;
        double r916418 = r916405 + r916410;
        double r916419 = r916418 + r916406;
        double r916420 = r916417 / r916419;
        return r916420;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r916421 = a;
        double r916422 = -2.7556754271139724e+158;
        bool r916423 = r916421 <= r916422;
        double r916424 = 3.3049763982427626e+161;
        bool r916425 = r916421 <= r916424;
        double r916426 = x;
        double r916427 = z;
        double r916428 = y;
        double r916429 = r916427 * r916428;
        double r916430 = fma(r916426, r916427, r916429);
        double r916431 = t;
        double r916432 = r916431 + r916428;
        double r916433 = r916432 * r916421;
        double r916434 = r916430 + r916433;
        double r916435 = b;
        double r916436 = r916428 * r916435;
        double r916437 = r916434 - r916436;
        double r916438 = r916426 + r916431;
        double r916439 = r916438 + r916428;
        double r916440 = r916437 / r916439;
        double r916441 = r916425 ? r916440 : r916421;
        double r916442 = r916423 ? r916421 : r916441;
        return r916442;
}

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.7
Target11.1
Herbie22.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} \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 2 regimes
  2. if a < -2.7556754271139724e+158 or 3.3049763982427626e+161 < a

    1. Initial program 43.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 0 27.4

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

    if -2.7556754271139724e+158 < a < 3.3049763982427626e+161

    1. Initial program 21.5

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

      \[\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. Simplified21.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \le -2.7556754271139724 \cdot 10^{158}:\\ \;\;\;\;a\\ \mathbf{elif}\;a \le 3.30497639824276263 \cdot 10^{161}:\\ \;\;\;\;\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 2020039 +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)))