Average Error: 19.9 → 7.2
Time: 18.2s
Precision: 64
\[\begin{array}{l} \mathbf{if}\;b \ge 0.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 -2.415824536209924848227828718073588940264 \cdot 10^{141}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.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(2 \cdot \left(\frac{a}{\sqrt[3]{b} \cdot \sqrt[3]{b}} \cdot \frac{c}{\sqrt[3]{b}}\right) - b\right) - b}\\ \end{array}\\ \mathbf{elif}\;b \le 4.623731436085776951393488738523920016456 \cdot 10^{144}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.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|\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}\right| \cdot \sqrt{\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}} - b}\\ \end{array}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;\frac{\mathsf{fma}\left(2, \frac{a \cdot c}{b}, -2 \cdot b\right)}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}\\ \end{array}\]
\begin{array}{l}
\mathbf{if}\;b \ge 0.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 -2.415824536209924848227828718073588940264 \cdot 10^{141}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0.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(2 \cdot \left(\frac{a}{\sqrt[3]{b} \cdot \sqrt[3]{b}} \cdot \frac{c}{\sqrt[3]{b}}\right) - b\right) - b}\\

\end{array}\\

\mathbf{elif}\;b \le 4.623731436085776951393488738523920016456 \cdot 10^{144}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0.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|\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}\right| \cdot \sqrt{\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}} - b}\\

\end{array}\\

\mathbf{elif}\;b \ge 0.0:\\
\;\;\;\;\frac{\mathsf{fma}\left(2, \frac{a \cdot c}{b}, -2 \cdot b\right)}{2 \cdot a}\\

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

\end{array}
double f(double a, double b, double c) {
        double r33458 = b;
        double r33459 = 0.0;
        bool r33460 = r33458 >= r33459;
        double r33461 = -r33458;
        double r33462 = r33458 * r33458;
        double r33463 = 4.0;
        double r33464 = a;
        double r33465 = r33463 * r33464;
        double r33466 = c;
        double r33467 = r33465 * r33466;
        double r33468 = r33462 - r33467;
        double r33469 = sqrt(r33468);
        double r33470 = r33461 - r33469;
        double r33471 = 2.0;
        double r33472 = r33471 * r33464;
        double r33473 = r33470 / r33472;
        double r33474 = r33471 * r33466;
        double r33475 = r33461 + r33469;
        double r33476 = r33474 / r33475;
        double r33477 = r33460 ? r33473 : r33476;
        return r33477;
}

double f(double a, double b, double c) {
        double r33478 = b;
        double r33479 = -2.415824536209925e+141;
        bool r33480 = r33478 <= r33479;
        double r33481 = 0.0;
        bool r33482 = r33478 >= r33481;
        double r33483 = -r33478;
        double r33484 = r33478 * r33478;
        double r33485 = 4.0;
        double r33486 = a;
        double r33487 = r33485 * r33486;
        double r33488 = c;
        double r33489 = r33487 * r33488;
        double r33490 = r33484 - r33489;
        double r33491 = sqrt(r33490);
        double r33492 = r33483 - r33491;
        double r33493 = 2.0;
        double r33494 = r33493 * r33486;
        double r33495 = r33492 / r33494;
        double r33496 = r33493 * r33488;
        double r33497 = cbrt(r33478);
        double r33498 = r33497 * r33497;
        double r33499 = r33486 / r33498;
        double r33500 = r33488 / r33497;
        double r33501 = r33499 * r33500;
        double r33502 = r33493 * r33501;
        double r33503 = r33502 - r33478;
        double r33504 = r33503 - r33478;
        double r33505 = r33496 / r33504;
        double r33506 = r33482 ? r33495 : r33505;
        double r33507 = 4.623731436085777e+144;
        bool r33508 = r33478 <= r33507;
        double r33509 = cbrt(r33490);
        double r33510 = fabs(r33509);
        double r33511 = sqrt(r33509);
        double r33512 = r33510 * r33511;
        double r33513 = r33512 - r33478;
        double r33514 = r33496 / r33513;
        double r33515 = r33482 ? r33495 : r33514;
        double r33516 = r33486 * r33488;
        double r33517 = r33516 / r33478;
        double r33518 = -2.0;
        double r33519 = r33518 * r33478;
        double r33520 = fma(r33493, r33517, r33519);
        double r33521 = r33520 / r33494;
        double r33522 = r33491 - r33478;
        double r33523 = r33496 / r33522;
        double r33524 = r33482 ? r33521 : r33523;
        double r33525 = r33508 ? r33515 : r33524;
        double r33526 = r33480 ? r33506 : r33525;
        return r33526;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 3 regimes
  2. if b < -2.415824536209925e+141

    1. Initial program 36.1

      \[\begin{array}{l} \mathbf{if}\;b \ge 0.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. Simplified36.1

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \ge 0.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}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}\\ \end{array}}\]
    3. Taylor expanded around -inf 6.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{\color{blue}{2 \cdot c}}{\left(2 \cdot \frac{a \cdot c}{b} - b\right) - b}\\ \end{array}\]
    4. Using strategy rm
    5. Applied add-cube-cbrt6.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.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(2 \cdot \frac{a \cdot c}{\left(\sqrt[3]{b} \cdot \sqrt[3]{b}\right) \cdot \sqrt[3]{b}} - b\right) - b}\\ \end{array}\]
    6. Applied times-frac1.2

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.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(2 \cdot \left(\frac{a}{\sqrt[3]{b} \cdot \sqrt[3]{b}} \cdot \frac{c}{\sqrt[3]{b}}\right) - b\right) - b}\\ \end{array}\]

    if -2.415824536209925e+141 < b < 4.623731436085777e+144

    1. Initial program 8.3

      \[\begin{array}{l} \mathbf{if}\;b \ge 0.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. Simplified8.3

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \ge 0.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}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}\\ \end{array}}\]
    3. Using strategy rm
    4. Applied add-cube-cbrt8.5

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{\color{blue}{2 \cdot c}}{\sqrt{\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}} - b}\\ \end{array}\]
    6. Simplified8.5

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

    if 4.623731436085777e+144 < b

    1. Initial program 59.8

      \[\begin{array}{l} \mathbf{if}\;b \ge 0.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. Simplified59.8

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \ge 0.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}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}\\ \end{array}}\]
    3. Taylor expanded around inf 10.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.415824536209924848227828718073588940264 \cdot 10^{141}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.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(2 \cdot \left(\frac{a}{\sqrt[3]{b} \cdot \sqrt[3]{b}} \cdot \frac{c}{\sqrt[3]{b}}\right) - b\right) - b}\\ \end{array}\\ \mathbf{elif}\;b \le 4.623731436085776951393488738523920016456 \cdot 10^{144}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.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|\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}\right| \cdot \sqrt{\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}} - b}\\ \end{array}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;\frac{\mathsf{fma}\left(2, \frac{a \cdot c}{b}, -2 \cdot b\right)}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}\\ \end{array}\]

Reproduce

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