Average Error: 34.2 → 10.0
Time: 5.4s
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 -5.2389466313579672 \cdot 10^{127}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.6670468245058271 \cdot 10^{-85}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}{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 -5.2389466313579672 \cdot 10^{127}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r211437 = b;
        double r211438 = -r211437;
        double r211439 = r211437 * r211437;
        double r211440 = 4.0;
        double r211441 = a;
        double r211442 = r211440 * r211441;
        double r211443 = c;
        double r211444 = r211442 * r211443;
        double r211445 = r211439 - r211444;
        double r211446 = sqrt(r211445);
        double r211447 = r211438 + r211446;
        double r211448 = 2.0;
        double r211449 = r211448 * r211441;
        double r211450 = r211447 / r211449;
        return r211450;
}

double f(double a, double b, double c) {
        double r211451 = b;
        double r211452 = -5.238946631357967e+127;
        bool r211453 = r211451 <= r211452;
        double r211454 = 1.0;
        double r211455 = c;
        double r211456 = r211455 / r211451;
        double r211457 = a;
        double r211458 = r211451 / r211457;
        double r211459 = r211456 - r211458;
        double r211460 = r211454 * r211459;
        double r211461 = 1.667046824505827e-85;
        bool r211462 = r211451 <= r211461;
        double r211463 = r211451 * r211451;
        double r211464 = 4.0;
        double r211465 = r211464 * r211457;
        double r211466 = r211465 * r211455;
        double r211467 = r211463 - r211466;
        double r211468 = sqrt(r211467);
        double r211469 = -r211451;
        double r211470 = r211468 + r211469;
        double r211471 = 2.0;
        double r211472 = r211471 * r211457;
        double r211473 = r211470 / r211472;
        double r211474 = -1.0;
        double r211475 = r211474 * r211456;
        double r211476 = r211462 ? r211473 : r211475;
        double r211477 = r211453 ? r211460 : r211476;
        return r211477;
}

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

Target

Original34.2
Target21.6
Herbie10.0
\[\begin{array}{l} \mathbf{if}\;b \lt 0.0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}}\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if b < -5.238946631357967e+127

    1. Initial program 54.2

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

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

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

    if -5.238946631357967e+127 < b < 1.667046824505827e-85

    1. Initial program 12.2

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

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

    if 1.667046824505827e-85 < b

    1. Initial program 52.8

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

      \[\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 -5.2389466313579672 \cdot 10^{127}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.6670468245058271 \cdot 10^{-85}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2020056 +o rules:numerics
(FPCore (a b c)
  :name "The quadratic formula (r1)"
  :precision binary64

  :herbie-target
  (if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))))

  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))