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

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

\end{array}\\

\mathbf{elif}\;b \le 5.139720957774800459105165687985873103887 \cdot 10^{144}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\

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

\end{array}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r32455 = b;
        double r32456 = 0.0;
        bool r32457 = r32455 >= r32456;
        double r32458 = 2.0;
        double r32459 = c;
        double r32460 = r32458 * r32459;
        double r32461 = -r32455;
        double r32462 = r32455 * r32455;
        double r32463 = 4.0;
        double r32464 = a;
        double r32465 = r32463 * r32464;
        double r32466 = r32465 * r32459;
        double r32467 = r32462 - r32466;
        double r32468 = sqrt(r32467);
        double r32469 = r32461 - r32468;
        double r32470 = r32460 / r32469;
        double r32471 = r32461 + r32468;
        double r32472 = r32458 * r32464;
        double r32473 = r32471 / r32472;
        double r32474 = r32457 ? r32470 : r32473;
        return r32474;
}

double f(double a, double b, double c) {
        double r32475 = b;
        double r32476 = -5.105369019268964e+141;
        bool r32477 = r32475 <= r32476;
        double r32478 = 0.0;
        bool r32479 = r32475 >= r32478;
        double r32480 = 2.0;
        double r32481 = c;
        double r32482 = r32480 * r32481;
        double r32483 = -r32475;
        double r32484 = r32475 * r32475;
        double r32485 = 4.0;
        double r32486 = a;
        double r32487 = r32485 * r32486;
        double r32488 = r32487 * r32481;
        double r32489 = r32484 - r32488;
        double r32490 = sqrt(r32489);
        double r32491 = r32483 - r32490;
        double r32492 = r32482 / r32491;
        double r32493 = r32486 * r32481;
        double r32494 = r32493 / r32475;
        double r32495 = -2.0;
        double r32496 = r32495 * r32475;
        double r32497 = fma(r32480, r32494, r32496);
        double r32498 = r32497 / r32480;
        double r32499 = r32498 / r32486;
        double r32500 = r32479 ? r32492 : r32499;
        double r32501 = 5.1397209577748005e+144;
        bool r32502 = r32475 <= r32501;
        double r32503 = cbrt(r32489);
        double r32504 = fabs(r32503);
        double r32505 = cbrt(r32490);
        double r32506 = sqrt(r32490);
        double r32507 = r32505 * r32505;
        double r32508 = r32507 * r32505;
        double r32509 = sqrt(r32508);
        double r32510 = r32506 * r32509;
        double r32511 = cbrt(r32510);
        double r32512 = r32505 * r32511;
        double r32513 = sqrt(r32512);
        double r32514 = r32504 * r32513;
        double r32515 = r32514 - r32475;
        double r32516 = r32515 / r32480;
        double r32517 = r32516 / r32486;
        double r32518 = r32479 ? r32492 : r32517;
        double r32519 = r32480 * r32494;
        double r32520 = r32475 - r32519;
        double r32521 = r32483 - r32520;
        double r32522 = r32482 / r32521;
        double r32523 = r32490 - r32475;
        double r32524 = r32523 / r32480;
        double r32525 = r32524 / r32486;
        double r32526 = r32479 ? r32522 : r32525;
        double r32527 = r32502 ? r32518 : r32526;
        double r32528 = r32477 ? r32500 : r32527;
        return r32528;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

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

    1. Initial program 60.4

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

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

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

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

    if -5.105369019268964e+141 < b < 5.1397209577748005e+144

    1. Initial program 8.2

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\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}{2}}{a}\\ \end{array}\]
    5. Applied sqrt-prod8.4

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\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}{2}}{a}\\ \end{array}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt8.4

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\left|\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}\right| \cdot \sqrt{\sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}} - b}{2}}{a}\\ \end{array}\]
    10. Using strategy rm
    11. Applied add-sqr-sqrt8.4

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

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

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

    if 5.1397209577748005e+144 < b

    1. Initial program 36.4

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -5.105369019268963816293244653075052742799 \cdot 10^{141}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(2, \frac{a \cdot c}{b}, -2 \cdot b\right)}{2}}{a}\\ \end{array}\\ \mathbf{elif}\;b \le 5.139720957774800459105165687985873103887 \cdot 10^{144}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\left|\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}\right| \cdot \sqrt{\sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt[3]{\sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\left(\sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\right) \cdot \sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}} - b}{2}}{a}\\ \end{array}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left(b - 2 \cdot \frac{a \cdot c}{b}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}{a}\\ \end{array}\]

Reproduce

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