Average Error: 33.0 → 6.6
Time: 1.7m
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 -9.139254247068609 \cdot 10^{+140}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 9.632148973470483 \cdot 10^{-296}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\sqrt{(-4 \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*} - b}{a}\\ \mathbf{elif}\;b \le 6.523631550102089 \cdot 10^{+89}:\\ \;\;\;\;\frac{\frac{-c}{\left(-b\right) - \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}}{\frac{-1}{2}}\\ \mathbf{else}:\\ \;\;\;\;-\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 -9.139254247068609 \cdot 10^{+140}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

\mathbf{elif}\;b \le 9.632148973470483 \cdot 10^{-296}:\\
\;\;\;\;\frac{1}{2} \cdot \frac{\sqrt{(-4 \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*} - b}{a}\\

\mathbf{elif}\;b \le 6.523631550102089 \cdot 10^{+89}:\\
\;\;\;\;\frac{\frac{-c}{\left(-b\right) - \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}}{\frac{-1}{2}}\\

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

\end{array}
double f(double a, double b, double c) {
        double r6061538 = b;
        double r6061539 = -r6061538;
        double r6061540 = r6061538 * r6061538;
        double r6061541 = 4.0;
        double r6061542 = a;
        double r6061543 = r6061541 * r6061542;
        double r6061544 = c;
        double r6061545 = r6061543 * r6061544;
        double r6061546 = r6061540 - r6061545;
        double r6061547 = sqrt(r6061546);
        double r6061548 = r6061539 + r6061547;
        double r6061549 = 2.0;
        double r6061550 = r6061549 * r6061542;
        double r6061551 = r6061548 / r6061550;
        return r6061551;
}

double f(double a, double b, double c) {
        double r6061552 = b;
        double r6061553 = -9.139254247068609e+140;
        bool r6061554 = r6061552 <= r6061553;
        double r6061555 = c;
        double r6061556 = r6061555 / r6061552;
        double r6061557 = a;
        double r6061558 = r6061552 / r6061557;
        double r6061559 = r6061556 - r6061558;
        double r6061560 = 9.632148973470483e-296;
        bool r6061561 = r6061552 <= r6061560;
        double r6061562 = 0.5;
        double r6061563 = -4.0;
        double r6061564 = r6061555 * r6061557;
        double r6061565 = r6061552 * r6061552;
        double r6061566 = fma(r6061563, r6061564, r6061565);
        double r6061567 = sqrt(r6061566);
        double r6061568 = r6061567 - r6061552;
        double r6061569 = r6061568 / r6061557;
        double r6061570 = r6061562 * r6061569;
        double r6061571 = 6.523631550102089e+89;
        bool r6061572 = r6061552 <= r6061571;
        double r6061573 = -r6061555;
        double r6061574 = -r6061552;
        double r6061575 = r6061557 * r6061563;
        double r6061576 = fma(r6061575, r6061555, r6061565);
        double r6061577 = sqrt(r6061576);
        double r6061578 = r6061574 - r6061577;
        double r6061579 = r6061573 / r6061578;
        double r6061580 = -0.5;
        double r6061581 = r6061579 / r6061580;
        double r6061582 = -r6061556;
        double r6061583 = r6061572 ? r6061581 : r6061582;
        double r6061584 = r6061561 ? r6061570 : r6061583;
        double r6061585 = r6061554 ? r6061559 : r6061584;
        return r6061585;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 4 regimes
  2. if b < -9.139254247068609e+140

    1. Initial program 55.8

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

      \[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}}\]

    if -9.139254247068609e+140 < b < 9.632148973470483e-296

    1. Initial program 8.7

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

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

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

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\left(-\color{blue}{1 \cdot b}\right) + 1 \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\]
    7. Applied distribute-rgt-neg-in8.9

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\color{blue}{1 \cdot \left(-b\right)} + 1 \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\]
    8. Applied distribute-lft-out8.9

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

      \[\leadsto \frac{1}{\color{blue}{\frac{2}{1} \cdot \frac{a}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}\]
    10. Applied add-sqr-sqrt8.9

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

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

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

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

    if 9.632148973470483e-296 < b < 6.523631550102089e+89

    1. Initial program 32.6

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

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}\]
    4. Using strategy rm
    5. Applied flip-+32.7

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\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}}}}}\]
    6. Applied associate-/r/32.8

      \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot a}{\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}} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\]
    7. Applied *-un-lft-identity32.8

      \[\leadsto \frac{\color{blue}{1 \cdot 1}}{\frac{2 \cdot a}{\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}} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\]
    8. Applied times-frac32.8

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\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}}} \cdot \frac{1}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\]
    9. Simplified16.4

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

      \[\leadsto \frac{-\frac{a \cdot c}{\frac{-1}{2}}}{a} \cdot \color{blue}{\frac{1}{\left(-b\right) - \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}}}\]
    11. Using strategy rm
    12. Applied distribute-frac-neg16.4

      \[\leadsto \color{blue}{\left(-\frac{\frac{a \cdot c}{\frac{-1}{2}}}{a}\right)} \cdot \frac{1}{\left(-b\right) - \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}}\]
    13. Applied distribute-lft-neg-out16.4

      \[\leadsto \color{blue}{-\frac{\frac{a \cdot c}{\frac{-1}{2}}}{a} \cdot \frac{1}{\left(-b\right) - \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}}}\]
    14. Simplified9.3

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

    if 6.523631550102089e+89 < b

    1. Initial program 58.7

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -9.139254247068609 \cdot 10^{+140}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 9.632148973470483 \cdot 10^{-296}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\sqrt{(-4 \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*} - b}{a}\\ \mathbf{elif}\;b \le 6.523631550102089 \cdot 10^{+89}:\\ \;\;\;\;\frac{\frac{-c}{\left(-b\right) - \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}}{\frac{-1}{2}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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