Average Error: 25.5 → 15.8
Time: 21.7s
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 r35365130 = x;
        double r35365131 = y;
        double r35365132 = r35365130 + r35365131;
        double r35365133 = z;
        double r35365134 = r35365132 * r35365133;
        double r35365135 = t;
        double r35365136 = r35365135 + r35365131;
        double r35365137 = a;
        double r35365138 = r35365136 * r35365137;
        double r35365139 = r35365134 + r35365138;
        double r35365140 = b;
        double r35365141 = r35365131 * r35365140;
        double r35365142 = r35365139 - r35365141;
        double r35365143 = r35365130 + r35365135;
        double r35365144 = r35365143 + r35365131;
        double r35365145 = r35365142 / r35365144;
        return r35365145;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r35365146 = y;
        double r35365147 = -2.3749133523278352e+123;
        bool r35365148 = r35365146 <= r35365147;
        double r35365149 = a;
        double r35365150 = z;
        double r35365151 = r35365149 + r35365150;
        double r35365152 = b;
        double r35365153 = r35365151 - r35365152;
        double r35365154 = 1.2649927179778784e+111;
        bool r35365155 = r35365146 <= r35365154;
        double r35365156 = x;
        double r35365157 = r35365150 - r35365152;
        double r35365158 = r35365149 + r35365157;
        double r35365159 = t;
        double r35365160 = r35365149 * r35365159;
        double r35365161 = fma(r35365146, r35365158, r35365160);
        double r35365162 = fma(r35365150, r35365156, r35365161);
        double r35365163 = r35365159 + r35365146;
        double r35365164 = r35365163 + r35365156;
        double r35365165 = r35365162 / r35365164;
        double r35365166 = r35365155 ? r35365165 : r35365153;
        double r35365167 = r35365148 ? r35365153 : r35365166;
        return r35365167;
}

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