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

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

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

\end{array}
double f(double a, double b, double c) {
        double r53341 = b;
        double r53342 = -r53341;
        double r53343 = r53341 * r53341;
        double r53344 = 4.0;
        double r53345 = a;
        double r53346 = r53344 * r53345;
        double r53347 = c;
        double r53348 = r53346 * r53347;
        double r53349 = r53343 - r53348;
        double r53350 = sqrt(r53349);
        double r53351 = r53342 + r53350;
        double r53352 = 2.0;
        double r53353 = r53352 * r53345;
        double r53354 = r53351 / r53353;
        return r53354;
}

double f(double a, double b, double c) {
        double r53355 = b;
        double r53356 = -2.61268387266151e+141;
        bool r53357 = r53355 <= r53356;
        double r53358 = 1.0;
        double r53359 = c;
        double r53360 = r53359 / r53355;
        double r53361 = a;
        double r53362 = r53355 / r53361;
        double r53363 = r53360 - r53362;
        double r53364 = r53358 * r53363;
        double r53365 = 1.1860189201379418e-161;
        bool r53366 = r53355 <= r53365;
        double r53367 = -r53355;
        double r53368 = r53355 * r53355;
        double r53369 = 4.0;
        double r53370 = r53369 * r53361;
        double r53371 = r53370 * r53359;
        double r53372 = r53368 - r53371;
        double r53373 = sqrt(r53372);
        double r53374 = r53367 + r53373;
        double r53375 = 2.0;
        double r53376 = r53375 * r53361;
        double r53377 = r53374 / r53376;
        double r53378 = 1.0;
        double r53379 = pow(r53377, r53378);
        double r53380 = -1.0;
        double r53381 = r53380 * r53360;
        double r53382 = r53366 ? r53379 : r53381;
        double r53383 = r53357 ? r53364 : r53382;
        return r53383;
}

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 < -2.61268387266151e+141

    1. Initial program 59.5

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

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

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

    if -2.61268387266151e+141 < 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. Using strategy rm
    3. Applied div-inv10.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. Using strategy rm
    5. Applied pow110.4

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

      \[\leadsto \color{blue}{{\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}^{1}} \cdot {\left(\frac{1}{2 \cdot a}\right)}^{1}\]
    7. Applied pow-prod-down10.4

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

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

    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. 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 -2.61268387266151013 \cdot 10^{141}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.1860189201379418 \cdot 10^{-161}:\\ \;\;\;\;{\left(\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\right)}^{1}\\ \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)))