Average Error: 25.5 → 15.8
Time: 16.3s
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(y, a - b, \mathsf{fma}\left(z, y + x, a \cdot t\right)\right)}{\left(y + x\right) + t}\\ \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(y, a - b, \mathsf{fma}\left(z, y + x, a \cdot t\right)\right)}{\left(y + x\right) + t}\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r41852644 = x;
        double r41852645 = y;
        double r41852646 = r41852644 + r41852645;
        double r41852647 = z;
        double r41852648 = r41852646 * r41852647;
        double r41852649 = t;
        double r41852650 = r41852649 + r41852645;
        double r41852651 = a;
        double r41852652 = r41852650 * r41852651;
        double r41852653 = r41852648 + r41852652;
        double r41852654 = b;
        double r41852655 = r41852645 * r41852654;
        double r41852656 = r41852653 - r41852655;
        double r41852657 = r41852644 + r41852649;
        double r41852658 = r41852657 + r41852645;
        double r41852659 = r41852656 / r41852658;
        return r41852659;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r41852660 = y;
        double r41852661 = -2.3749133523278352e+123;
        bool r41852662 = r41852660 <= r41852661;
        double r41852663 = a;
        double r41852664 = z;
        double r41852665 = r41852663 + r41852664;
        double r41852666 = b;
        double r41852667 = r41852665 - r41852666;
        double r41852668 = 1.2649927179778784e+111;
        bool r41852669 = r41852660 <= r41852668;
        double r41852670 = r41852663 - r41852666;
        double r41852671 = x;
        double r41852672 = r41852660 + r41852671;
        double r41852673 = t;
        double r41852674 = r41852663 * r41852673;
        double r41852675 = fma(r41852664, r41852672, r41852674);
        double r41852676 = fma(r41852660, r41852670, r41852675);
        double r41852677 = r41852672 + r41852673;
        double r41852678 = r41852676 / r41852677;
        double r41852679 = r41852669 ? r41852678 : r41852667;
        double r41852680 = r41852662 ? r41852667 : r41852679;
        return r41852680;
}

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.1

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(y, a - b, \mathsf{fma}\left(t, a, \left(x + y\right) \cdot z\right)\right)}{t + \left(x + y\right)}}\]
    3. Taylor expanded around inf 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.0

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

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

      \[\leadsto \frac{\mathsf{fma}\left(y, a - b, \color{blue}{\mathsf{fma}\left(z, x + y, a \cdot t\right)}\right)}{t + \left(x + y\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(y, a - b, \mathsf{fma}\left(z, y + x, a \cdot t\right)\right)}{\left(y + x\right) + t}\\ \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)))