Average Error: 34.6 → 10.0
Time: 29.8s
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.6581383089037873 \cdot 10^{81}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 2.45811587950602871 \cdot 10^{-136}:\\ \;\;\;\;\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 4.40565710546396028 \cdot 10^{-70}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le 1.1310446734884525 \cdot 10^{-47}:\\ \;\;\;\;\frac{\frac{\left(4 \cdot a\right) \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.155213356860159 \cdot 10^{83}:\\ \;\;\;\;\frac{\left(4 \cdot a\right) \cdot c}{\left(a \cdot 2\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\\ \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.6581383089037873 \cdot 10^{81}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\mathbf{elif}\;b \le 2.45811587950602871 \cdot 10^{-136}:\\
\;\;\;\;\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 4.40565710546396028 \cdot 10^{-70}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r61504 = b;
        double r61505 = -r61504;
        double r61506 = r61504 * r61504;
        double r61507 = 4.0;
        double r61508 = a;
        double r61509 = r61507 * r61508;
        double r61510 = c;
        double r61511 = r61509 * r61510;
        double r61512 = r61506 - r61511;
        double r61513 = sqrt(r61512);
        double r61514 = r61505 + r61513;
        double r61515 = 2.0;
        double r61516 = r61515 * r61508;
        double r61517 = r61514 / r61516;
        return r61517;
}

double f(double a, double b, double c) {
        double r61518 = b;
        double r61519 = -1.6581383089037873e+81;
        bool r61520 = r61518 <= r61519;
        double r61521 = 1.0;
        double r61522 = c;
        double r61523 = r61522 / r61518;
        double r61524 = a;
        double r61525 = r61518 / r61524;
        double r61526 = r61523 - r61525;
        double r61527 = r61521 * r61526;
        double r61528 = 2.4581158795060287e-136;
        bool r61529 = r61518 <= r61528;
        double r61530 = -r61518;
        double r61531 = r61518 * r61518;
        double r61532 = 4.0;
        double r61533 = r61532 * r61524;
        double r61534 = r61533 * r61522;
        double r61535 = r61531 - r61534;
        double r61536 = sqrt(r61535);
        double r61537 = r61530 + r61536;
        double r61538 = 1.0;
        double r61539 = 2.0;
        double r61540 = r61539 * r61524;
        double r61541 = r61538 / r61540;
        double r61542 = r61537 * r61541;
        double r61543 = 4.40565710546396e-70;
        bool r61544 = r61518 <= r61543;
        double r61545 = -1.0;
        double r61546 = r61545 * r61523;
        double r61547 = 1.1310446734884525e-47;
        bool r61548 = r61518 <= r61547;
        double r61549 = r61530 - r61536;
        double r61550 = r61534 / r61549;
        double r61551 = r61524 * r61539;
        double r61552 = r61550 / r61551;
        double r61553 = 1.155213356860159e+83;
        bool r61554 = r61518 <= r61553;
        double r61555 = r61551 * r61549;
        double r61556 = r61534 / r61555;
        double r61557 = r61554 ? r61556 : r61546;
        double r61558 = r61548 ? r61552 : r61557;
        double r61559 = r61544 ? r61546 : r61558;
        double r61560 = r61529 ? r61542 : r61559;
        double r61561 = r61520 ? r61527 : r61560;
        return r61561;
}

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.6
Target21.3
Herbie10.0
\[\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 5 regimes
  2. if b < -1.6581383089037873e+81

    1. Initial program 43.9

      \[\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 -1.6581383089037873e+81 < b < 2.4581158795060287e-136

    1. Initial program 11.7

      \[\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-inv11.8

      \[\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 2.4581158795060287e-136 < b < 4.40565710546396e-70 or 1.155213356860159e+83 < b

    1. Initial program 53.8

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]

    if 4.40565710546396e-70 < b < 1.1310446734884525e-47

    1. Initial program 31.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-+31.8

      \[\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. Simplified13.4

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

    if 1.1310446734884525e-47 < b < 1.155213356860159e+83

    1. Initial program 45.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-+45.8

      \[\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. Simplified14.4

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

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

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

      \[\leadsto \frac{0 + \left(4 \cdot a\right) \cdot c}{\color{blue}{\left(a \cdot 2\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\]
  3. Recombined 5 regimes into one program.
  4. Final simplification10.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.6581383089037873 \cdot 10^{81}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 2.45811587950602871 \cdot 10^{-136}:\\ \;\;\;\;\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 4.40565710546396028 \cdot 10^{-70}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le 1.1310446734884525 \cdot 10^{-47}:\\ \;\;\;\;\frac{\frac{\left(4 \cdot a\right) \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.155213356860159 \cdot 10^{83}:\\ \;\;\;\;\frac{\left(4 \cdot a\right) \cdot c}{\left(a \cdot 2\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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

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

  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))