Average Error: 34.1 → 6.7
Time: 5.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 -2.223763057046510327568967152287533282505 \cdot 10^{109}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -3.319380566438366601816459280349243307141 \cdot 10^{-186}:\\ \;\;\;\;\frac{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2} \cdot \frac{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{a}\\ \mathbf{elif}\;b \le 1.458057835821772074616178333218437979276 \cdot 10^{144}:\\ \;\;\;\;\frac{\frac{1}{2} \cdot \left(c \cdot 4\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \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 -2.223763057046510327568967152287533282505 \cdot 10^{109}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\mathbf{elif}\;b \le -3.319380566438366601816459280349243307141 \cdot 10^{-186}:\\
\;\;\;\;\frac{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2} \cdot \frac{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{a}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r59413 = b;
        double r59414 = -r59413;
        double r59415 = r59413 * r59413;
        double r59416 = 4.0;
        double r59417 = a;
        double r59418 = r59416 * r59417;
        double r59419 = c;
        double r59420 = r59418 * r59419;
        double r59421 = r59415 - r59420;
        double r59422 = sqrt(r59421);
        double r59423 = r59414 + r59422;
        double r59424 = 2.0;
        double r59425 = r59424 * r59417;
        double r59426 = r59423 / r59425;
        return r59426;
}

double f(double a, double b, double c) {
        double r59427 = b;
        double r59428 = -2.2237630570465103e+109;
        bool r59429 = r59427 <= r59428;
        double r59430 = 1.0;
        double r59431 = c;
        double r59432 = r59431 / r59427;
        double r59433 = a;
        double r59434 = r59427 / r59433;
        double r59435 = r59432 - r59434;
        double r59436 = r59430 * r59435;
        double r59437 = -3.3193805664383666e-186;
        bool r59438 = r59427 <= r59437;
        double r59439 = -r59427;
        double r59440 = r59427 * r59427;
        double r59441 = 4.0;
        double r59442 = r59441 * r59433;
        double r59443 = r59442 * r59431;
        double r59444 = r59440 - r59443;
        double r59445 = sqrt(r59444);
        double r59446 = r59439 + r59445;
        double r59447 = sqrt(r59446);
        double r59448 = 2.0;
        double r59449 = r59447 / r59448;
        double r59450 = r59447 / r59433;
        double r59451 = r59449 * r59450;
        double r59452 = 1.458057835821772e+144;
        bool r59453 = r59427 <= r59452;
        double r59454 = 1.0;
        double r59455 = r59454 / r59448;
        double r59456 = r59431 * r59441;
        double r59457 = r59455 * r59456;
        double r59458 = r59439 - r59445;
        double r59459 = r59457 / r59458;
        double r59460 = -1.0;
        double r59461 = r59460 * r59432;
        double r59462 = r59453 ? r59459 : r59461;
        double r59463 = r59438 ? r59451 : r59462;
        double r59464 = r59429 ? r59436 : r59463;
        return r59464;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 4 regimes
  2. if b < -2.2237630570465103e+109

    1. Initial program 48.6

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

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

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

    if -2.2237630570465103e+109 < b < -3.3193805664383666e-186

    1. Initial program 6.9

      \[\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-sqr-sqrt7.3

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

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

    if -3.3193805664383666e-186 < b < 1.458057835821772e+144

    1. Initial program 31.3

      \[\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-+31.5

      \[\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. Simplified16.1

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

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\frac{0 + 4 \cdot \left(a \cdot c\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}}\]
    7. Simplified15.3

      \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot a}{4 \cdot \left(a \cdot c\right)} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\]
    8. Using strategy rm
    9. Applied associate-/l*15.3

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

      \[\leadsto \frac{1}{\frac{2}{\color{blue}{\frac{c \cdot 4}{1}}} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\]
    11. Using strategy rm
    12. Applied associate-/r*9.9

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

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

    if 1.458057835821772e+144 < b

    1. Initial program 62.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.223763057046510327568967152287533282505 \cdot 10^{109}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -3.319380566438366601816459280349243307141 \cdot 10^{-186}:\\ \;\;\;\;\frac{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2} \cdot \frac{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{a}\\ \mathbf{elif}\;b \le 1.458057835821772074616178333218437979276 \cdot 10^{144}:\\ \;\;\;\;\frac{\frac{1}{2} \cdot \left(c \cdot 4\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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