Average Error: 34.1 → 6.9
Time: 18.1s
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.46337219442650475190360405115215330559 \cdot 10^{111}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -3.104620340175948664814965097441450913118 \cdot 10^{-300}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.201425921513023399093785571786407855582 \cdot 10^{53}:\\ \;\;\;\;\frac{1}{\frac{2}{c} \cdot \frac{a}{\frac{4 \cdot a}{\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.46337219442650475190360405115215330559 \cdot 10^{111}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

\mathbf{elif}\;b \le 3.201425921513023399093785571786407855582 \cdot 10^{53}:\\
\;\;\;\;\frac{1}{\frac{2}{c} \cdot \frac{a}{\frac{4 \cdot a}{\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 r45611 = b;
        double r45612 = -r45611;
        double r45613 = r45611 * r45611;
        double r45614 = 4.0;
        double r45615 = a;
        double r45616 = r45614 * r45615;
        double r45617 = c;
        double r45618 = r45616 * r45617;
        double r45619 = r45613 - r45618;
        double r45620 = sqrt(r45619);
        double r45621 = r45612 + r45620;
        double r45622 = 2.0;
        double r45623 = r45622 * r45615;
        double r45624 = r45621 / r45623;
        return r45624;
}

double f(double a, double b, double c) {
        double r45625 = b;
        double r45626 = -2.463372194426505e+111;
        bool r45627 = r45625 <= r45626;
        double r45628 = 1.0;
        double r45629 = c;
        double r45630 = r45629 / r45625;
        double r45631 = a;
        double r45632 = r45625 / r45631;
        double r45633 = r45630 - r45632;
        double r45634 = r45628 * r45633;
        double r45635 = -3.1046203401759487e-300;
        bool r45636 = r45625 <= r45635;
        double r45637 = -r45625;
        double r45638 = r45625 * r45625;
        double r45639 = 4.0;
        double r45640 = r45639 * r45631;
        double r45641 = r45640 * r45629;
        double r45642 = r45638 - r45641;
        double r45643 = sqrt(r45642);
        double r45644 = r45637 + r45643;
        double r45645 = 1.0;
        double r45646 = 2.0;
        double r45647 = r45646 * r45631;
        double r45648 = r45645 / r45647;
        double r45649 = r45644 * r45648;
        double r45650 = 3.2014259215130234e+53;
        bool r45651 = r45625 <= r45650;
        double r45652 = r45646 / r45629;
        double r45653 = r45637 - r45643;
        double r45654 = r45640 / r45653;
        double r45655 = r45631 / r45654;
        double r45656 = r45652 * r45655;
        double r45657 = r45645 / r45656;
        double r45658 = -1.0;
        double r45659 = r45658 * r45630;
        double r45660 = r45651 ? r45657 : r45659;
        double r45661 = r45636 ? r45649 : r45660;
        double r45662 = r45627 ? r45634 : r45661;
        return r45662;
}

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.463372194426505e+111

    1. Initial program 48.7

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

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

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

    if -2.463372194426505e+111 < b < -3.1046203401759487e-300

    1. Initial program 8.4

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

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

    if -3.1046203401759487e-300 < b < 3.2014259215130234e+53

    1. Initial program 29.1

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

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

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

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

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

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

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

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

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

    if 3.2014259215130234e+53 < b

    1. Initial program 58.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.46337219442650475190360405115215330559 \cdot 10^{111}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -3.104620340175948664814965097441450913118 \cdot 10^{-300}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.201425921513023399093785571786407855582 \cdot 10^{53}:\\ \;\;\;\;\frac{1}{\frac{2}{c} \cdot \frac{a}{\frac{4 \cdot a}{\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 2019326 +o rules:numerics
(FPCore (a b c)
  :name "Quadratic roots, full range"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))