Average Error: 27.1 → 16.4
Time: 25.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 -9.283225756149319248945106802416453318378 \cdot 10^{114} \lor \neg \left(y \le 339454492032664018177593228072776105984\right):\\ \;\;\;\;\left(a + z\right) - b\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a, t + y, \mathsf{fma}\left(x, z, y \cdot \left(z - b\right)\right)\right) \cdot \frac{1}{\left(x + t\right) + y}\\ \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 -9.283225756149319248945106802416453318378 \cdot 10^{114} \lor \neg \left(y \le 339454492032664018177593228072776105984\right):\\
\;\;\;\;\left(a + z\right) - b\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r626974 = x;
        double r626975 = y;
        double r626976 = r626974 + r626975;
        double r626977 = z;
        double r626978 = r626976 * r626977;
        double r626979 = t;
        double r626980 = r626979 + r626975;
        double r626981 = a;
        double r626982 = r626980 * r626981;
        double r626983 = r626978 + r626982;
        double r626984 = b;
        double r626985 = r626975 * r626984;
        double r626986 = r626983 - r626985;
        double r626987 = r626974 + r626979;
        double r626988 = r626987 + r626975;
        double r626989 = r626986 / r626988;
        return r626989;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r626990 = y;
        double r626991 = -9.283225756149319e+114;
        bool r626992 = r626990 <= r626991;
        double r626993 = 3.39454492032664e+38;
        bool r626994 = r626990 <= r626993;
        double r626995 = !r626994;
        bool r626996 = r626992 || r626995;
        double r626997 = a;
        double r626998 = z;
        double r626999 = r626997 + r626998;
        double r627000 = b;
        double r627001 = r626999 - r627000;
        double r627002 = t;
        double r627003 = r627002 + r626990;
        double r627004 = x;
        double r627005 = r626998 - r627000;
        double r627006 = r626990 * r627005;
        double r627007 = fma(r627004, r626998, r627006);
        double r627008 = fma(r626997, r627003, r627007);
        double r627009 = 1.0;
        double r627010 = r627004 + r627002;
        double r627011 = r627010 + r626990;
        double r627012 = r627009 / r627011;
        double r627013 = r627008 * r627012;
        double r627014 = r626996 ? r627001 : r627013;
        return r627014;
}

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

Original27.1
Target11.4
Herbie16.4
\[\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 < -9.283225756149319e+114 or 3.39454492032664e+38 < y

    1. Initial program 44.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. Simplified44.0

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

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

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

    if -9.283225756149319e+114 < y < 3.39454492032664e+38

    1. Initial program 17.1

      \[\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(a, t + y, \mathsf{fma}\left(x, z, y \cdot \left(z - b\right)\right)\right)}{\left(x + t\right) + y}}\]
    3. Using strategy rm
    4. Applied div-inv17.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -9.283225756149319248945106802416453318378 \cdot 10^{114} \lor \neg \left(y \le 339454492032664018177593228072776105984\right):\\ \;\;\;\;\left(a + z\right) - b\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a, t + y, \mathsf{fma}\left(x, z, y \cdot \left(z - b\right)\right)\right) \cdot \frac{1}{\left(x + t\right) + y}\\ \end{array}\]

Reproduce

herbie shell --seed 2019323 +o rules:numerics
(FPCore (x y z t a b)
  :name "AI.Clustering.Hierarchical.Internal:ward from clustering-0.2.1"
  :precision binary64

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