Average Error: 18.9 → 12.8
Time: 18.5s
Precision: 64
\[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
\[\begin{array}{l} \mathbf{if}\;b \le 5.005151079924739 \cdot 10^{+122}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\sqrt{\mathsf{fma}\left(\left(a \cdot -4\right), c, \left(b \cdot b\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(\left(a \cdot -4\right), c, \left(b \cdot b\right)\right)}}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{\mathsf{fma}\left(\left(a \cdot -4\right), c, \left(b \cdot b\right)\right)} - b}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{\mathsf{fma}\left(\left(a \cdot -4\right), c, \left(b \cdot b\right)\right)} - b}\\ \end{array}\]
\begin{array}{l}
\mathbf{if}\;b \ge 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\

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

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

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

\end{array}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r431234 = b;
        double r431235 = 0.0;
        bool r431236 = r431234 >= r431235;
        double r431237 = -r431234;
        double r431238 = r431234 * r431234;
        double r431239 = 4.0;
        double r431240 = a;
        double r431241 = r431239 * r431240;
        double r431242 = c;
        double r431243 = r431241 * r431242;
        double r431244 = r431238 - r431243;
        double r431245 = sqrt(r431244);
        double r431246 = r431237 - r431245;
        double r431247 = 2.0;
        double r431248 = r431247 * r431240;
        double r431249 = r431246 / r431248;
        double r431250 = r431247 * r431242;
        double r431251 = r431237 + r431245;
        double r431252 = r431250 / r431251;
        double r431253 = r431236 ? r431249 : r431252;
        return r431253;
}

double f(double a, double b, double c) {
        double r431254 = b;
        double r431255 = 5.005151079924739e+122;
        bool r431256 = r431254 <= r431255;
        double r431257 = 0.0;
        bool r431258 = r431254 >= r431257;
        double r431259 = -r431254;
        double r431260 = a;
        double r431261 = -4.0;
        double r431262 = r431260 * r431261;
        double r431263 = c;
        double r431264 = r431254 * r431254;
        double r431265 = fma(r431262, r431263, r431264);
        double r431266 = sqrt(r431265);
        double r431267 = sqrt(r431266);
        double r431268 = r431267 * r431267;
        double r431269 = r431259 - r431268;
        double r431270 = 2.0;
        double r431271 = r431260 * r431270;
        double r431272 = r431269 / r431271;
        double r431273 = r431263 * r431270;
        double r431274 = r431266 - r431254;
        double r431275 = r431273 / r431274;
        double r431276 = r431258 ? r431272 : r431275;
        double r431277 = r431259 - r431254;
        double r431278 = r431277 / r431271;
        double r431279 = r431258 ? r431278 : r431275;
        double r431280 = r431256 ? r431276 : r431279;
        return r431280;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 2 regimes
  2. if b < 5.005151079924739e+122

    1. Initial program 14.1

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

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

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

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

    if 5.005151079924739e+122 < b

    1. Initial program 50.0

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

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

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

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

Reproduce

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