Average Error: 34.6 → 9.8
Time: 4.9s
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.9358923729233266 \cdot 10^{149}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 9.39036747108992214 \cdot 10^{-69}:\\ \;\;\;\;\frac{b - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{-2 \cdot a}\\ \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.9358923729233266 \cdot 10^{149}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r53418 = b;
        double r53419 = -r53418;
        double r53420 = r53418 * r53418;
        double r53421 = 4.0;
        double r53422 = a;
        double r53423 = r53421 * r53422;
        double r53424 = c;
        double r53425 = r53423 * r53424;
        double r53426 = r53420 - r53425;
        double r53427 = sqrt(r53426);
        double r53428 = r53419 + r53427;
        double r53429 = 2.0;
        double r53430 = r53429 * r53422;
        double r53431 = r53428 / r53430;
        return r53431;
}

double f(double a, double b, double c) {
        double r53432 = b;
        double r53433 = -2.9358923729233266e+149;
        bool r53434 = r53432 <= r53433;
        double r53435 = 1.0;
        double r53436 = c;
        double r53437 = r53436 / r53432;
        double r53438 = a;
        double r53439 = r53432 / r53438;
        double r53440 = r53437 - r53439;
        double r53441 = r53435 * r53440;
        double r53442 = 9.390367471089922e-69;
        bool r53443 = r53432 <= r53442;
        double r53444 = r53432 * r53432;
        double r53445 = 4.0;
        double r53446 = r53445 * r53438;
        double r53447 = r53446 * r53436;
        double r53448 = r53444 - r53447;
        double r53449 = sqrt(r53448);
        double r53450 = r53432 - r53449;
        double r53451 = 2.0;
        double r53452 = r53451 * r53438;
        double r53453 = -r53452;
        double r53454 = r53450 / r53453;
        double r53455 = -1.0;
        double r53456 = r53455 * r53437;
        double r53457 = r53443 ? r53454 : r53456;
        double r53458 = r53434 ? r53441 : r53457;
        return r53458;
}

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.9358923729233266e+149

    1. Initial program 62.1

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

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

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

    if -2.9358923729233266e+149 < b < 9.390367471089922e-69

    1. Initial program 12.5

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

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

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

    if 9.390367471089922e-69 < b

    1. Initial program 53.5

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

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

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

Reproduce

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