Average Error: 34.2 → 15.4
Time: 5.5s
Precision: 64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -2.0697892322852844 \cdot 10^{57}:\\ \;\;\;\;\frac{\left(-b\right) + \left(2 \cdot \frac{a \cdot c}{b} - b\right)}{2 \cdot a}\\ \mathbf{elif}\;b \le 5.08229739317807349 \cdot 10^{-29}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\sqrt[3]{-b} \cdot \sqrt[3]{-b}, \sqrt[3]{-b}, \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2 \cdot \frac{a \cdot c}{b}}{2 \cdot a}\\ \end{array}\]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \le -2.0697892322852844 \cdot 10^{57}:\\
\;\;\;\;\frac{\left(-b\right) + \left(2 \cdot \frac{a \cdot c}{b} - b\right)}{2 \cdot a}\\

\mathbf{elif}\;b \le 5.08229739317807349 \cdot 10^{-29}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\sqrt[3]{-b} \cdot \sqrt[3]{-b}, \sqrt[3]{-b}, \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}{2 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;\frac{-2 \cdot \frac{a \cdot c}{b}}{2 \cdot a}\\

\end{array}
double f(double a, double b, double c) {
        double r58503 = b;
        double r58504 = -r58503;
        double r58505 = r58503 * r58503;
        double r58506 = 4.0;
        double r58507 = a;
        double r58508 = r58506 * r58507;
        double r58509 = c;
        double r58510 = r58508 * r58509;
        double r58511 = r58505 - r58510;
        double r58512 = sqrt(r58511);
        double r58513 = r58504 + r58512;
        double r58514 = 2.0;
        double r58515 = r58514 * r58507;
        double r58516 = r58513 / r58515;
        return r58516;
}

double f(double a, double b, double c) {
        double r58517 = b;
        double r58518 = -2.0697892322852844e+57;
        bool r58519 = r58517 <= r58518;
        double r58520 = -r58517;
        double r58521 = 2.0;
        double r58522 = a;
        double r58523 = c;
        double r58524 = r58522 * r58523;
        double r58525 = r58524 / r58517;
        double r58526 = r58521 * r58525;
        double r58527 = r58526 - r58517;
        double r58528 = r58520 + r58527;
        double r58529 = r58521 * r58522;
        double r58530 = r58528 / r58529;
        double r58531 = 5.082297393178073e-29;
        bool r58532 = r58517 <= r58531;
        double r58533 = cbrt(r58520);
        double r58534 = r58533 * r58533;
        double r58535 = r58517 * r58517;
        double r58536 = 4.0;
        double r58537 = r58536 * r58522;
        double r58538 = r58537 * r58523;
        double r58539 = r58535 - r58538;
        double r58540 = sqrt(r58539);
        double r58541 = fma(r58534, r58533, r58540);
        double r58542 = r58541 / r58529;
        double r58543 = -2.0;
        double r58544 = r58543 * r58525;
        double r58545 = r58544 / r58529;
        double r58546 = r58532 ? r58542 : r58545;
        double r58547 = r58519 ? r58530 : r58546;
        return r58547;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 3 regimes
  2. if b < -2.0697892322852844e+57

    1. Initial program 39.1

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Taylor expanded around -inf 10.0

      \[\leadsto \frac{\left(-b\right) + \color{blue}{\left(2 \cdot \frac{a \cdot c}{b} - b\right)}}{2 \cdot a}\]

    if -2.0697892322852844e+57 < b < 5.082297393178073e-29

    1. Initial program 16.0

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied add-cube-cbrt16.2

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{-b} \cdot \sqrt[3]{-b}\right) \cdot \sqrt[3]{-b}} + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    4. Applied fma-def16.2

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\sqrt[3]{-b} \cdot \sqrt[3]{-b}, \sqrt[3]{-b}, \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}{2 \cdot a}\]

    if 5.082297393178073e-29 < b

    1. Initial program 54.3

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Taylor expanded around inf 17.5

      \[\leadsto \frac{\color{blue}{-2 \cdot \frac{a \cdot c}{b}}}{2 \cdot a}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification15.4

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

Reproduce

herbie shell --seed 2020033 +o rules:numerics
(FPCore (a b c)
  :name "Quadratic roots, full range"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))