Average Error: 19.8 → 7.5
Time: 21.7s
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 -1.350676057343211554491874986591947593393 \cdot 10^{154}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(\frac{a}{\sqrt{b}} \cdot \frac{c}{\sqrt{b}}, 2, b \cdot -2\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \left(2 \cdot \frac{a \cdot c}{b} - b\right)}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \le -4.452231346955637703324616244948712027068 \cdot 10^{-267}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\frac{\left(4 \cdot a\right) \cdot c}{\sqrt{\mathsf{fma}\left(b, b, -\left(4 \cdot a\right) \cdot c\right)} - b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \le 1.287594296476507417293820707954348336152 \cdot 10^{78}:\\ \;\;\;\;\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(a \cdot c\right) \cdot 4}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(\frac{a}{\sqrt{b}} \cdot \frac{c}{\sqrt{b}}, 2, b \cdot -2\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \left(2 \cdot \frac{a \cdot c}{b} - b\right)}{2 \cdot 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 -1.350676057343211554491874986591947593393 \cdot 10^{154}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(\frac{a}{\sqrt{b}} \cdot \frac{c}{\sqrt{b}}, 2, b \cdot -2\right)}\\

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

\end{array}\\

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

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

\end{array}\\

\mathbf{elif}\;b \le 1.287594296476507417293820707954348336152 \cdot 10^{78}:\\
\;\;\;\;\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(a \cdot c\right) \cdot 4}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\

\end{array}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r32482 = b;
        double r32483 = 0.0;
        bool r32484 = r32482 >= r32483;
        double r32485 = 2.0;
        double r32486 = c;
        double r32487 = r32485 * r32486;
        double r32488 = -r32482;
        double r32489 = r32482 * r32482;
        double r32490 = 4.0;
        double r32491 = a;
        double r32492 = r32490 * r32491;
        double r32493 = r32492 * r32486;
        double r32494 = r32489 - r32493;
        double r32495 = sqrt(r32494);
        double r32496 = r32488 - r32495;
        double r32497 = r32487 / r32496;
        double r32498 = r32488 + r32495;
        double r32499 = r32485 * r32491;
        double r32500 = r32498 / r32499;
        double r32501 = r32484 ? r32497 : r32500;
        return r32501;
}

