Average Error: 34.2 → 11.9
Time: 14.6s
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.547666603636537260513437138645901028344 \cdot 10^{50}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 7.455592343308264166675918758902222662503 \cdot 10^{-170}:\\ \;\;\;\;\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.547666603636537260513437138645901028344 \cdot 10^{50}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\mathbf{elif}\;b \le 7.455592343308264166675918758902222662503 \cdot 10^{-170}:\\
\;\;\;\;\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 r30379 = b;
        double r30380 = -r30379;
        double r30381 = r30379 * r30379;
        double r30382 = 4.0;
        double r30383 = a;
        double r30384 = r30382 * r30383;
        double r30385 = c;
        double r30386 = r30384 * r30385;
        double r30387 = r30381 - r30386;
        double r30388 = sqrt(r30387);
        double r30389 = r30380 + r30388;
        double r30390 = 2.0;
        double r30391 = r30390 * r30383;
        double r30392 = r30389 / r30391;
        return r30392;
}

double f(double a, double b, double c) {
        double r30393 = b;
        double r30394 = -1.5476666036365373e+50;
        bool r30395 = r30393 <= r30394;
        double r30396 = 1.0;
        double r30397 = c;
        double r30398 = r30397 / r30393;
        double r30399 = a;
        double r30400 = r30393 / r30399;
        double r30401 = r30398 - r30400;
        double r30402 = r30396 * r30401;
        double r30403 = 7.455592343308264e-170;
        bool r30404 = r30393 <= r30403;
        double r30405 = 1.0;
        double r30406 = 2.0;
        double r30407 = r30406 * r30399;
        double r30408 = r30393 * r30393;
        double r30409 = 4.0;
        double r30410 = r30409 * r30399;
        double r30411 = r30410 * r30397;
        double r30412 = r30408 - r30411;
        double r30413 = sqrt(r30412);
        double r30414 = r30413 - r30393;
        double r30415 = r30407 / r30414;
        double r30416 = r30405 / r30415;
        double r30417 = -1.0;
        double r30418 = r30417 * r30398;
        double r30419 = r30404 ? r30416 : r30418;
        double r30420 = r30395 ? r30402 : r30419;
        return r30420;
}

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.5476666036365373e+50

    1. Initial program 37.8

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified37.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 5.8

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

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

    if -1.5476666036365373e+50 < b < 7.455592343308264e-170

    1. Initial program 12.4

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

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

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

    if 7.455592343308264e-170 < b

    1. Initial program 48.9

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

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

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

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