Average Error: 34.2 → 7.4
Time: 25.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.555632367828988861043913196266489993904 \cdot 10^{101}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \mathbf{elif}\;b \le -1.588581026022229142935221773282266391902 \cdot 10^{-168}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{{b}^{2} - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{elif}\;b \le 87537227540251800037021545535125898395650:\\ \;\;\;\;\frac{\frac{1}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{\frac{2 \cdot a}{4 \cdot a}} \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.555632367828988861043913196266489993904 \cdot 10^{101}:\\
\;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r87404 = b;
        double r87405 = -r87404;
        double r87406 = r87404 * r87404;
        double r87407 = 4.0;
        double r87408 = a;
        double r87409 = r87407 * r87408;
        double r87410 = c;
        double r87411 = r87409 * r87410;
        double r87412 = r87406 - r87411;
        double r87413 = sqrt(r87412);
        double r87414 = r87405 + r87413;
        double r87415 = 2.0;
        double r87416 = r87415 * r87408;
        double r87417 = r87414 / r87416;
        return r87417;
}

double f(double a, double b, double c) {
        double r87418 = b;
        double r87419 = -1.555632367828989e+101;
        bool r87420 = r87418 <= r87419;
        double r87421 = c;
        double r87422 = r87421 / r87418;
        double r87423 = a;
        double r87424 = r87418 / r87423;
        double r87425 = r87422 - r87424;
        double r87426 = 1.0;
        double r87427 = r87425 * r87426;
        double r87428 = -1.5885810260222291e-168;
        bool r87429 = r87418 <= r87428;
        double r87430 = -r87418;
        double r87431 = 2.0;
        double r87432 = pow(r87418, r87431);
        double r87433 = 4.0;
        double r87434 = r87423 * r87421;
        double r87435 = r87433 * r87434;
        double r87436 = r87432 - r87435;
        double r87437 = sqrt(r87436);
        double r87438 = r87430 + r87437;
        double r87439 = 2.0;
        double r87440 = r87439 * r87423;
        double r87441 = r87438 / r87440;
        double r87442 = 8.75372275402518e+40;
        bool r87443 = r87418 <= r87442;
        double r87444 = 1.0;
        double r87445 = r87418 * r87418;
        double r87446 = r87433 * r87423;
        double r87447 = r87446 * r87421;
        double r87448 = r87445 - r87447;
        double r87449 = sqrt(r87448);
        double r87450 = r87430 - r87449;
        double r87451 = r87444 / r87450;
        double r87452 = r87440 / r87446;
        double r87453 = r87451 / r87452;
        double r87454 = r87453 * r87421;
        double r87455 = -1.0;
        double r87456 = r87455 * r87422;
        double r87457 = r87443 ? r87454 : r87456;
        double r87458 = r87429 ? r87441 : r87457;
        double r87459 = r87420 ? r87427 : r87458;
        return r87459;
}

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

Target

Original34.2
Target20.8
Herbie7.4
\[\begin{array}{l} \mathbf{if}\;b \lt 0.0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}}\\ \end{array}\]

Derivation

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

    1. Initial program 47.4

      \[\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}{\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1}\]

    if -1.555632367828989e+101 < b < -1.5885810260222291e-168

    1. Initial program 7.2

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

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

    if -1.5885810260222291e-168 < b < 8.75372275402518e+40

    1. Initial program 25.8

      \[\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-+26.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. Simplified16.9

      \[\leadsto \frac{\frac{\color{blue}{\mathsf{fma}\left(4 \cdot a, c, 0\right)}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity16.9

      \[\leadsto \frac{\frac{\mathsf{fma}\left(4 \cdot a, c, 0\right)}{\color{blue}{1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}}{2 \cdot a}\]
    7. Applied *-un-lft-identity16.9

      \[\leadsto \frac{\frac{\color{blue}{1 \cdot \mathsf{fma}\left(4 \cdot a, c, 0\right)}}{1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}{2 \cdot a}\]
    8. Applied times-frac16.9

      \[\leadsto \frac{\color{blue}{\frac{1}{1} \cdot \frac{\mathsf{fma}\left(4 \cdot a, c, 0\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{2 \cdot a}\]
    9. Applied associate-/l*17.0

      \[\leadsto \color{blue}{\frac{\frac{1}{1}}{\frac{2 \cdot a}{\frac{\mathsf{fma}\left(4 \cdot a, c, 0\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}}\]
    10. Simplified16.9

      \[\leadsto \frac{\frac{1}{1}}{\color{blue}{\left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{2 \cdot a}{\left(4 \cdot a\right) \cdot c}}}\]
    11. Using strategy rm
    12. Applied associate-/r*11.7

      \[\leadsto \frac{\frac{1}{1}}{\left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \color{blue}{\frac{\frac{2 \cdot a}{4 \cdot a}}{c}}}\]
    13. Using strategy rm
    14. Applied associate-*r/11.7

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

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

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

    if 8.75372275402518e+40 < b

    1. Initial program 56.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.555632367828988861043913196266489993904 \cdot 10^{101}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \mathbf{elif}\;b \le -1.588581026022229142935221773282266391902 \cdot 10^{-168}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{{b}^{2} - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{elif}\;b \le 87537227540251800037021545535125898395650:\\ \;\;\;\;\frac{\frac{1}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{\frac{2 \cdot a}{4 \cdot a}} \cdot c\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019323 +o rules:numerics
(FPCore (a b c)
  :name "The quadratic formula (r1)"
  :precision binary64

  :herbie-target
  (if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))))

  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))