Average Error: 33.8 → 6.8
Time: 1.0m
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 -4.3671561050226844 \cdot 10^{+101}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -2.5255536235408963 \cdot 10^{-284}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}}\\ \mathbf{elif}\;b \le 1.4199128551722248 \cdot 10^{+110}:\\ \;\;\;\;\frac{1}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + b} \cdot \left(-2 \cdot c\right)\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]
double f(double a, double b, double c) {
        double r4971605 = b;
        double r4971606 = -r4971605;
        double r4971607 = r4971605 * r4971605;
        double r4971608 = 4.0;
        double r4971609 = a;
        double r4971610 = r4971608 * r4971609;
        double r4971611 = c;
        double r4971612 = r4971610 * r4971611;
        double r4971613 = r4971607 - r4971612;
        double r4971614 = sqrt(r4971613);
        double r4971615 = r4971606 + r4971614;
        double r4971616 = 2.0;
        double r4971617 = r4971616 * r4971609;
        double r4971618 = r4971615 / r4971617;
        return r4971618;
}

double f(double a, double b, double c) {
        double r4971619 = b;
        double r4971620 = -4.3671561050226844e+101;
        bool r4971621 = r4971619 <= r4971620;
        double r4971622 = c;
        double r4971623 = r4971622 / r4971619;
        double r4971624 = a;
        double r4971625 = r4971619 / r4971624;
        double r4971626 = r4971623 - r4971625;
        double r4971627 = -2.5255536235408963e-284;
        bool r4971628 = r4971619 <= r4971627;
        double r4971629 = 1.0;
        double r4971630 = 2.0;
        double r4971631 = r4971624 * r4971630;
        double r4971632 = r4971619 * r4971619;
        double r4971633 = 4.0;
        double r4971634 = r4971622 * r4971624;
        double r4971635 = r4971633 * r4971634;
        double r4971636 = r4971632 - r4971635;
        double r4971637 = sqrt(r4971636);
        double r4971638 = r4971637 - r4971619;
        double r4971639 = r4971631 / r4971638;
        double r4971640 = r4971629 / r4971639;
        double r4971641 = 1.4199128551722248e+110;
        bool r4971642 = r4971619 <= r4971641;
        double r4971643 = r4971637 + r4971619;
        double r4971644 = r4971629 / r4971643;
        double r4971645 = -2.0;
        double r4971646 = r4971645 * r4971622;
        double r4971647 = r4971644 * r4971646;
        double r4971648 = -r4971623;
        double r4971649 = r4971642 ? r4971647 : r4971648;
        double r4971650 = r4971628 ? r4971640 : r4971649;
        double r4971651 = r4971621 ? r4971626 : r4971650;
        return r4971651;
}

\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 -4.3671561050226844 \cdot 10^{+101}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

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

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

\end{array}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 4 regimes
  2. if b < -4.3671561050226844e+101

    1. Initial program 44.7

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

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

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

    if -4.3671561050226844e+101 < b < -2.5255536235408963e-284

    1. Initial program 9.0

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

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

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

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

    if -2.5255536235408963e-284 < b < 1.4199128551722248e+110

    1. Initial program 32.0

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

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

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

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

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

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

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

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

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

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

    if 1.4199128551722248e+110 < b

    1. Initial program 59.7

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

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

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

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

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

Reproduce

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