Average Error: 34.3 → 6.6
Time: 5.4s
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 -4.297522851756149307625287590446857172218 \cdot 10^{130}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -1.941529513459981659526481896938835655376 \cdot 10^{-260}:\\ \;\;\;\;\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 1.752150488567700802544439975375947245276 \cdot 10^{103}:\\ \;\;\;\;\frac{2 \cdot c}{\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 -4.297522851756149307625287590446857172218 \cdot 10^{130}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\mathbf{elif}\;b \le -1.941529513459981659526481896938835655376 \cdot 10^{-260}:\\
\;\;\;\;\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 1.752150488567700802544439975375947245276 \cdot 10^{103}:\\
\;\;\;\;\frac{2 \cdot c}{\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 r139380 = b;
        double r139381 = -r139380;
        double r139382 = r139380 * r139380;
        double r139383 = 4.0;
        double r139384 = a;
        double r139385 = r139383 * r139384;
        double r139386 = c;
        double r139387 = r139385 * r139386;
        double r139388 = r139382 - r139387;
        double r139389 = sqrt(r139388);
        double r139390 = r139381 + r139389;
        double r139391 = 2.0;
        double r139392 = r139391 * r139384;
        double r139393 = r139390 / r139392;
        return r139393;
}

double f(double a, double b, double c) {
        double r139394 = b;
        double r139395 = -4.2975228517561493e+130;
        bool r139396 = r139394 <= r139395;
        double r139397 = 1.0;
        double r139398 = c;
        double r139399 = r139398 / r139394;
        double r139400 = a;
        double r139401 = r139394 / r139400;
        double r139402 = r139399 - r139401;
        double r139403 = r139397 * r139402;
        double r139404 = -1.9415295134599817e-260;
        bool r139405 = r139394 <= r139404;
        double r139406 = -r139394;
        double r139407 = r139394 * r139394;
        double r139408 = 4.0;
        double r139409 = r139408 * r139400;
        double r139410 = r139409 * r139398;
        double r139411 = r139407 - r139410;
        double r139412 = sqrt(r139411);
        double r139413 = r139406 + r139412;
        double r139414 = 1.0;
        double r139415 = 2.0;
        double r139416 = r139415 * r139400;
        double r139417 = r139414 / r139416;
        double r139418 = r139413 * r139417;
        double r139419 = 1.7521504885677008e+103;
        bool r139420 = r139394 <= r139419;
        double r139421 = r139415 * r139398;
        double r139422 = r139406 - r139412;
        double r139423 = r139421 / r139422;
        double r139424 = -1.0;
        double r139425 = r139424 * r139399;
        double r139426 = r139420 ? r139423 : r139425;
        double r139427 = r139405 ? r139418 : r139426;
        double r139428 = r139396 ? r139403 : r139427;
        return r139428;
}

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
Target20.6
Herbie6.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 < -4.2975228517561493e+130

    1. Initial program 54.6

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

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

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

    if -4.2975228517561493e+130 < b < -1.9415295134599817e-260

    1. Initial program 8.5

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

      \[\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 -1.9415295134599817e-260 < b < 1.7521504885677008e+103

    1. Initial program 32.0

      \[\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-+32.1

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

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

      \[\leadsto \frac{\color{blue}{\left(0 + 4 \cdot \left(a \cdot c\right)\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*21.0

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

      \[\leadsto \frac{0 + 4 \cdot \left(a \cdot c\right)}{\color{blue}{\left(2 \cdot a\right) \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*15.4

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

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

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

    if 1.7521504885677008e+103 < b

    1. Initial program 59.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.297522851756149307625287590446857172218 \cdot 10^{130}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -1.941529513459981659526481896938835655376 \cdot 10^{-260}:\\ \;\;\;\;\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 1.752150488567700802544439975375947245276 \cdot 10^{103}:\\ \;\;\;\;\frac{2 \cdot c}{\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 2019362 
(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)))