Average Error: 26.8 → 16.0
Time: 24.7s
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.967499584174674248364030486477827237773 \cdot 10^{140}:\\ \;\;\;\;\left(a + z\right) - b\\ \mathbf{elif}\;y \le -2.073956642809603980847998976244338730115 \cdot 10^{98}:\\ \;\;\;\;\frac{1}{\frac{\left(t + y\right) + x}{\mathsf{fma}\left(y + x, z, a \cdot \left(t + y\right)\right) - y \cdot b}}\\ \mathbf{elif}\;y \le -2.310983057827040438914549423634512128913 \cdot 10^{48}:\\ \;\;\;\;\left(a + z\right) - b\\ \mathbf{elif}\;y \le 3.386128128459719612981223918062857795656 \cdot 10^{60}:\\ \;\;\;\;\frac{1}{\frac{\left(t + y\right) + x}{\mathsf{fma}\left(y + x, z, a \cdot \left(t + y\right)\right) - y \cdot b}}\\ \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.967499584174674248364030486477827237773 \cdot 10^{140}:\\
\;\;\;\;\left(a + z\right) - b\\

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

\mathbf{elif}\;y \le -2.310983057827040438914549423634512128913 \cdot 10^{48}:\\
\;\;\;\;\left(a + z\right) - b\\

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

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r38138890 = x;
        double r38138891 = y;
        double r38138892 = r38138890 + r38138891;
        double r38138893 = z;
        double r38138894 = r38138892 * r38138893;
        double r38138895 = t;
        double r38138896 = r38138895 + r38138891;
        double r38138897 = a;
        double r38138898 = r38138896 * r38138897;
        double r38138899 = r38138894 + r38138898;
        double r38138900 = b;
        double r38138901 = r38138891 * r38138900;
        double r38138902 = r38138899 - r38138901;
        double r38138903 = r38138890 + r38138895;
        double r38138904 = r38138903 + r38138891;
        double r38138905 = r38138902 / r38138904;
        return r38138905;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r38138906 = y;
        double r38138907 = -1.9674995841746742e+140;
        bool r38138908 = r38138906 <= r38138907;
        double r38138909 = a;
        double r38138910 = z;
        double r38138911 = r38138909 + r38138910;
        double r38138912 = b;
        double r38138913 = r38138911 - r38138912;
        double r38138914 = -2.073956642809604e+98;
        bool r38138915 = r38138906 <= r38138914;
        double r38138916 = 1.0;
        double r38138917 = t;
        double r38138918 = r38138917 + r38138906;
        double r38138919 = x;
        double r38138920 = r38138918 + r38138919;
        double r38138921 = r38138906 + r38138919;
        double r38138922 = r38138909 * r38138918;
        double r38138923 = fma(r38138921, r38138910, r38138922);
        double r38138924 = r38138906 * r38138912;
        double r38138925 = r38138923 - r38138924;
        double r38138926 = r38138920 / r38138925;
        double r38138927 = r38138916 / r38138926;
        double r38138928 = -2.3109830578270404e+48;
        bool r38138929 = r38138906 <= r38138928;
        double r38138930 = 3.3861281284597196e+60;
        bool r38138931 = r38138906 <= r38138930;
        double r38138932 = r38138931 ? r38138927 : r38138913;
        double r38138933 = r38138929 ? r38138913 : r38138932;
        double r38138934 = r38138915 ? r38138927 : r38138933;
        double r38138935 = r38138908 ? r38138913 : r38138934;
        return r38138935;
}

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.1
Herbie16.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.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 < -1.9674995841746742e+140 or -2.073956642809604e+98 < y < -2.3109830578270404e+48 or 3.3861281284597196e+60 < y

    1. Initial program 42.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. Simplified42.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)}}\]
    3. Taylor expanded around inf 14.1

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

    if -1.9674995841746742e+140 < y < -2.073956642809604e+98 or -2.3109830578270404e+48 < y < 3.3861281284597196e+60

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.967499584174674248364030486477827237773 \cdot 10^{140}:\\ \;\;\;\;\left(a + z\right) - b\\ \mathbf{elif}\;y \le -2.073956642809603980847998976244338730115 \cdot 10^{98}:\\ \;\;\;\;\frac{1}{\frac{\left(t + y\right) + x}{\mathsf{fma}\left(y + x, z, a \cdot \left(t + y\right)\right) - y \cdot b}}\\ \mathbf{elif}\;y \le -2.310983057827040438914549423634512128913 \cdot 10^{48}:\\ \;\;\;\;\left(a + z\right) - b\\ \mathbf{elif}\;y \le 3.386128128459719612981223918062857795656 \cdot 10^{60}:\\ \;\;\;\;\frac{1}{\frac{\left(t + y\right) + x}{\mathsf{fma}\left(y + x, z, a \cdot \left(t + y\right)\right) - y \cdot b}}\\ \mathbf{else}:\\ \;\;\;\;\left(a + z\right) - b\\ \end{array}\]

Reproduce

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