Average Error: 27.0 → 15.9
Time: 20.0s
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.377781447530395283080383565792233554007 \cdot 10^{49}:\\ \;\;\;\;\left(a + z\right) - b\\ \mathbf{elif}\;y \le 2.740519347061663533893075988126946093752 \cdot 10^{102}:\\ \;\;\;\;\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.377781447530395283080383565792233554007 \cdot 10^{49}:\\
\;\;\;\;\left(a + z\right) - b\\

\mathbf{elif}\;y \le 2.740519347061663533893075988126946093752 \cdot 10^{102}:\\
\;\;\;\;\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 r25039441 = x;
        double r25039442 = y;
        double r25039443 = r25039441 + r25039442;
        double r25039444 = z;
        double r25039445 = r25039443 * r25039444;
        double r25039446 = t;
        double r25039447 = r25039446 + r25039442;
        double r25039448 = a;
        double r25039449 = r25039447 * r25039448;
        double r25039450 = r25039445 + r25039449;
        double r25039451 = b;
        double r25039452 = r25039442 * r25039451;
        double r25039453 = r25039450 - r25039452;
        double r25039454 = r25039441 + r25039446;
        double r25039455 = r25039454 + r25039442;
        double r25039456 = r25039453 / r25039455;
        return r25039456;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r25039457 = y;
        double r25039458 = -1.3777814475303953e+49;
        bool r25039459 = r25039457 <= r25039458;
        double r25039460 = a;
        double r25039461 = z;
        double r25039462 = r25039460 + r25039461;
        double r25039463 = b;
        double r25039464 = r25039462 - r25039463;
        double r25039465 = 2.7405193470616635e+102;
        bool r25039466 = r25039457 <= r25039465;
        double r25039467 = x;
        double r25039468 = r25039457 + r25039467;
        double r25039469 = t;
        double r25039470 = r25039469 + r25039457;
        double r25039471 = r25039460 * r25039470;
        double r25039472 = fma(r25039468, r25039461, r25039471);
        double r25039473 = r25039457 * r25039463;
        double r25039474 = r25039472 - r25039473;
        double r25039475 = r25039470 + r25039467;
        double r25039476 = r25039474 / r25039475;
        double r25039477 = r25039466 ? r25039476 : r25039464;
        double r25039478 = r25039459 ? r25039464 : r25039477;
        return r25039478;
}

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.3
Herbie15.9
\[\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.3777814475303953e+49 or 2.7405193470616635e+102 < y

    1. Initial program 43.2

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

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

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

    if -1.3777814475303953e+49 < y < 2.7405193470616635e+102

    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. Recombined 2 regimes into one program.
  4. Final simplification15.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.377781447530395283080383565792233554007 \cdot 10^{49}:\\ \;\;\;\;\left(a + z\right) - b\\ \mathbf{elif}\;y \le 2.740519347061663533893075988126946093752 \cdot 10^{102}:\\ \;\;\;\;\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 2019174 +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)))