Average Error: 25.5 → 15.8
Time: 22.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}\;y \le -2.3749133523278352 \cdot 10^{+123}:\\ \;\;\;\;\left(a + z\right) - b\\ \mathbf{elif}\;y \le 1.2649927179778784 \cdot 10^{+111}:\\ \;\;\;\;\frac{\mathsf{fma}\left(z, x, \mathsf{fma}\left(y, a + \left(z - b\right), a \cdot t\right)\right)}{\left(t + y\right) + x}\\ \mathbf{else}:\\ \;\;\;\;\left(a + z\right) - b\\ \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 -2.3749133523278352 \cdot 10^{+123}:\\
\;\;\;\;\left(a + z\right) - b\\

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

\mathbf{else}:\\
\;\;\;\;\left(a + z\right) - b\\

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r39900992 = x;
        double r39900993 = y;
        double r39900994 = r39900992 + r39900993;
        double r39900995 = z;
        double r39900996 = r39900994 * r39900995;
        double r39900997 = t;
        double r39900998 = r39900997 + r39900993;
        double r39900999 = a;
        double r39901000 = r39900998 * r39900999;
        double r39901001 = r39900996 + r39901000;
        double r39901002 = b;
        double r39901003 = r39900993 * r39901002;
        double r39901004 = r39901001 - r39901003;
        double r39901005 = r39900992 + r39900997;
        double r39901006 = r39901005 + r39900993;
        double r39901007 = r39901004 / r39901006;
        return r39901007;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r39901008 = y;
        double r39901009 = -2.3749133523278352e+123;
        bool r39901010 = r39901008 <= r39901009;
        double r39901011 = a;
        double r39901012 = z;
        double r39901013 = r39901011 + r39901012;
        double r39901014 = b;
        double r39901015 = r39901013 - r39901014;
        double r39901016 = 1.2649927179778784e+111;
        bool r39901017 = r39901008 <= r39901016;
        double r39901018 = x;
        double r39901019 = r39901012 - r39901014;
        double r39901020 = r39901011 + r39901019;
        double r39901021 = t;
        double r39901022 = r39901011 * r39901021;
        double r39901023 = fma(r39901008, r39901020, r39901022);
        double r39901024 = fma(r39901012, r39901018, r39901023);
        double r39901025 = r39901021 + r39901008;
        double r39901026 = r39901025 + r39901018;
        double r39901027 = r39901024 / r39901026;
        double r39901028 = r39901017 ? r39901027 : r39901015;
        double r39901029 = r39901010 ? r39901015 : r39901028;
        return r39901029;
}

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

Original25.5
Target11.0
Herbie15.8
\[\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 y < -2.3749133523278352e+123 or 1.2649927179778784e+111 < y

    1. Initial program 44.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. Simplified44.0

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

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

    if -2.3749133523278352e+123 < y < 1.2649927179778784e+111

    1. Initial program 17.0

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, x, \mathsf{fma}\left(a, t, \left(\left(z + a\right) - b\right) \cdot y\right)\right) \cdot \frac{1}{x + \left(y + t\right)}}\]
    5. Using strategy rm
    6. Applied associate-*r/17.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -2.3749133523278352 \cdot 10^{+123}:\\ \;\;\;\;\left(a + z\right) - b\\ \mathbf{elif}\;y \le 1.2649927179778784 \cdot 10^{+111}:\\ \;\;\;\;\frac{\mathsf{fma}\left(z, x, \mathsf{fma}\left(y, a + \left(z - b\right), a \cdot t\right)\right)}{\left(t + y\right) + x}\\ \mathbf{else}:\\ \;\;\;\;\left(a + z\right) - b\\ \end{array}\]

Reproduce

herbie shell --seed 2019163 +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 (/ (+ (+ 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)))