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

\mathbf{elif}\;b \le 1.447939350868406385811948663168665665979 \cdot 10^{78}:\\
\;\;\;\;\frac{\frac{a \cdot \left(c \cdot 4\right)}{2 \cdot a}}{\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 r61316 = b;
        double r61317 = -r61316;
        double r61318 = r61316 * r61316;
        double r61319 = 4.0;
        double r61320 = a;
        double r61321 = r61319 * r61320;
        double r61322 = c;
        double r61323 = r61321 * r61322;
        double r61324 = r61318 - r61323;
        double r61325 = sqrt(r61324);
        double r61326 = r61317 + r61325;
        double r61327 = 2.0;
        double r61328 = r61327 * r61320;
        double r61329 = r61326 / r61328;
        return r61329;
}

double f(double a, double b, double c) {
        double r61330 = b;
        double r61331 = -1.569310777886352e+111;
        bool r61332 = r61330 <= r61331;
        double r61333 = 1.0;
        double r61334 = c;
        double r61335 = r61334 / r61330;
        double r61336 = a;
        double r61337 = r61330 / r61336;
        double r61338 = r61335 - r61337;
        double r61339 = r61333 * r61338;
        double r61340 = -2.0759438211365155e-290;
        bool r61341 = r61330 <= r61340;
        double r61342 = r61330 * r61330;
        double r61343 = 4.0;
        double r61344 = r61343 * r61336;
        double r61345 = r61344 * r61334;
        double r61346 = r61342 - r61345;
        double r61347 = sqrt(r61346);
        double r61348 = -r61330;
        double r61349 = r61347 + r61348;
        double r61350 = 1.0;
        double r61351 = 2.0;
        double r61352 = r61351 * r61336;
        double r61353 = r61350 / r61352;
        double r61354 = r61349 * r61353;
        double r61355 = 1.4479393508684064e+78;
        bool r61356 = r61330 <= r61355;
        double r61357 = r61334 * r61343;
        double r61358 = r61336 * r61357;
        double r61359 = r61358 / r61352;
        double r61360 = r61348 - r61347;
        double r61361 = r61359 / r61360;
        double r61362 = -1.0;
        double r61363 = r61362 * r61335;
        double r61364 = r61356 ? r61361 : r61363;
        double r61365 = r61341 ? r61354 : r61364;
        double r61366 = r61332 ? r61339 : r61365;
        return r61366;
}

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.3
Target21.1
Herbie8.6
\[\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.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. Taylor expanded around -inf 3.9

      \[\leadsto \color{blue}{1 \cdot \frac{c}{b} - 1 \cdot \frac{b}{a}}\]
    3. 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 *-un-lft-identity8.4

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

      \[\leadsto \color{blue}{\left(1 \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)\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 *-un-lft-identity30.6

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

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

      \[\leadsto \left(1 \cdot \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}}}\right) \cdot \frac{1}{2 \cdot a}\]
    8. Applied associate-*r/30.7

      \[\leadsto \color{blue}{\frac{1 \cdot \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)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}} \cdot \frac{1}{2 \cdot a}\]
    9. Applied associate-*l/30.8

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

      \[\leadsto \frac{\color{blue}{\frac{0 + a \cdot \left(c \cdot 4\right)}{a \cdot 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. 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(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;b \le 1.447939350868406385811948663168665665979 \cdot 10^{78}:\\ \;\;\;\;\frac{\frac{a \cdot \left(c \cdot 4\right)}{2 \cdot a}}{\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 "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)))