Average Error: 26.9 → 16.5
Time: 20.8s
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}\;y \le -1.260180339436653635916883174940229460122 \cdot 10^{135} \lor \neg \left(y \le 2.172072385982974663344524408646353917622 \cdot 10^{114}\right):\\ \;\;\;\;a - \left(b - z\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{1}{\mathsf{fma}\left(x, z, \mathsf{fma}\left(y, \left(a + z\right) - b, a \cdot t\right)\right)} \cdot \left(\left(y + t\right) + x\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}
\mathbf{if}\;y \le -1.260180339436653635916883174940229460122 \cdot 10^{135} \lor \neg \left(y \le 2.172072385982974663344524408646353917622 \cdot 10^{114}\right):\\
\;\;\;\;a - \left(b - z\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{1}{\mathsf{fma}\left(x, z, \mathsf{fma}\left(y, \left(a + z\right) - b, a \cdot t\right)\right)} \cdot \left(\left(y + t\right) + x\right)}\\

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r855555 = x;
        double r855556 = y;
        double r855557 = r855555 + r855556;
        double r855558 = z;
        double r855559 = r855557 * r855558;
        double r855560 = t;
        double r855561 = r855560 + r855556;
        double r855562 = a;
        double r855563 = r855561 * r855562;
        double r855564 = r855559 + r855563;
        double r855565 = b;
        double r855566 = r855556 * r855565;
        double r855567 = r855564 - r855566;
        double r855568 = r855555 + r855560;
        double r855569 = r855568 + r855556;
        double r855570 = r855567 / r855569;
        return r855570;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r855571 = y;
        double r855572 = -1.2601803394366536e+135;
        bool r855573 = r855571 <= r855572;
        double r855574 = 2.1720723859829747e+114;
        bool r855575 = r855571 <= r855574;
        double r855576 = !r855575;
        bool r855577 = r855573 || r855576;
        double r855578 = a;
        double r855579 = b;
        double r855580 = z;
        double r855581 = r855579 - r855580;
        double r855582 = r855578 - r855581;
        double r855583 = 1.0;
        double r855584 = x;
        double r855585 = r855578 + r855580;
        double r855586 = r855585 - r855579;
        double r855587 = t;
        double r855588 = r855578 * r855587;
        double r855589 = fma(r855571, r855586, r855588);
        double r855590 = fma(r855584, r855580, r855589);
        double r855591 = r855583 / r855590;
        double r855592 = r855571 + r855587;
        double r855593 = r855592 + r855584;
        double r855594 = r855591 * r855593;
        double r855595 = r855583 / r855594;
        double r855596 = r855577 ? r855582 : r855595;
        return r855596;
}

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.3
Herbie16.5
\[\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.581311708415056427521064305370896655752 \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.228596430831560895857110658734089400289 \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 y < -1.2601803394366536e+135 or 2.1720723859829747e+114 < y

    1. Initial program 47.2

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

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

      \[\leadsto \color{blue}{\left(a + z\right) - b}\]
    4. Simplified12.0

      \[\leadsto \color{blue}{a - \left(b - z\right)}\]

    if -1.2601803394366536e+135 < y < 2.1720723859829747e+114

    1. Initial program 18.2

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(y, a - \left(b - z\right), \mathsf{fma}\left(t, a, z \cdot x\right)\right)}{x + \left(y + t\right)}}\]
    3. Using strategy rm
    4. Applied clear-num18.3

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

      \[\leadsto \frac{1}{\color{blue}{\frac{\left(y + t\right) + x}{\mathsf{fma}\left(x, z, \mathsf{fma}\left(a - \left(b - z\right), y, t \cdot a\right)\right)}}}\]
    6. Using strategy rm
    7. Applied div-inv18.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.260180339436653635916883174940229460122 \cdot 10^{135} \lor \neg \left(y \le 2.172072385982974663344524408646353917622 \cdot 10^{114}\right):\\ \;\;\;\;a - \left(b - z\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{1}{\mathsf{fma}\left(x, z, \mathsf{fma}\left(y, \left(a + z\right) - b, a \cdot t\right)\right)} \cdot \left(\left(y + t\right) + x\right)}\\ \end{array}\]

Reproduce

herbie shell --seed 2019196 +o rules:numerics
(FPCore (x y z t a b)
  :name "AI.Clustering.Hierarchical.Internal:ward from clustering-0.2.1"

  :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)))