Average Error: 26.7 → 15.9
Time: 40.9s
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 -44587221161492483218018742042624:\\ \;\;\;\;\left(z + a\right) - b\\ \mathbf{elif}\;y \le 11954042188640717677055876658790137856:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, a - b, \mathsf{fma}\left(t, a, \left(y + x\right) \cdot z\right)\right)}{t + \left(y + x\right)}\\ \mathbf{else}:\\ \;\;\;\;\left(z + a\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 -44587221161492483218018742042624:\\
\;\;\;\;\left(z + a\right) - b\\

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

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r33417360 = x;
        double r33417361 = y;
        double r33417362 = r33417360 + r33417361;
        double r33417363 = z;
        double r33417364 = r33417362 * r33417363;
        double r33417365 = t;
        double r33417366 = r33417365 + r33417361;
        double r33417367 = a;
        double r33417368 = r33417366 * r33417367;
        double r33417369 = r33417364 + r33417368;
        double r33417370 = b;
        double r33417371 = r33417361 * r33417370;
        double r33417372 = r33417369 - r33417371;
        double r33417373 = r33417360 + r33417365;
        double r33417374 = r33417373 + r33417361;
        double r33417375 = r33417372 / r33417374;
        return r33417375;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r33417376 = y;
        double r33417377 = -4.458722116149248e+31;
        bool r33417378 = r33417376 <= r33417377;
        double r33417379 = z;
        double r33417380 = a;
        double r33417381 = r33417379 + r33417380;
        double r33417382 = b;
        double r33417383 = r33417381 - r33417382;
        double r33417384 = 1.1954042188640718e+37;
        bool r33417385 = r33417376 <= r33417384;
        double r33417386 = r33417380 - r33417382;
        double r33417387 = t;
        double r33417388 = x;
        double r33417389 = r33417376 + r33417388;
        double r33417390 = r33417389 * r33417379;
        double r33417391 = fma(r33417387, r33417380, r33417390);
        double r33417392 = fma(r33417376, r33417386, r33417391);
        double r33417393 = r33417387 + r33417389;
        double r33417394 = r33417392 / r33417393;
        double r33417395 = r33417385 ? r33417394 : r33417383;
        double r33417396 = r33417378 ? r33417383 : r33417395;
        return r33417396;
}

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
Herbie15.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.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 < -4.458722116149248e+31 or 1.1954042188640718e+37 < y

    1. Initial program 40.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. Simplified40.7

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

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

    if -4.458722116149248e+31 < y < 1.1954042188640718e+37

    1. Initial program 15.4

      \[\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.4

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

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

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

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\left(\left(y + x\right) + t\right) \cdot \frac{1}{\mathsf{fma}\left(y, a - b, \mathsf{fma}\left(t, a, z \cdot \left(y + x\right)\right)\right)}}\]
    8. Applied times-frac15.6

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

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

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

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

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

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

Reproduce

herbie shell --seed 2019200 +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)))