Average Error: 34.3 → 9.1
Time: 6.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.568201128637223695690583924646661116118 \cdot 10^{55}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -4.546128927832045171835550197132658970541 \cdot 10^{-301}:\\ \;\;\;\;\frac{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{\frac{2 \cdot a}{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}\\ \mathbf{elif}\;b \le 9.748353205521284417498320088314179968082 \cdot 10^{77}:\\ \;\;\;\;\frac{\frac{0 + 4 \cdot \left(a \cdot c\right)}{\left(-b\right) - \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.568201128637223695690583924646661116118 \cdot 10^{55}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

\mathbf{elif}\;b \le 9.748353205521284417498320088314179968082 \cdot 10^{77}:\\
\;\;\;\;\frac{\frac{0 + 4 \cdot \left(a \cdot c\right)}{\left(-b\right) - \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 r59538 = b;
        double r59539 = -r59538;
        double r59540 = r59538 * r59538;
        double r59541 = 4.0;
        double r59542 = a;
        double r59543 = r59541 * r59542;
        double r59544 = c;
        double r59545 = r59543 * r59544;
        double r59546 = r59540 - r59545;
        double r59547 = sqrt(r59546);
        double r59548 = r59539 + r59547;
        double r59549 = 2.0;
        double r59550 = r59549 * r59542;
        double r59551 = r59548 / r59550;
        return r59551;
}

double f(double a, double b, double c) {
        double r59552 = b;
        double r59553 = -2.5682011286372237e+55;
        bool r59554 = r59552 <= r59553;
        double r59555 = 1.0;
        double r59556 = c;
        double r59557 = r59556 / r59552;
        double r59558 = a;
        double r59559 = r59552 / r59558;
        double r59560 = r59557 - r59559;
        double r59561 = r59555 * r59560;
        double r59562 = -4.546128927832045e-301;
        bool r59563 = r59552 <= r59562;
        double r59564 = -r59552;
        double r59565 = r59552 * r59552;
        double r59566 = 4.0;
        double r59567 = r59566 * r59558;
        double r59568 = r59567 * r59556;
        double r59569 = r59565 - r59568;
        double r59570 = sqrt(r59569);
        double r59571 = r59564 + r59570;
        double r59572 = sqrt(r59571);
        double r59573 = 2.0;
        double r59574 = r59573 * r59558;
        double r59575 = r59574 / r59572;
        double r59576 = r59572 / r59575;
        double r59577 = 9.748353205521284e+77;
        bool r59578 = r59552 <= r59577;
        double r59579 = 0.0;
        double r59580 = r59558 * r59556;
        double r59581 = r59566 * r59580;
        double r59582 = r59579 + r59581;
        double r59583 = r59564 - r59570;
        double r59584 = r59582 / r59583;
        double r59585 = r59584 / r59574;
        double r59586 = -1.0;
        double r59587 = r59586 * r59557;
        double r59588 = r59578 ? r59585 : r59587;
        double r59589 = r59563 ? r59576 : r59588;
        double r59590 = r59554 ? r59561 : r59589;
        return r59590;
}

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 4 regimes
  2. if b < -2.5682011286372237e+55

    1. Initial program 38.3

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

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

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

    if -2.5682011286372237e+55 < b < -4.546128927832045e-301

    1. Initial program 9.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 add-sqr-sqrt9.8

      \[\leadsto \frac{\color{blue}{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{2 \cdot a}\]
    4. Applied associate-/l*9.9

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

    if -4.546128927832045e-301 < b < 9.748353205521284e+77

    1. Initial program 31.3

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

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

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

    if 9.748353205521284e+77 < b

    1. Initial program 58.3

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

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

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