Average Error: 27.1 → 16.4
Time: 23.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 r559132 = x;
        double r559133 = y;
        double r559134 = r559132 + r559133;
        double r559135 = z;
        double r559136 = r559134 * r559135;
        double r559137 = t;
        double r559138 = r559137 + r559133;
        double r559139 = a;
        double r559140 = r559138 * r559139;
        double r559141 = r559136 + r559140;
        double r559142 = b;
        double r559143 = r559133 * r559142;
        double r559144 = r559141 - r559143;
        double r559145 = r559132 + r559137;
        double r559146 = r559145 + r559133;
        double r559147 = r559144 / r559146;
        return r559147;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r559148 = y;
        double r559149 = -9.283225756149319e+114;
        bool r559150 = r559148 <= r559149;
        double r559151 = 3.39454492032664e+38;
        bool r559152 = r559148 <= r559151;
        double r559153 = !r559152;
        bool r559154 = r559150 || r559153;
        double r559155 = a;
        double r559156 = z;
        double r559157 = r559155 + r559156;
        double r559158 = b;
        double r559159 = r559157 - r559158;
        double r559160 = t;
        double r559161 = r559160 + r559148;
        double r559162 = x;
        double r559163 = r559156 - r559158;
        double r559164 = r559148 * r559163;
        double r559165 = fma(r559162, r559156, r559164);
        double r559166 = fma(r559155, r559161, r559165);
        double r559167 = 1.0;
        double r559168 = r559162 + r559160;
        double r559169 = r559168 + r559148;
        double r559170 = r559167 / r559169;
        double r559171 = r559166 * r559170;
        double r559172 = r559154 ? r559159 : r559171;
        return r559172;
}

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