Average Error: 33.2 → 10.6
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 -3.5748480491313226 \cdot 10^{+106}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 3.821014310434392 \cdot 10^{-21}:\\ \;\;\;\;\frac{\sqrt{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}{\frac{a \cdot 2}{\sqrt{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}}\\ \mathbf{else}:\\ \;\;\;\;-\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 -3.5748480491313226 \cdot 10^{+106}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r4872382 = b;
        double r4872383 = -r4872382;
        double r4872384 = r4872382 * r4872382;
        double r4872385 = 4.0;
        double r4872386 = a;
        double r4872387 = r4872385 * r4872386;
        double r4872388 = c;
        double r4872389 = r4872387 * r4872388;
        double r4872390 = r4872384 - r4872389;
        double r4872391 = sqrt(r4872390);
        double r4872392 = r4872383 + r4872391;
        double r4872393 = 2.0;
        double r4872394 = r4872393 * r4872386;
        double r4872395 = r4872392 / r4872394;
        return r4872395;
}

double f(double a, double b, double c) {
        double r4872396 = b;
        double r4872397 = -3.5748480491313226e+106;
        bool r4872398 = r4872396 <= r4872397;
        double r4872399 = c;
        double r4872400 = r4872399 / r4872396;
        double r4872401 = a;
        double r4872402 = r4872396 / r4872401;
        double r4872403 = r4872400 - r4872402;
        double r4872404 = 3.821014310434392e-21;
        bool r4872405 = r4872396 <= r4872404;
        double r4872406 = -r4872396;
        double r4872407 = r4872396 * r4872396;
        double r4872408 = 4.0;
        double r4872409 = r4872408 * r4872401;
        double r4872410 = r4872399 * r4872409;
        double r4872411 = r4872407 - r4872410;
        double r4872412 = sqrt(r4872411);
        double r4872413 = r4872406 + r4872412;
        double r4872414 = sqrt(r4872413);
        double r4872415 = 2.0;
        double r4872416 = r4872401 * r4872415;
        double r4872417 = r4872416 / r4872414;
        double r4872418 = r4872414 / r4872417;
        double r4872419 = -r4872400;
        double r4872420 = r4872405 ? r4872418 : r4872419;
        double r4872421 = r4872398 ? r4872403 : r4872420;
        return r4872421;
}

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

Original33.2
Target20.5
Herbie10.6
\[\begin{array}{l} \mathbf{if}\;b \lt 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 3 regimes
  2. if b < -3.5748480491313226e+106

    1. Initial program 46.5

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

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

    if -3.5748480491313226e+106 < b < 3.821014310434392e-21

    1. Initial program 14.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 add-sqr-sqrt15.2

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

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

    if 3.821014310434392e-21 < b

    1. Initial program 54.7

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.5748480491313226 \cdot 10^{+106}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 3.821014310434392 \cdot 10^{-21}:\\ \;\;\;\;\frac{\sqrt{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}{\frac{a \cdot 2}{\sqrt{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< b 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)))