double f(double a, double b, double c) {
        double r32502 = b;
        double r32503 = -1.3506760573432116e+154;
        bool r32504 = r32502 <= r32503;
        double r32505 = 0.0;
        bool r32506 = r32502 >= r32505;
        double r32507 = 2.0;
        double r32508 = c;
        double r32509 = r32507 * r32508;
        double r32510 = a;
        double r32511 = sqrt(r32502);
        double r32512 = r32510 / r32511;
        double r32513 = r32508 / r32511;
        double r32514 = r32512 * r32513;
        double r32515 = -2.0;
        double r32516 = r32502 * r32515;
        double r32517 = fma(r32514, r32507, r32516);
        double r32518 = r32509 / r32517;
        double r32519 = -r32502;
        double r32520 = r32510 * r32508;
        double r32521 = r32520 / r32502;
        double r32522 = r32507 * r32521;
        double r32523 = r32522 - r32502;
        double r32524 = r32519 + r32523;
        double r32525 = r32507 * r32510;
        double r32526 = r32524 / r32525;
        double r32527 = r32506 ? r32518 : r32526;
        double r32528 = -4.452231346955638e-267;
        bool r32529 = r32502 <= r32528;
        double r32530 = 4.0;
        double r32531 = r32530 * r32510;
        double r32532 = r32531 * r32508;
        double r32533 = -r32532;
        double r32534 = fma(r32502, r32502, r32533);
        double r32535 = sqrt(r32534);
        double r32536 = r32535 - r32502;
        double r32537 = r32532 / r32536;
        double r32538 = r32509 / r32537;
        double r32539 = r32502 * r32502;
        double r32540 = r32539 - r32532;
        double r32541 = sqrt(r32540);
        double r32542 = r32519 + r32541;
        double r32543 = r32542 / r32525;
        double r32544 = r32506 ? r32538 : r32543;
        double r32545 = 1.2875942964765074e+78;
        bool r32546 = r32502 <= r32545;
        double r32547 = r32519 - r32541;
        double r32548 = r32509 / r32547;
        double r32549 = r32520 * r32530;
        double r32550 = r32549 / r32547;
        double r32551 = r32550 / r32525;
        double r32552 = r32506 ? r32548 : r32551;
        double r32553 = r32546 ? r32552 : r32527;
        double r32554 = r32529 ? r32544 : r32553;
        double r32555 = r32504 ? r32527 : r32554;
        return r32555;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 3 regimes
  2. if b < -1.3506760573432116e+154 or 1.2875942964765074e+78 < b

    1. Initial program 38.5

      \[\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. Taylor expanded around inf 24.0

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

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

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

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

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

    if -1.3506760573432116e+154 < b < -4.452231346955638e-267

    1. Initial program 7.7

      \[\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. Using strategy rm
    3. Applied flip--7.7

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\frac{\color{blue}{0 + c \cdot \left(4 \cdot a\right)}}{\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}\]
    5. Simplified7.7

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

    if -4.452231346955638e-267 < b < 1.2875942964765074e+78

    1. Initial program 9.5

      \[\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. Using strategy rm
    3. Applied add-sqr-sqrt9.5

      \[\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{\left(-b\right) + \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \end{array}\]
    4. Applied sqrt-prod9.5

      \[\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{\left(-b\right) + \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}}}{2 \cdot a}\\ \end{array}\]
    5. Simplified9.5

      \[\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{\left(-b\right) + \sqrt{\sqrt{\mathsf{fma}\left(b, b, -\left(4 \cdot a\right) \cdot c\right)}} \cdot \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \end{array}\]
    6. Simplified9.5

      \[\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{\left(-b\right) + \sqrt{\sqrt{\mathsf{fma}\left(b, b, -\left(4 \cdot a\right) \cdot c\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(b, b, -\left(4 \cdot a\right) \cdot c\right)}}}{2 \cdot a}\\ \end{array}\]
    7. Using strategy rm
    8. Applied flip-+9.5

      \[\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(-b\right) \cdot \left(-b\right) - \left(\sqrt{\sqrt{\mathsf{fma}\left(b, b, -\left(4 \cdot a\right) \cdot c\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(b, b, -\left(4 \cdot a\right) \cdot c\right)}}\right) \cdot \left(\sqrt{\sqrt{\mathsf{fma}\left(b, b, -\left(4 \cdot a\right) \cdot c\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(b, b, -\left(4 \cdot a\right) \cdot c\right)}}\right)}{\left(-b\right) - \sqrt{\sqrt{\mathsf{fma}\left(b, b, -\left(4 \cdot a\right) \cdot c\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(b, b, -\left(4 \cdot a\right) \cdot c\right)}}}}{2 \cdot a}\\ \end{array}\]
    9. Simplified9.5

      \[\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(a \cdot c\right) \cdot 4}{\left(-b\right) - \sqrt{\sqrt{\mathsf{fma}\left(b, b, -\left(4 \cdot a\right) \cdot c\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(b, b, -\left(4 \cdot a\right) \cdot c\right)}}}}{2 \cdot a}\\ \end{array}\]
    10. Simplified9.5

      \[\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(a \cdot c\right) \cdot 4}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \end{array}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification7.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.350676057343211554491874986591947593393 \cdot 10^{154}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(\frac{a}{\sqrt{b}} \cdot \frac{c}{\sqrt{b}}, 2, b \cdot -2\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \left(2 \cdot \frac{a \cdot c}{b} - b\right)}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \le -4.452231346955637703324616244948712027068 \cdot 10^{-267}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\frac{\left(4 \cdot a\right) \cdot c}{\sqrt{\mathsf{fma}\left(b, b, -\left(4 \cdot a\right) \cdot c\right)} - b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \le 1.287594296476507417293820707954348336152 \cdot 10^{78}:\\ \;\;\;\;\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(a \cdot c\right) \cdot 4}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(\frac{a}{\sqrt{b}} \cdot \frac{c}{\sqrt{b}}, 2, b \cdot -2\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \left(2 \cdot \frac{a \cdot c}{b} - b\right)}{2 \cdot a}\\ \end{array}\]

Reproduce

herbie shell --seed 2019303 +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))))