Average Error: 19.0 → 13.2
Time: 1.1m
Precision: 64
\[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
\[\begin{array}{l} \mathbf{if}\;b \le 3.451238017257403 \cdot 10^{+79}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)} - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)} - b}{2 \cdot a}\\ \end{array}\]
\begin{array}{l}
\mathbf{if}\;b \ge 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\

\end{array}
\begin{array}{l}
\mathbf{if}\;b \le 3.451238017257403 \cdot 10^{+79}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)}}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)} - b}{2 \cdot a}\\

\end{array}\\

\mathbf{elif}\;b \ge 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\

\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)} - b}{2 \cdot a}\\

\end{array}
double f(double a, double b, double c) {
        double r2496985 = b;
        double r2496986 = 0.0;
        bool r2496987 = r2496985 >= r2496986;
        double r2496988 = 2.0;
        double r2496989 = c;
        double r2496990 = r2496988 * r2496989;
        double r2496991 = -r2496985;
        double r2496992 = r2496985 * r2496985;
        double r2496993 = 4.0;
        double r2496994 = a;
        double r2496995 = r2496993 * r2496994;
        double r2496996 = r2496995 * r2496989;
        double r2496997 = r2496992 - r2496996;
        double r2496998 = sqrt(r2496997);
        double r2496999 = r2496991 - r2496998;
        double r2497000 = r2496990 / r2496999;
        double r2497001 = r2496991 + r2496998;
        double r2497002 = r2496988 * r2496994;
        double r2497003 = r2497001 / r2497002;
        double r2497004 = r2496987 ? r2497000 : r2497003;
        return r2497004;
}

double f(double a, double b, double c) {
        double r2497005 = b;
        double r2497006 = 3.451238017257403e+79;
        bool r2497007 = r2497005 <= r2497006;
        double r2497008 = 0.0;
        bool r2497009 = r2497005 >= r2497008;
        double r2497010 = 2.0;
        double r2497011 = c;
        double r2497012 = r2497010 * r2497011;
        double r2497013 = -r2497005;
        double r2497014 = -4.0;
        double r2497015 = a;
        double r2497016 = r2497015 * r2497011;
        double r2497017 = r2497005 * r2497005;
        double r2497018 = fma(r2497014, r2497016, r2497017);
        double r2497019 = sqrt(r2497018);
        double r2497020 = sqrt(r2497019);
        double r2497021 = r2497020 * r2497020;
        double r2497022 = r2497013 - r2497021;
        double r2497023 = r2497012 / r2497022;
        double r2497024 = r2497019 - r2497005;
        double r2497025 = r2497010 * r2497015;
        double r2497026 = r2497024 / r2497025;
        double r2497027 = r2497009 ? r2497023 : r2497026;
        double r2497028 = r2497013 - r2497005;
        double r2497029 = r2497012 / r2497028;
        double r2497030 = r2497009 ? r2497029 : r2497026;
        double r2497031 = r2497007 ? r2497027 : r2497030;
        return r2497031;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 2 regimes
  2. if b < 3.451238017257403e+79

    1. Initial program 16.4

      \[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
    2. Simplified16.4

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)} - b}{2 \cdot a}\\ \end{array}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt16.4

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\color{blue}{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)} \cdot \sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)} - b}{2 \cdot a}\\ \end{array}\]
    5. Applied sqrt-prod16.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{\sqrt{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)} - b}{2 \cdot a}\\ \end{array}\]

    if 3.451238017257403e+79 < b

    1. Initial program 26.9

      \[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
    2. Simplified26.8

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)} - b}{2 \cdot a}\\ \end{array}}\]
    3. Taylor expanded around 0 3.3

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)} - b}{2 \cdot a}\\ \end{array}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification13.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le 3.451238017257403 \cdot 10^{+79}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)} - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)} - b}{2 \cdot a}\\ \end{array}\]

Reproduce

herbie shell --seed 2019125 +o rules:numerics
(FPCore (a b c)
  :name "jeff quadratic root 2"
  (if (>= b 0) (/ (* 2 c) (- (- b) (sqrt (- (* b b) (* (* 4 a) c))))) (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a))))