Average Error: 24.4 → 15.0
Time: 19.5s
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 -5.161631857410307 \cdot 10^{+87}:\\ \;\;\;\;\left(a + z\right) - b\\ \mathbf{elif}\;y \le 1.2744164181753573 \cdot 10^{+42}:\\ \;\;\;\;\frac{\mathsf{fma}\left(z, y + x, a \cdot \left(t + y\right) - y \cdot b\right)}{\left(t + x\right) + y}\\ \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 -5.161631857410307 \cdot 10^{+87}:\\
\;\;\;\;\left(a + z\right) - b\\

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

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r39574910 = x;
        double r39574911 = y;
        double r39574912 = r39574910 + r39574911;
        double r39574913 = z;
        double r39574914 = r39574912 * r39574913;
        double r39574915 = t;
        double r39574916 = r39574915 + r39574911;
        double r39574917 = a;
        double r39574918 = r39574916 * r39574917;
        double r39574919 = r39574914 + r39574918;
        double r39574920 = b;
        double r39574921 = r39574911 * r39574920;
        double r39574922 = r39574919 - r39574921;
        double r39574923 = r39574910 + r39574915;
        double r39574924 = r39574923 + r39574911;
        double r39574925 = r39574922 / r39574924;
        return r39574925;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r39574926 = y;
        double r39574927 = -5.161631857410307e+87;
        bool r39574928 = r39574926 <= r39574927;
        double r39574929 = a;
        double r39574930 = z;
        double r39574931 = r39574929 + r39574930;
        double r39574932 = b;
        double r39574933 = r39574931 - r39574932;
        double r39574934 = 1.2744164181753573e+42;
        bool r39574935 = r39574926 <= r39574934;
        double r39574936 = x;
        double r39574937 = r39574926 + r39574936;
        double r39574938 = t;
        double r39574939 = r39574938 + r39574926;
        double r39574940 = r39574929 * r39574939;
        double r39574941 = r39574926 * r39574932;
        double r39574942 = r39574940 - r39574941;
        double r39574943 = fma(r39574930, r39574937, r39574942);
        double r39574944 = r39574938 + r39574936;
        double r39574945 = r39574944 + r39574926;
        double r39574946 = r39574943 / r39574945;
        double r39574947 = r39574935 ? r39574946 : r39574933;
        double r39574948 = r39574928 ? r39574933 : r39574947;
        return r39574948;
}

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

Original24.4
Target11.4
Herbie15.0
\[\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 < -5.161631857410307e+87 or 1.2744164181753573e+42 < y

    1. Initial program 39.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. Simplified39.3

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

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

    if -5.161631857410307e+87 < y < 1.2744164181753573e+42

    1. Initial program 15.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. Using strategy rm
    3. Applied *-un-lft-identity15.0

      \[\leadsto \frac{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) - y \cdot b}{\color{blue}{1 \cdot \left(\left(x + t\right) + y\right)}}\]
    4. Applied associate-/r*15.0

      \[\leadsto \color{blue}{\frac{\frac{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) - y \cdot b}{1}}{\left(x + t\right) + y}}\]
    5. Simplified15.0

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

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

Reproduce

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