Average Error: 33.9 → 10.3
Time: 16.5s
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.361733299857302083043096878302889042354 \cdot 10^{105}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 3.09136118080059703772253670927164991568 \cdot 10^{-86}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}\\ \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.361733299857302083043096878302889042354 \cdot 10^{105}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r41757 = b;
        double r41758 = -r41757;
        double r41759 = r41757 * r41757;
        double r41760 = 4.0;
        double r41761 = a;
        double r41762 = r41760 * r41761;
        double r41763 = c;
        double r41764 = r41762 * r41763;
        double r41765 = r41759 - r41764;
        double r41766 = sqrt(r41765);
        double r41767 = r41758 + r41766;
        double r41768 = 2.0;
        double r41769 = r41768 * r41761;
        double r41770 = r41767 / r41769;
        return r41770;
}

double f(double a, double b, double c) {
        double r41771 = b;
        double r41772 = -1.361733299857302e+105;
        bool r41773 = r41771 <= r41772;
        double r41774 = 1.0;
        double r41775 = c;
        double r41776 = r41775 / r41771;
        double r41777 = a;
        double r41778 = r41771 / r41777;
        double r41779 = r41776 - r41778;
        double r41780 = r41774 * r41779;
        double r41781 = 3.091361180800597e-86;
        bool r41782 = r41771 <= r41781;
        double r41783 = 1.0;
        double r41784 = 2.0;
        double r41785 = r41784 * r41777;
        double r41786 = r41771 * r41771;
        double r41787 = 4.0;
        double r41788 = r41787 * r41777;
        double r41789 = r41788 * r41775;
        double r41790 = r41786 - r41789;
        double r41791 = sqrt(r41790);
        double r41792 = r41791 - r41771;
        double r41793 = r41785 / r41792;
        double r41794 = r41783 / r41793;
        double r41795 = -1.0;
        double r41796 = r41795 * r41776;
        double r41797 = r41782 ? r41794 : r41796;
        double r41798 = r41773 ? r41780 : r41797;
        return r41798;
}

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 3 regimes
  2. if b < -1.361733299857302e+105

    1. Initial program 48.6

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}}\]
    3. Taylor expanded around -inf 3.6

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

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

    if -1.361733299857302e+105 < b < 3.091361180800597e-86

    1. Initial program 12.2

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

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

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

    if 3.091361180800597e-86 < b

    1. Initial program 51.8

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}}\]
    3. Taylor expanded around inf 10.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.361733299857302083043096878302889042354 \cdot 10^{105}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 3.09136118080059703772253670927164991568 \cdot 10^{-86}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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