Average Error: 33.7 → 10.9
Time: 10.3s
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.98276540088900058 \cdot 10^{134}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.1860189201379418 \cdot 10^{-161}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2} \cdot \frac{1}{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.98276540088900058 \cdot 10^{134}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r64145 = b;
        double r64146 = -r64145;
        double r64147 = r64145 * r64145;
        double r64148 = 4.0;
        double r64149 = a;
        double r64150 = r64148 * r64149;
        double r64151 = c;
        double r64152 = r64150 * r64151;
        double r64153 = r64147 - r64152;
        double r64154 = sqrt(r64153);
        double r64155 = r64146 + r64154;
        double r64156 = 2.0;
        double r64157 = r64156 * r64149;
        double r64158 = r64155 / r64157;
        return r64158;
}

double f(double a, double b, double c) {
        double r64159 = b;
        double r64160 = -1.9827654008890006e+134;
        bool r64161 = r64159 <= r64160;
        double r64162 = 1.0;
        double r64163 = c;
        double r64164 = r64163 / r64159;
        double r64165 = a;
        double r64166 = r64159 / r64165;
        double r64167 = r64164 - r64166;
        double r64168 = r64162 * r64167;
        double r64169 = 1.1860189201379418e-161;
        bool r64170 = r64159 <= r64169;
        double r64171 = r64159 * r64159;
        double r64172 = 4.0;
        double r64173 = r64172 * r64165;
        double r64174 = r64173 * r64163;
        double r64175 = r64171 - r64174;
        double r64176 = sqrt(r64175);
        double r64177 = r64176 - r64159;
        double r64178 = 2.0;
        double r64179 = r64177 / r64178;
        double r64180 = 1.0;
        double r64181 = r64180 / r64165;
        double r64182 = r64179 * r64181;
        double r64183 = -1.0;
        double r64184 = r64183 * r64164;
        double r64185 = r64170 ? r64182 : r64184;
        double r64186 = r64161 ? r64168 : r64185;
        return r64186;
}

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.9827654008890006e+134

    1. Initial program 56.8

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified56.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 3.1

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

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

    if -1.9827654008890006e+134 < b < 1.1860189201379418e-161

    1. Initial program 10.3

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

      \[\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 div-inv10.5

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

    if 1.1860189201379418e-161 < b

    1. Initial program 49.7

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

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

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

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

Reproduce

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