Average Error: 34.3 → 8.6
Time: 16.5s
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.569310777886352095486911207889814773134 \cdot 10^{111}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -2.075943821136515538074933331988827259408 \cdot 10^{-290}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;b \le 1.447939350868406385811948663168665665979 \cdot 10^{78}:\\ \;\;\;\;\frac{\frac{\frac{\left(4 \cdot a\right) \cdot c}{a}}{2}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \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.569310777886352095486911207889814773134 \cdot 10^{111}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r38710 = b;
        double r38711 = -r38710;
        double r38712 = r38710 * r38710;
        double r38713 = 4.0;
        double r38714 = a;
        double r38715 = r38713 * r38714;
        double r38716 = c;
        double r38717 = r38715 * r38716;
        double r38718 = r38712 - r38717;
        double r38719 = sqrt(r38718);
        double r38720 = r38711 + r38719;
        double r38721 = 2.0;
        double r38722 = r38721 * r38714;
        double r38723 = r38720 / r38722;
        return r38723;
}

double f(double a, double b, double c) {
        double r38724 = b;
        double r38725 = -1.569310777886352e+111;
        bool r38726 = r38724 <= r38725;
        double r38727 = 1.0;
        double r38728 = c;
        double r38729 = r38728 / r38724;
        double r38730 = a;
        double r38731 = r38724 / r38730;
        double r38732 = r38729 - r38731;
        double r38733 = r38727 * r38732;
        double r38734 = -2.0759438211365155e-290;
        bool r38735 = r38724 <= r38734;
        double r38736 = -r38724;
        double r38737 = r38724 * r38724;
        double r38738 = 4.0;
        double r38739 = r38738 * r38730;
        double r38740 = r38739 * r38728;
        double r38741 = r38737 - r38740;
        double r38742 = sqrt(r38741);
        double r38743 = r38736 + r38742;
        double r38744 = 1.0;
        double r38745 = 2.0;
        double r38746 = r38745 * r38730;
        double r38747 = r38744 / r38746;
        double r38748 = r38743 * r38747;
        double r38749 = 1.4479393508684064e+78;
        bool r38750 = r38724 <= r38749;
        double r38751 = r38740 / r38730;
        double r38752 = r38751 / r38745;
        double r38753 = r38736 - r38742;
        double r38754 = r38752 / r38753;
        double r38755 = -1.0;
        double r38756 = r38755 * r38729;
        double r38757 = r38750 ? r38754 : r38756;
        double r38758 = r38735 ? r38748 : r38757;
        double r38759 = r38726 ? r38733 : r38758;
        return r38759;
}

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 < -1.569310777886352e+111

    1. Initial program 50.4

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

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

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

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

    if -1.569310777886352e+111 < b < -2.0759438211365155e-290

    1. Initial program 8.4

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

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

    if -2.0759438211365155e-290 < b < 1.4479393508684064e+78

    1. Initial program 30.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 div-inv30.6

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

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

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

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

    if 1.4479393508684064e+78 < 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. Using strategy rm
    3. Applied div-inv58.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.569310777886352095486911207889814773134 \cdot 10^{111}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -2.075943821136515538074933331988827259408 \cdot 10^{-290}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;b \le 1.447939350868406385811948663168665665979 \cdot 10^{78}:\\ \;\;\;\;\frac{\frac{\frac{\left(4 \cdot a\right) \cdot c}{a}}{2}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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