Average Error: 34.4 → 10.2
Time: 5.2s
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.375455844612867193528729078860191211023 \cdot 10^{101}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 6.172683485094139204428067385532716833219 \cdot 10^{-78}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2} \cdot \left(-2 \cdot \frac{c}{b}\right)\\ \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.375455844612867193528729078860191211023 \cdot 10^{101}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{2} \cdot \left(-2 \cdot \frac{c}{b}\right)\\

\end{array}
double f(double a, double b, double c) {
        double r87539 = b;
        double r87540 = -r87539;
        double r87541 = r87539 * r87539;
        double r87542 = 4.0;
        double r87543 = a;
        double r87544 = r87542 * r87543;
        double r87545 = c;
        double r87546 = r87544 * r87545;
        double r87547 = r87541 - r87546;
        double r87548 = sqrt(r87547);
        double r87549 = r87540 + r87548;
        double r87550 = 2.0;
        double r87551 = r87550 * r87543;
        double r87552 = r87549 / r87551;
        return r87552;
}

double f(double a, double b, double c) {
        double r87553 = b;
        double r87554 = -1.3754558446128672e+101;
        bool r87555 = r87553 <= r87554;
        double r87556 = 1.0;
        double r87557 = c;
        double r87558 = r87557 / r87553;
        double r87559 = a;
        double r87560 = r87553 / r87559;
        double r87561 = r87558 - r87560;
        double r87562 = r87556 * r87561;
        double r87563 = 6.172683485094139e-78;
        bool r87564 = r87553 <= r87563;
        double r87565 = -r87553;
        double r87566 = r87553 * r87553;
        double r87567 = 4.0;
        double r87568 = r87567 * r87559;
        double r87569 = r87568 * r87557;
        double r87570 = r87566 - r87569;
        double r87571 = sqrt(r87570);
        double r87572 = sqrt(r87571);
        double r87573 = r87572 * r87572;
        double r87574 = r87565 + r87573;
        double r87575 = 2.0;
        double r87576 = r87575 * r87559;
        double r87577 = r87574 / r87576;
        double r87578 = 1.0;
        double r87579 = r87578 / r87575;
        double r87580 = -2.0;
        double r87581 = r87580 * r87558;
        double r87582 = r87579 * r87581;
        double r87583 = r87564 ? r87577 : r87582;
        double r87584 = r87555 ? r87562 : r87583;
        return r87584;
}

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.4
Target21.0
Herbie10.2
\[\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 < -1.3754558446128672e+101

    1. Initial program 46.5

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

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

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

    if -1.3754558446128672e+101 < b < 6.172683485094139e-78

    1. Initial program 13.1

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

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

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

    if 6.172683485094139e-78 < b

    1. Initial program 53.4

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

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

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

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(\color{blue}{{4}^{1}} \cdot {a}^{1}\right) \cdot {c}^{1}}}{2 \cdot a}\]
    6. Applied pow-prod-down53.4

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \color{blue}{{\left(4 \cdot a\right)}^{1}} \cdot {c}^{1}}}{2 \cdot a}\]
    7. Applied pow-prod-down53.4

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

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - {\color{blue}{\left(4 \cdot \left(a \cdot c\right)\right)}}^{1}}}{2 \cdot a}\]
    9. Using strategy rm
    10. Applied *-un-lft-identity53.4

      \[\leadsto \frac{\color{blue}{1 \cdot \left(\left(-b\right) + \sqrt{b \cdot b - {\left(4 \cdot \left(a \cdot c\right)\right)}^{1}}\right)}}{2 \cdot a}\]
    11. Applied times-frac53.4

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - {\left(4 \cdot \left(a \cdot c\right)\right)}^{1}}}{a}}\]
    12. Taylor expanded around inf 9.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.375455844612867193528729078860191211023 \cdot 10^{101}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 6.172683485094139204428067385532716833219 \cdot 10^{-78}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2} \cdot \left(-2 \cdot \frac{c}{b}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020002 
(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)))