Average Error: 26.5 → 17.1
Time: 19.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 -3.779017099091306629227354324491082033966 \cdot 10^{-72} \lor \neg \left(y \le 5.718779504277736397867079463733055523154 \cdot 10^{75}\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 -3.779017099091306629227354324491082033966 \cdot 10^{-72} \lor \neg \left(y \le 5.718779504277736397867079463733055523154 \cdot 10^{75}\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 r675137 = x;
        double r675138 = y;
        double r675139 = r675137 + r675138;
        double r675140 = z;
        double r675141 = r675139 * r675140;
        double r675142 = t;
        double r675143 = r675142 + r675138;
        double r675144 = a;
        double r675145 = r675143 * r675144;
        double r675146 = r675141 + r675145;
        double r675147 = b;
        double r675148 = r675138 * r675147;
        double r675149 = r675146 - r675148;
        double r675150 = r675137 + r675142;
        double r675151 = r675150 + r675138;
        double r675152 = r675149 / r675151;
        return r675152;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r675153 = y;
        double r675154 = -3.7790170990913066e-72;
        bool r675155 = r675153 <= r675154;
        double r675156 = 5.718779504277736e+75;
        bool r675157 = r675153 <= r675156;
        double r675158 = !r675157;
        bool r675159 = r675155 || r675158;
        double r675160 = a;
        double r675161 = b;
        double r675162 = z;
        double r675163 = r675161 - r675162;
        double r675164 = r675160 - r675163;
        double r675165 = 1.0;
        double r675166 = x;
        double r675167 = r675160 + r675162;
        double r675168 = r675167 - r675161;
        double r675169 = t;
        double r675170 = r675160 * r675169;
        double r675171 = fma(r675153, r675168, r675170);
        double r675172 = fma(r675166, r675162, r675171);
        double r675173 = r675165 / r675172;
        double r675174 = r675153 + r675169;
        double r675175 = r675174 + r675166;
        double r675176 = r675173 * r675175;
        double r675177 = r675165 / r675176;
        double r675178 = r675159 ? r675164 : r675177;
        return r675178;
}

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.5
Target11.0
Herbie17.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.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 < -3.7790170990913066e-72 or 5.718779504277736e+75 < y

    1. Initial program 37.6

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

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

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

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

    if -3.7790170990913066e-72 < y < 5.718779504277736e+75

    1. Initial program 15.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. Simplified15.7

      \[\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-num15.8

      \[\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. Simplified15.8

      \[\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-inv15.9

      \[\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. Simplified15.9

      \[\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 simplification17.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -3.779017099091306629227354324491082033966 \cdot 10^{-72} \lor \neg \left(y \le 5.718779504277736397867079463733055523154 \cdot 10^{75}\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 2019194 +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)))