Average Error: 27.0 → 16.5
Time: 20.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 -0.04160164215629180706201850625802762806416:\\ \;\;\;\;\left(a + z\right) - b\\ \mathbf{elif}\;y \le 8.144388898542231826711430095459243082849 \cdot 10^{53}:\\ \;\;\;\;\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 -0.04160164215629180706201850625802762806416:\\
\;\;\;\;\left(a + z\right) - b\\

\mathbf{elif}\;y \le 8.144388898542231826711430095459243082849 \cdot 10^{53}:\\
\;\;\;\;\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 r26117687 = x;
        double r26117688 = y;
        double r26117689 = r26117687 + r26117688;
        double r26117690 = z;
        double r26117691 = r26117689 * r26117690;
        double r26117692 = t;
        double r26117693 = r26117692 + r26117688;
        double r26117694 = a;
        double r26117695 = r26117693 * r26117694;
        double r26117696 = r26117691 + r26117695;
        double r26117697 = b;
        double r26117698 = r26117688 * r26117697;
        double r26117699 = r26117696 - r26117698;
        double r26117700 = r26117687 + r26117692;
        double r26117701 = r26117700 + r26117688;
        double r26117702 = r26117699 / r26117701;
        return r26117702;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r26117703 = y;
        double r26117704 = -0.04160164215629181;
        bool r26117705 = r26117703 <= r26117704;
        double r26117706 = a;
        double r26117707 = z;
        double r26117708 = r26117706 + r26117707;
        double r26117709 = b;
        double r26117710 = r26117708 - r26117709;
        double r26117711 = 8.144388898542232e+53;
        bool r26117712 = r26117703 <= r26117711;
        double r26117713 = x;
        double r26117714 = r26117703 + r26117713;
        double r26117715 = t;
        double r26117716 = r26117715 + r26117703;
        double r26117717 = r26117706 * r26117716;
        double r26117718 = fma(r26117714, r26117707, r26117717);
        double r26117719 = r26117703 * r26117709;
        double r26117720 = r26117718 - r26117719;
        double r26117721 = r26117716 + r26117713;
        double r26117722 = r26117720 / r26117721;
        double r26117723 = r26117712 ? r26117722 : r26117710;
        double r26117724 = r26117705 ? r26117710 : r26117723;
        return r26117724;
}

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.0
Target11.2
Herbie16.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 2 regimes
  2. if y < -0.04160164215629181 or 8.144388898542232e+53 < y

    1. Initial program 40.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. Simplified40.0

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

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

    if -0.04160164215629181 < y < 8.144388898542232e+53

    1. Initial program 16.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. Simplified16.0

      \[\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. Recombined 2 regimes into one program.
  4. Final simplification16.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -0.04160164215629180706201850625802762806416:\\ \;\;\;\;\left(a + z\right) - b\\ \mathbf{elif}\;y \le 8.144388898542231826711430095459243082849 \cdot 10^{53}:\\ \;\;\;\;\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 2019192 +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)))