Average Error: 33.8 → 6.7
Time: 17.7s
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 -8.301687926884188663878043402578250574713 \cdot 10^{98}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -4.487727332912796743719870498916005978223 \cdot 10^{-230}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 6.208057797080499790536355473922963434123 \cdot 10^{104}:\\ \;\;\;\;\frac{\frac{1}{\frac{\frac{2}{4}}{c}}}{\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 -8.301687926884188663878043402578250574713 \cdot 10^{98}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

\mathbf{elif}\;b \le 6.208057797080499790536355473922963434123 \cdot 10^{104}:\\
\;\;\;\;\frac{\frac{1}{\frac{\frac{2}{4}}{c}}}{\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 r40201 = b;
        double r40202 = -r40201;
        double r40203 = r40201 * r40201;
        double r40204 = 4.0;
        double r40205 = a;
        double r40206 = r40204 * r40205;
        double r40207 = c;
        double r40208 = r40206 * r40207;
        double r40209 = r40203 - r40208;
        double r40210 = sqrt(r40209);
        double r40211 = r40202 + r40210;
        double r40212 = 2.0;
        double r40213 = r40212 * r40205;
        double r40214 = r40211 / r40213;
        return r40214;
}

double f(double a, double b, double c) {
        double r40215 = b;
        double r40216 = -8.301687926884189e+98;
        bool r40217 = r40215 <= r40216;
        double r40218 = 1.0;
        double r40219 = c;
        double r40220 = r40219 / r40215;
        double r40221 = a;
        double r40222 = r40215 / r40221;
        double r40223 = r40220 - r40222;
        double r40224 = r40218 * r40223;
        double r40225 = -4.487727332912797e-230;
        bool r40226 = r40215 <= r40225;
        double r40227 = -r40215;
        double r40228 = r40215 * r40215;
        double r40229 = 4.0;
        double r40230 = r40229 * r40221;
        double r40231 = r40230 * r40219;
        double r40232 = r40228 - r40231;
        double r40233 = sqrt(r40232);
        double r40234 = r40227 + r40233;
        double r40235 = 2.0;
        double r40236 = r40235 * r40221;
        double r40237 = r40234 / r40236;
        double r40238 = 6.2080577970805e+104;
        bool r40239 = r40215 <= r40238;
        double r40240 = 1.0;
        double r40241 = r40235 / r40229;
        double r40242 = r40241 / r40219;
        double r40243 = r40240 / r40242;
        double r40244 = r40227 - r40233;
        double r40245 = r40243 / r40244;
        double r40246 = -1.0;
        double r40247 = r40246 * r40220;
        double r40248 = r40239 ? r40245 : r40247;
        double r40249 = r40226 ? r40237 : r40248;
        double r40250 = r40217 ? r40224 : r40249;
        return r40250;
}

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 < -8.301687926884189e+98

    1. Initial program 46.2

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

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

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

    if -8.301687926884189e+98 < b < -4.487727332912797e-230

    1. Initial program 8.1

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

    if -4.487727332912797e-230 < b < 6.2080577970805e+104

    1. Initial program 29.9

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

      \[\leadsto \frac{\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}}}}{2 \cdot a}\]
    4. Simplified15.8

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

      \[\leadsto \color{blue}{\frac{0 + \left(c \cdot 4\right) \cdot a}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \frac{1}{2 \cdot a}}\]
    7. Using strategy rm
    8. Applied associate-*l/15.1

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

      \[\leadsto \frac{\color{blue}{\frac{c \cdot \left(4 \cdot a\right)}{2 \cdot a}}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\]
    10. Using strategy rm
    11. Applied clear-num15.1

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

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

    if 6.2080577970805e+104 < b

    1. Initial program 59.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -8.301687926884188663878043402578250574713 \cdot 10^{98}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -4.487727332912796743719870498916005978223 \cdot 10^{-230}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 6.208057797080499790536355473922963434123 \cdot 10^{104}:\\ \;\;\;\;\frac{\frac{1}{\frac{\frac{2}{4}}{c}}}{\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 2019304 +o rules:numerics
(FPCore (a b c)
  :name "Quadratic roots, full range"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))