Average Error: 34.1 → 6.5
Time: 5.2s
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 -1.7431685240570133 \cdot 10^{102}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.0417939395900796 \cdot 10^{-259}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 9.37351117144741807 \cdot 10^{103}:\\ \;\;\;\;\frac{c}{0.5} \cdot \frac{1}{\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 -1.7431685240570133 \cdot 10^{102}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

\mathbf{elif}\;b \le 9.37351117144741807 \cdot 10^{103}:\\
\;\;\;\;\frac{c}{0.5} \cdot \frac{1}{\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 r54722 = b;
        double r54723 = -r54722;
        double r54724 = r54722 * r54722;
        double r54725 = 4.0;
        double r54726 = a;
        double r54727 = r54725 * r54726;
        double r54728 = c;
        double r54729 = r54727 * r54728;
        double r54730 = r54724 - r54729;
        double r54731 = sqrt(r54730);
        double r54732 = r54723 + r54731;
        double r54733 = 2.0;
        double r54734 = r54733 * r54726;
        double r54735 = r54732 / r54734;
        return r54735;
}

double f(double a, double b, double c) {
        double r54736 = b;
        double r54737 = -1.7431685240570133e+102;
        bool r54738 = r54736 <= r54737;
        double r54739 = 1.0;
        double r54740 = c;
        double r54741 = r54740 / r54736;
        double r54742 = a;
        double r54743 = r54736 / r54742;
        double r54744 = r54741 - r54743;
        double r54745 = r54739 * r54744;
        double r54746 = 1.0417939395900796e-259;
        bool r54747 = r54736 <= r54746;
        double r54748 = -r54736;
        double r54749 = r54736 * r54736;
        double r54750 = 4.0;
        double r54751 = r54750 * r54742;
        double r54752 = r54751 * r54740;
        double r54753 = r54749 - r54752;
        double r54754 = sqrt(r54753);
        double r54755 = r54748 + r54754;
        double r54756 = 2.0;
        double r54757 = r54756 * r54742;
        double r54758 = r54755 / r54757;
        double r54759 = 9.373511171447418e+103;
        bool r54760 = r54736 <= r54759;
        double r54761 = 0.5;
        double r54762 = r54740 / r54761;
        double r54763 = 1.0;
        double r54764 = r54748 - r54754;
        double r54765 = r54763 / r54764;
        double r54766 = r54762 * r54765;
        double r54767 = -1.0;
        double r54768 = r54767 * r54741;
        double r54769 = r54760 ? r54766 : r54768;
        double r54770 = r54747 ? r54758 : r54769;
        double r54771 = r54738 ? r54745 : r54770;
        return r54771;
}

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 < -1.7431685240570133e+102

    1. Initial program 47.5

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

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

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

    if -1.7431685240570133e+102 < b < 1.0417939395900796e-259

    1. Initial program 9.7

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

    if 1.0417939395900796e-259 < b < 9.373511171447418e+103

    1. Initial program 34.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 flip-+35.0

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

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

      \[\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. Taylor expanded around 0 8.3

      \[\leadsto \frac{1}{\color{blue}{\frac{0.5}{c}} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\]
    9. Using strategy rm
    10. Applied add-cube-cbrt8.3

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

      \[\leadsto \color{blue}{\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\frac{0.5}{c}} \cdot \frac{\sqrt[3]{1}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\]
    12. Simplified7.8

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

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

    if 9.373511171447418e+103 < b

    1. Initial program 59.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.7431685240570133 \cdot 10^{102}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.0417939395900796 \cdot 10^{-259}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 9.37351117144741807 \cdot 10^{103}:\\ \;\;\;\;\frac{c}{0.5} \cdot \frac{1}{\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 2020024 +o rules:numerics
(FPCore (a b c)
  :name "Quadratic roots, full range"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))