Average Error: 33.8 → 9.5
Time: 8.7s
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 -3.12428337420519208 \cdot 10^{57}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 6.78592592067132194 \cdot 10^{-105}:\\ \;\;\;\;\frac{1}{\frac{2}{\frac{\sqrt{{b}^{2} - 4 \cdot \left(a \cdot c\right)} - b}{a}}}\\ \mathbf{elif}\;b \le 1.04869647254834991 \cdot 10^{-20}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\mathsf{fma}\left(c, 4 \cdot a, 0\right)}{a \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \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 -3.12428337420519208 \cdot 10^{57}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\mathbf{elif}\;b \le 6.78592592067132194 \cdot 10^{-105}:\\
\;\;\;\;\frac{1}{\frac{2}{\frac{\sqrt{{b}^{2} - 4 \cdot \left(a \cdot c\right)} - b}{a}}}\\

\mathbf{elif}\;b \le 1.04869647254834991 \cdot 10^{-20}:\\
\;\;\;\;\frac{1}{2} \cdot \frac{\mathsf{fma}\left(c, 4 \cdot a, 0\right)}{a \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\\

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

\end{array}
double f(double a, double b, double c) {
        double r47338 = b;
        double r47339 = -r47338;
        double r47340 = r47338 * r47338;
        double r47341 = 4.0;
        double r47342 = a;
        double r47343 = r47341 * r47342;
        double r47344 = c;
        double r47345 = r47343 * r47344;
        double r47346 = r47340 - r47345;
        double r47347 = sqrt(r47346);
        double r47348 = r47339 + r47347;
        double r47349 = 2.0;
        double r47350 = r47349 * r47342;
        double r47351 = r47348 / r47350;
        return r47351;
}

double f(double a, double b, double c) {
        double r47352 = b;
        double r47353 = -3.124283374205192e+57;
        bool r47354 = r47352 <= r47353;
        double r47355 = 1.0;
        double r47356 = c;
        double r47357 = r47356 / r47352;
        double r47358 = a;
        double r47359 = r47352 / r47358;
        double r47360 = r47357 - r47359;
        double r47361 = r47355 * r47360;
        double r47362 = 6.785925920671322e-105;
        bool r47363 = r47352 <= r47362;
        double r47364 = 1.0;
        double r47365 = 2.0;
        double r47366 = 2.0;
        double r47367 = pow(r47352, r47366);
        double r47368 = 4.0;
        double r47369 = r47358 * r47356;
        double r47370 = r47368 * r47369;
        double r47371 = r47367 - r47370;
        double r47372 = sqrt(r47371);
        double r47373 = r47372 - r47352;
        double r47374 = r47373 / r47358;
        double r47375 = r47365 / r47374;
        double r47376 = r47364 / r47375;
        double r47377 = 1.0486964725483499e-20;
        bool r47378 = r47352 <= r47377;
        double r47379 = r47364 / r47365;
        double r47380 = r47368 * r47358;
        double r47381 = 0.0;
        double r47382 = fma(r47356, r47380, r47381);
        double r47383 = -r47352;
        double r47384 = r47352 * r47352;
        double r47385 = r47380 * r47356;
        double r47386 = r47384 - r47385;
        double r47387 = sqrt(r47386);
        double r47388 = r47383 - r47387;
        double r47389 = r47358 * r47388;
        double r47390 = r47382 / r47389;
        double r47391 = r47379 * r47390;
        double r47392 = -1.0;
        double r47393 = r47392 * r47357;
        double r47394 = r47378 ? r47391 : r47393;
        double r47395 = r47363 ? r47376 : r47394;
        double r47396 = r47354 ? r47361 : r47395;
        return r47396;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 4 regimes
  2. if b < -3.124283374205192e+57

    1. Initial program 39.5

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

      \[\leadsto \color{blue}{1 \cdot \frac{c}{b} - 1 \cdot \frac{b}{a}}\]
    3. Simplified5.4

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

    if -3.124283374205192e+57 < b < 6.785925920671322e-105

    1. Initial program 11.8

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

      \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{{b}^{2} - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\]
    3. Using strategy rm
    4. Applied clear-num11.9

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{{b}^{2} - 4 \cdot \left(a \cdot c\right)}}}}\]
    5. Simplified11.9

      \[\leadsto \frac{1}{\color{blue}{\frac{2}{\frac{\sqrt{{b}^{2} - 4 \cdot \left(a \cdot c\right)} - b}{a}}}}\]

    if 6.785925920671322e-105 < b < 1.0486964725483499e-20

    1. Initial program 34.8

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

      \[\leadsto \frac{\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}}}}{2 \cdot a}\]
    4. Simplified17.9

      \[\leadsto \frac{\frac{\color{blue}{\left(4 \cdot a\right) \cdot c + b \cdot \left(b - b\right)}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity17.9

      \[\leadsto \frac{\frac{\left(4 \cdot a\right) \cdot c + b \cdot \left(b - b\right)}{\color{blue}{1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}}{2 \cdot a}\]
    7. Applied *-un-lft-identity17.9

      \[\leadsto \frac{\frac{\color{blue}{1 \cdot \left(\left(4 \cdot a\right) \cdot c + b \cdot \left(b - b\right)\right)}}{1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}{2 \cdot a}\]
    8. Applied times-frac17.9

      \[\leadsto \frac{\color{blue}{\frac{1}{1} \cdot \frac{\left(4 \cdot a\right) \cdot c + b \cdot \left(b - b\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{2 \cdot a}\]
    9. Applied times-frac17.9

      \[\leadsto \color{blue}{\frac{\frac{1}{1}}{2} \cdot \frac{\frac{\left(4 \cdot a\right) \cdot c + b \cdot \left(b - b\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{a}}\]
    10. Simplified17.9

      \[\leadsto \color{blue}{\frac{1}{2}} \cdot \frac{\frac{\left(4 \cdot a\right) \cdot c + b \cdot \left(b - b\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{a}\]
    11. Simplified23.6

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

    if 1.0486964725483499e-20 < b

    1. Initial program 55.5

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification9.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.12428337420519208 \cdot 10^{57}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 6.78592592067132194 \cdot 10^{-105}:\\ \;\;\;\;\frac{1}{\frac{2}{\frac{\sqrt{{b}^{2} - 4 \cdot \left(a \cdot c\right)} - b}{a}}}\\ \mathbf{elif}\;b \le 1.04869647254834991 \cdot 10^{-20}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\mathsf{fma}\left(c, 4 \cdot a, 0\right)}{a \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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