Average Error: 34.1 → 6.4
Time: 15.1s
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.46337219442650475190360405115215330559 \cdot 10^{111}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -3.104620340175948664814965097441450913118 \cdot 10^{-300}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;b \le 5.732888581164670930257747643857376081135 \cdot 10^{134}:\\ \;\;\;\;\frac{\frac{c}{0.5}}{\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 -2.46337219442650475190360405115215330559 \cdot 10^{111}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

\mathbf{elif}\;b \le 5.732888581164670930257747643857376081135 \cdot 10^{134}:\\
\;\;\;\;\frac{\frac{c}{0.5}}{\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 r65424 = b;
        double r65425 = -r65424;
        double r65426 = r65424 * r65424;
        double r65427 = 4.0;
        double r65428 = a;
        double r65429 = r65427 * r65428;
        double r65430 = c;
        double r65431 = r65429 * r65430;
        double r65432 = r65426 - r65431;
        double r65433 = sqrt(r65432);
        double r65434 = r65425 + r65433;
        double r65435 = 2.0;
        double r65436 = r65435 * r65428;
        double r65437 = r65434 / r65436;
        return r65437;
}

double f(double a, double b, double c) {
        double r65438 = b;
        double r65439 = -2.463372194426505e+111;
        bool r65440 = r65438 <= r65439;
        double r65441 = 1.0;
        double r65442 = c;
        double r65443 = r65442 / r65438;
        double r65444 = a;
        double r65445 = r65438 / r65444;
        double r65446 = r65443 - r65445;
        double r65447 = r65441 * r65446;
        double r65448 = -3.1046203401759487e-300;
        bool r65449 = r65438 <= r65448;
        double r65450 = -r65438;
        double r65451 = r65438 * r65438;
        double r65452 = 4.0;
        double r65453 = r65452 * r65444;
        double r65454 = r65453 * r65442;
        double r65455 = r65451 - r65454;
        double r65456 = sqrt(r65455);
        double r65457 = r65450 + r65456;
        double r65458 = 1.0;
        double r65459 = 2.0;
        double r65460 = r65459 * r65444;
        double r65461 = r65458 / r65460;
        double r65462 = r65457 * r65461;
        double r65463 = 5.732888581164671e+134;
        bool r65464 = r65438 <= r65463;
        double r65465 = 0.5;
        double r65466 = r65442 / r65465;
        double r65467 = r65450 - r65456;
        double r65468 = r65466 / r65467;
        double r65469 = -1.0;
        double r65470 = r65469 * r65443;
        double r65471 = r65464 ? r65468 : r65470;
        double r65472 = r65449 ? r65462 : r65471;
        double r65473 = r65440 ? r65447 : r65472;
        return r65473;
}

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.1
Target21.0
Herbie6.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 < -2.463372194426505e+111

    1. Initial program 48.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.0

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

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

    if -2.463372194426505e+111 < b < -3.1046203401759487e-300

    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 div-inv8.6

      \[\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}}\]

    if -3.1046203401759487e-300 < b < 5.732888581164671e+134

    1. Initial program 33.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-+33.9

      \[\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.6

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

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

      \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot a}{4 \cdot \left(a \cdot c\right)} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\]
    8. Taylor expanded around 0 9.1

      \[\leadsto \frac{1}{\color{blue}{\frac{0.5}{c}} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\]
    9. Using strategy rm
    10. Applied associate-/r*8.7

      \[\leadsto \color{blue}{\frac{\frac{1}{\frac{0.5}{c}}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\]
    11. Simplified8.6

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

    if 5.732888581164671e+134 < b

    1. Initial program 62.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.46337219442650475190360405115215330559 \cdot 10^{111}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -3.104620340175948664814965097441450913118 \cdot 10^{-300}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;b \le 5.732888581164670930257747643857376081135 \cdot 10^{134}:\\ \;\;\;\;\frac{\frac{c}{0.5}}{\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 2019326 
(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)))