Average Error: 34.4 → 6.7
Time: 18.6s
Precision: 64
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -1.763315479739403460017265344144602342789 \cdot 10^{89}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le -1.085000278636624341855070450537604684134 \cdot 10^{-297}:\\ \;\;\;\;\frac{c \cdot 2}{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}\\ \mathbf{elif}\;b \le 3.355858625783055094237525774982320834143 \cdot 10^{101}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \end{array}\]
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \le -1.763315479739403460017265344144602342789 \cdot 10^{89}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\

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

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

\mathbf{else}:\\
\;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\

\end{array}
double f(double a, double b, double c) {
        double r4409423 = b;
        double r4409424 = -r4409423;
        double r4409425 = r4409423 * r4409423;
        double r4409426 = 4.0;
        double r4409427 = a;
        double r4409428 = c;
        double r4409429 = r4409427 * r4409428;
        double r4409430 = r4409426 * r4409429;
        double r4409431 = r4409425 - r4409430;
        double r4409432 = sqrt(r4409431);
        double r4409433 = r4409424 - r4409432;
        double r4409434 = 2.0;
        double r4409435 = r4409434 * r4409427;
        double r4409436 = r4409433 / r4409435;
        return r4409436;
}

double f(double a, double b, double c) {
        double r4409437 = b;
        double r4409438 = -1.7633154797394035e+89;
        bool r4409439 = r4409437 <= r4409438;
        double r4409440 = -1.0;
        double r4409441 = c;
        double r4409442 = r4409441 / r4409437;
        double r4409443 = r4409440 * r4409442;
        double r4409444 = -1.0850002786366243e-297;
        bool r4409445 = r4409437 <= r4409444;
        double r4409446 = 2.0;
        double r4409447 = r4409441 * r4409446;
        double r4409448 = -r4409437;
        double r4409449 = r4409437 * r4409437;
        double r4409450 = a;
        double r4409451 = 4.0;
        double r4409452 = r4409450 * r4409451;
        double r4409453 = r4409441 * r4409452;
        double r4409454 = r4409449 - r4409453;
        double r4409455 = sqrt(r4409454);
        double r4409456 = r4409448 + r4409455;
        double r4409457 = r4409447 / r4409456;
        double r4409458 = 3.355858625783055e+101;
        bool r4409459 = r4409437 <= r4409458;
        double r4409460 = r4409448 - r4409455;
        double r4409461 = r4409450 * r4409446;
        double r4409462 = r4409460 / r4409461;
        double r4409463 = r4409437 / r4409450;
        double r4409464 = r4409442 - r4409463;
        double r4409465 = 1.0;
        double r4409466 = r4409464 * r4409465;
        double r4409467 = r4409459 ? r4409462 : r4409466;
        double r4409468 = r4409445 ? r4409457 : r4409467;
        double r4409469 = r4409439 ? r4409443 : r4409468;
        return r4409469;
}

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.4
Target20.9
Herbie6.7
\[\begin{array}{l} \mathbf{if}\;b \lt 0.0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if b < -1.7633154797394035e+89

    1. Initial program 59.1

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

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

    if -1.7633154797394035e+89 < b < -1.0850002786366243e-297

    1. Initial program 32.1

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

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

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

      \[\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}}\]
    6. Using strategy rm
    7. Applied flip--32.2

      \[\leadsto \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}}} \cdot \frac{1}{2 \cdot a}\]
    8. Applied associate-*l/32.2

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

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

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

    if -1.0850002786366243e-297 < b < 3.355858625783055e+101

    1. Initial program 9.5

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

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

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

    if 3.355858625783055e+101 < b

    1. Initial program 46.8

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

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

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

      \[\leadsto \color{blue}{1 \cdot \frac{c}{b} - 1 \cdot \frac{b}{a}}\]
    5. Simplified4.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.763315479739403460017265344144602342789 \cdot 10^{89}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le -1.085000278636624341855070450537604684134 \cdot 10^{-297}:\\ \;\;\;\;\frac{c \cdot 2}{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}\\ \mathbf{elif}\;b \le 3.355858625783055094237525774982320834143 \cdot 10^{101}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \end{array}\]

Reproduce

herbie shell --seed 2019172 
(FPCore (a b c)
  :name "The quadratic formula (r2)"

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

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