Average Error: 27.0 → 14.7
Time: 19.4s
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 -2.02509966178956068764645940207030966215 \cdot 10^{48}:\\ \;\;\;\;\left(a + z\right) - \frac{y}{\left(y + t\right) + x} \cdot b\\ \mathbf{elif}\;y \le 6.969158922345329457700669137109401128173 \cdot 10^{-157}:\\ \;\;\;\;\frac{1}{\frac{\left(y + t\right) + x}{\mathsf{fma}\left(b, -y, \mathsf{fma}\left(y + t, a, z \cdot \left(y + x\right)\right)\right)}}\\ \mathbf{elif}\;y \le 1.393749186532247507350391500444142245385 \cdot 10^{-9} \lor \neg \left(y \le 3.052020515903186671430155196512088928835 \cdot 10^{101}\right):\\ \;\;\;\;\left(a + z\right) - \frac{y}{\left(y + t\right) + x} \cdot b\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y + t, a, z \cdot \left(y + x\right)\right)}{\left(y + t\right) + x} - y \cdot \frac{b}{\left(y + t\right) + x}\\ \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 -2.02509966178956068764645940207030966215 \cdot 10^{48}:\\
\;\;\;\;\left(a + z\right) - \frac{y}{\left(y + t\right) + x} \cdot b\\

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

\mathbf{elif}\;y \le 1.393749186532247507350391500444142245385 \cdot 10^{-9} \lor \neg \left(y \le 3.052020515903186671430155196512088928835 \cdot 10^{101}\right):\\
\;\;\;\;\left(a + z\right) - \frac{y}{\left(y + t\right) + x} \cdot b\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r630805 = x;
        double r630806 = y;
        double r630807 = r630805 + r630806;
        double r630808 = z;
        double r630809 = r630807 * r630808;
        double r630810 = t;
        double r630811 = r630810 + r630806;
        double r630812 = a;
        double r630813 = r630811 * r630812;
        double r630814 = r630809 + r630813;
        double r630815 = b;
        double r630816 = r630806 * r630815;
        double r630817 = r630814 - r630816;
        double r630818 = r630805 + r630810;
        double r630819 = r630818 + r630806;
        double r630820 = r630817 / r630819;
        return r630820;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r630821 = y;
        double r630822 = -2.0250996617895607e+48;
        bool r630823 = r630821 <= r630822;
        double r630824 = a;
        double r630825 = z;
        double r630826 = r630824 + r630825;
        double r630827 = t;
        double r630828 = r630821 + r630827;
        double r630829 = x;
        double r630830 = r630828 + r630829;
        double r630831 = r630821 / r630830;
        double r630832 = b;
        double r630833 = r630831 * r630832;
        double r630834 = r630826 - r630833;
        double r630835 = 6.96915892234533e-157;
        bool r630836 = r630821 <= r630835;
        double r630837 = 1.0;
        double r630838 = -r630821;
        double r630839 = r630821 + r630829;
        double r630840 = r630825 * r630839;
        double r630841 = fma(r630828, r630824, r630840);
        double r630842 = fma(r630832, r630838, r630841);
        double r630843 = r630830 / r630842;
        double r630844 = r630837 / r630843;
        double r630845 = 1.3937491865322475e-09;
        bool r630846 = r630821 <= r630845;
        double r630847 = 3.0520205159031867e+101;
        bool r630848 = r630821 <= r630847;
        double r630849 = !r630848;
        bool r630850 = r630846 || r630849;
        double r630851 = r630841 / r630830;
        double r630852 = r630832 / r630830;
        double r630853 = r630821 * r630852;
        double r630854 = r630851 - r630853;
        double r630855 = r630850 ? r630834 : r630854;
        double r630856 = r630836 ? r630844 : r630855;
        double r630857 = r630823 ? r630834 : r630856;
        return r630857;
}

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
Herbie14.7
\[\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 < -2.0250996617895607e+48 or 6.96915892234533e-157 < y < 1.3937491865322475e-09 or 3.0520205159031867e+101 < y

    1. Initial program 36.4

      \[\frac{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y}\]
    2. Using strategy rm
    3. Applied div-sub36.4

      \[\leadsto \color{blue}{\frac{\left(x + y\right) \cdot z + \left(t + y\right) \cdot a}{\left(x + t\right) + y} - \frac{y \cdot b}{\left(x + t\right) + y}}\]
    4. Simplified36.4

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

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

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

    if -2.0250996617895607e+48 < y < 6.96915892234533e-157

    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. Using strategy rm
    3. Applied clear-num16.1

      \[\leadsto \color{blue}{\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}}}\]
    4. Simplified16.1

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

    if 1.3937491865322475e-09 < y < 3.0520205159031867e+101

    1. Initial program 23.7

      \[\frac{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y}\]
    2. Using strategy rm
    3. Applied div-sub23.7

      \[\leadsto \color{blue}{\frac{\left(x + y\right) \cdot z + \left(t + y\right) \cdot a}{\left(x + t\right) + y} - \frac{y \cdot b}{\left(x + t\right) + y}}\]
    4. Simplified23.7

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

      \[\leadsto \frac{\mathsf{fma}\left(y + t, a, \left(y + x\right) \cdot z\right)}{x + \left(y + t\right)} - \color{blue}{\frac{y}{x + \left(y + t\right)} \cdot b}\]
    6. Using strategy rm
    7. Applied div-inv20.7

      \[\leadsto \frac{\mathsf{fma}\left(y + t, a, \left(y + x\right) \cdot z\right)}{x + \left(y + t\right)} - \color{blue}{\left(y \cdot \frac{1}{x + \left(y + t\right)}\right)} \cdot b\]
    8. Applied associate-*l*20.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -2.02509966178956068764645940207030966215 \cdot 10^{48}:\\ \;\;\;\;\left(a + z\right) - \frac{y}{\left(y + t\right) + x} \cdot b\\ \mathbf{elif}\;y \le 6.969158922345329457700669137109401128173 \cdot 10^{-157}:\\ \;\;\;\;\frac{1}{\frac{\left(y + t\right) + x}{\mathsf{fma}\left(b, -y, \mathsf{fma}\left(y + t, a, z \cdot \left(y + x\right)\right)\right)}}\\ \mathbf{elif}\;y \le 1.393749186532247507350391500444142245385 \cdot 10^{-9} \lor \neg \left(y \le 3.052020515903186671430155196512088928835 \cdot 10^{101}\right):\\ \;\;\;\;\left(a + z\right) - \frac{y}{\left(y + t\right) + x} \cdot b\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y + t, a, z \cdot \left(y + x\right)\right)}{\left(y + t\right) + x} - y \cdot \frac{b}{\left(y + t\right) + x}\\ \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)))