Average Error: 34.2 → 11.6
Time: 21.6s
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.555632367828988861043913196266489993904 \cdot 10^{101}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 7.455592343308264166675918758902222662503 \cdot 10^{-170}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{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 -1.555632367828988861043913196266489993904 \cdot 10^{101}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r36478 = b;
        double r36479 = -r36478;
        double r36480 = r36478 * r36478;
        double r36481 = 4.0;
        double r36482 = a;
        double r36483 = r36481 * r36482;
        double r36484 = c;
        double r36485 = r36483 * r36484;
        double r36486 = r36480 - r36485;
        double r36487 = sqrt(r36486);
        double r36488 = r36479 + r36487;
        double r36489 = 2.0;
        double r36490 = r36489 * r36482;
        double r36491 = r36488 / r36490;
        return r36491;
}

double f(double a, double b, double c) {
        double r36492 = b;
        double r36493 = -1.555632367828989e+101;
        bool r36494 = r36492 <= r36493;
        double r36495 = 1.0;
        double r36496 = c;
        double r36497 = r36496 / r36492;
        double r36498 = a;
        double r36499 = r36492 / r36498;
        double r36500 = r36497 - r36499;
        double r36501 = r36495 * r36500;
        double r36502 = 7.455592343308264e-170;
        bool r36503 = r36492 <= r36502;
        double r36504 = r36492 * r36492;
        double r36505 = 4.0;
        double r36506 = r36505 * r36498;
        double r36507 = r36506 * r36496;
        double r36508 = r36504 - r36507;
        double r36509 = sqrt(r36508);
        double r36510 = r36509 - r36492;
        double r36511 = 2.0;
        double r36512 = r36511 * r36498;
        double r36513 = r36510 / r36512;
        double r36514 = -1.0;
        double r36515 = r36514 * r36497;
        double r36516 = r36503 ? r36513 : r36515;
        double r36517 = r36494 ? r36501 : r36516;
        return r36517;
}

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 < -1.555632367828989e+101

    1. Initial program 47.4

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

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

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

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

    if -1.555632367828989e+101 < b < 7.455592343308264e-170

    1. Initial program 11.7

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

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

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

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

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

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

    if 7.455592343308264e-170 < b

    1. Initial program 48.9

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

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

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

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

Reproduce

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