Average Error: 26.8 → 17.5
Time: 22.8s
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 -1.12340553540398282974395246595228861055 \cdot 10^{66}:\\ \;\;\;\;\left(a + z\right) - b\\ \mathbf{elif}\;y \le -1.472184673179024906311519965673653353206 \cdot 10^{-191}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y + x, z, a \cdot \left(t + y\right)\right) - y \cdot b}{\left(t + y\right) + x}\\ \mathbf{elif}\;y \le -1.624020243223143567434005918463591296748 \cdot 10^{-228}:\\ \;\;\;\;a\\ \mathbf{elif}\;y \le 0.001960496957535617142814876601164542080369:\\ \;\;\;\;\frac{\mathsf{fma}\left(y + x, z, a \cdot \left(t + y\right)\right) - y \cdot b}{\left(t + y\right) + x}\\ \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 -1.12340553540398282974395246595228861055 \cdot 10^{66}:\\
\;\;\;\;\left(a + z\right) - b\\

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

\mathbf{elif}\;y \le -1.624020243223143567434005918463591296748 \cdot 10^{-228}:\\
\;\;\;\;a\\

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

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r40123839 = x;
        double r40123840 = y;
        double r40123841 = r40123839 + r40123840;
        double r40123842 = z;
        double r40123843 = r40123841 * r40123842;
        double r40123844 = t;
        double r40123845 = r40123844 + r40123840;
        double r40123846 = a;
        double r40123847 = r40123845 * r40123846;
        double r40123848 = r40123843 + r40123847;
        double r40123849 = b;
        double r40123850 = r40123840 * r40123849;
        double r40123851 = r40123848 - r40123850;
        double r40123852 = r40123839 + r40123844;
        double r40123853 = r40123852 + r40123840;
        double r40123854 = r40123851 / r40123853;
        return r40123854;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r40123855 = y;
        double r40123856 = -1.1234055354039828e+66;
        bool r40123857 = r40123855 <= r40123856;
        double r40123858 = a;
        double r40123859 = z;
        double r40123860 = r40123858 + r40123859;
        double r40123861 = b;
        double r40123862 = r40123860 - r40123861;
        double r40123863 = -1.472184673179025e-191;
        bool r40123864 = r40123855 <= r40123863;
        double r40123865 = x;
        double r40123866 = r40123855 + r40123865;
        double r40123867 = t;
        double r40123868 = r40123867 + r40123855;
        double r40123869 = r40123858 * r40123868;
        double r40123870 = fma(r40123866, r40123859, r40123869);
        double r40123871 = r40123855 * r40123861;
        double r40123872 = r40123870 - r40123871;
        double r40123873 = r40123868 + r40123865;
        double r40123874 = r40123872 / r40123873;
        double r40123875 = -1.6240202432231436e-228;
        bool r40123876 = r40123855 <= r40123875;
        double r40123877 = 0.001960496957535617;
        bool r40123878 = r40123855 <= r40123877;
        double r40123879 = r40123878 ? r40123874 : r40123862;
        double r40123880 = r40123876 ? r40123858 : r40123879;
        double r40123881 = r40123864 ? r40123874 : r40123880;
        double r40123882 = r40123857 ? r40123862 : r40123881;
        return r40123882;
}

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.8
Target11.6
Herbie17.5
\[\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 3 regimes
  2. if y < -1.1234055354039828e+66 or 0.001960496957535617 < y

    1. Initial program 39.5

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

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

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

    if -1.1234055354039828e+66 < y < -1.472184673179025e-191 or -1.6240202432231436e-228 < y < 0.001960496957535617

    1. Initial program 16.8

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

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

    if -1.472184673179025e-191 < y < -1.6240202432231436e-228

    1. Initial program 17.9

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

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

      \[\leadsto \color{blue}{a}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification17.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.12340553540398282974395246595228861055 \cdot 10^{66}:\\ \;\;\;\;\left(a + z\right) - b\\ \mathbf{elif}\;y \le -1.472184673179024906311519965673653353206 \cdot 10^{-191}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y + x, z, a \cdot \left(t + y\right)\right) - y \cdot b}{\left(t + y\right) + x}\\ \mathbf{elif}\;y \le -1.624020243223143567434005918463591296748 \cdot 10^{-228}:\\ \;\;\;\;a\\ \mathbf{elif}\;y \le 0.001960496957535617142814876601164542080369:\\ \;\;\;\;\frac{\mathsf{fma}\left(y + x, z, a \cdot \left(t + y\right)\right) - y \cdot b}{\left(t + y\right) + x}\\ \mathbf{else}:\\ \;\;\;\;\left(a + z\right) - b\\ \end{array}\]

Reproduce

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