Average Error: 33.8 → 9.8
Time: 14.8s
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 -7.93152454634661985 \cdot 10^{153}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 2.0569776426586135 \cdot 10^{-106}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{\frac{a}{\frac{1}{2}}}\\ \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 -7.93152454634661985 \cdot 10^{153}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r66519 = b;
        double r66520 = -r66519;
        double r66521 = r66519 * r66519;
        double r66522 = 4.0;
        double r66523 = a;
        double r66524 = r66522 * r66523;
        double r66525 = c;
        double r66526 = r66524 * r66525;
        double r66527 = r66521 - r66526;
        double r66528 = sqrt(r66527);
        double r66529 = r66520 + r66528;
        double r66530 = 2.0;
        double r66531 = r66530 * r66523;
        double r66532 = r66529 / r66531;
        return r66532;
}

double f(double a, double b, double c) {
        double r66533 = b;
        double r66534 = -7.93152454634662e+153;
        bool r66535 = r66533 <= r66534;
        double r66536 = 1.0;
        double r66537 = c;
        double r66538 = r66537 / r66533;
        double r66539 = a;
        double r66540 = r66533 / r66539;
        double r66541 = r66538 - r66540;
        double r66542 = r66536 * r66541;
        double r66543 = 2.0569776426586135e-106;
        bool r66544 = r66533 <= r66543;
        double r66545 = r66533 * r66533;
        double r66546 = 4.0;
        double r66547 = r66546 * r66539;
        double r66548 = r66547 * r66537;
        double r66549 = r66545 - r66548;
        double r66550 = sqrt(r66549);
        double r66551 = r66550 - r66533;
        double r66552 = 1.0;
        double r66553 = 2.0;
        double r66554 = r66552 / r66553;
        double r66555 = r66539 / r66554;
        double r66556 = r66551 / r66555;
        double r66557 = -1.0;
        double r66558 = r66557 * r66538;
        double r66559 = r66544 ? r66556 : r66558;
        double r66560 = r66535 ? r66542 : r66559;
        return r66560;
}

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 < -7.93152454634662e+153

    1. Initial program 63.8

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

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}{a}}\]
    3. Taylor expanded around -inf 1.9

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

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

    if -7.93152454634662e+153 < b < 2.0569776426586135e-106

    1. Initial program 11.2

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

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}{a}}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity11.2

      \[\leadsto \frac{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{\color{blue}{1 \cdot 2}}}{a}\]
    5. Applied *-un-lft-identity11.2

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

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

      \[\leadsto \color{blue}{\frac{\frac{1}{1}}{\frac{a}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}}}\]
    8. Using strategy rm
    9. Applied div-inv11.3

      \[\leadsto \frac{\frac{1}{1}}{\frac{a}{\color{blue}{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right) \cdot \frac{1}{2}}}}\]
    10. Applied *-un-lft-identity11.3

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

      \[\leadsto \frac{\frac{1}{1}}{\color{blue}{\frac{1}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b} \cdot \frac{a}{\frac{1}{2}}}}\]
    12. Applied associate-/r*11.3

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

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

    if 2.0569776426586135e-106 < b

    1. Initial program 52.0

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

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}{a}}\]
    3. Taylor expanded around inf 10.3

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

Reproduce

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