Average Error: 33.7 → 10.0
Time: 18.3s
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.847204280282031663920354805138023860461 \cdot 10^{48}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.407088231767797284873172100248652560848 \cdot 10^{-46}:\\ \;\;\;\;\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 -2.847204280282031663920354805138023860461 \cdot 10^{48}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\mathbf{elif}\;b \le 1.407088231767797284873172100248652560848 \cdot 10^{-46}:\\
\;\;\;\;\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 r49440 = b;
        double r49441 = -r49440;
        double r49442 = r49440 * r49440;
        double r49443 = 4.0;
        double r49444 = a;
        double r49445 = r49443 * r49444;
        double r49446 = c;
        double r49447 = r49445 * r49446;
        double r49448 = r49442 - r49447;
        double r49449 = sqrt(r49448);
        double r49450 = r49441 + r49449;
        double r49451 = 2.0;
        double r49452 = r49451 * r49444;
        double r49453 = r49450 / r49452;
        return r49453;
}

double f(double a, double b, double c) {
        double r49454 = b;
        double r49455 = -2.8472042802820317e+48;
        bool r49456 = r49454 <= r49455;
        double r49457 = 1.0;
        double r49458 = c;
        double r49459 = r49458 / r49454;
        double r49460 = a;
        double r49461 = r49454 / r49460;
        double r49462 = r49459 - r49461;
        double r49463 = r49457 * r49462;
        double r49464 = 1.4070882317677973e-46;
        bool r49465 = r49454 <= r49464;
        double r49466 = 1.0;
        double r49467 = 2.0;
        double r49468 = r49467 * r49460;
        double r49469 = r49454 * r49454;
        double r49470 = 4.0;
        double r49471 = r49470 * r49460;
        double r49472 = r49471 * r49458;
        double r49473 = r49469 - r49472;
        double r49474 = sqrt(r49473);
        double r49475 = r49474 - r49454;
        double r49476 = r49468 / r49475;
        double r49477 = r49466 / r49476;
        double r49478 = -1.0;
        double r49479 = r49478 * r49459;
        double r49480 = r49465 ? r49477 : r49479;
        double r49481 = r49456 ? r49463 : r49480;
        return r49481;
}

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 < -2.8472042802820317e+48

    1. Initial program 38.1

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

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

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

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

    if -2.8472042802820317e+48 < b < 1.4070882317677973e-46

    1. Initial program 14.4

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

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

    if 1.4070882317677973e-46 < b

    1. Initial program 53.8

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

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

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