Average Error: 33.6 → 10.4
Time: 17.5s
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.1144981103869975 \cdot 10^{+131}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 4.5810084990875205 \cdot 10^{-68}:\\ \;\;\;\;\frac{1}{\frac{a}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2}}}\\ \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 -2.1144981103869975 \cdot 10^{+131}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r3011519 = b;
        double r3011520 = -r3011519;
        double r3011521 = r3011519 * r3011519;
        double r3011522 = 4.0;
        double r3011523 = a;
        double r3011524 = r3011522 * r3011523;
        double r3011525 = c;
        double r3011526 = r3011524 * r3011525;
        double r3011527 = r3011521 - r3011526;
        double r3011528 = sqrt(r3011527);
        double r3011529 = r3011520 + r3011528;
        double r3011530 = 2.0;
        double r3011531 = r3011530 * r3011523;
        double r3011532 = r3011529 / r3011531;
        return r3011532;
}

double f(double a, double b, double c) {
        double r3011533 = b;
        double r3011534 = -2.1144981103869975e+131;
        bool r3011535 = r3011533 <= r3011534;
        double r3011536 = c;
        double r3011537 = r3011536 / r3011533;
        double r3011538 = a;
        double r3011539 = r3011533 / r3011538;
        double r3011540 = r3011537 - r3011539;
        double r3011541 = 4.5810084990875205e-68;
        bool r3011542 = r3011533 <= r3011541;
        double r3011543 = 1.0;
        double r3011544 = r3011533 * r3011533;
        double r3011545 = r3011536 * r3011538;
        double r3011546 = 4.0;
        double r3011547 = r3011545 * r3011546;
        double r3011548 = r3011544 - r3011547;
        double r3011549 = sqrt(r3011548);
        double r3011550 = r3011549 - r3011533;
        double r3011551 = 2.0;
        double r3011552 = r3011550 / r3011551;
        double r3011553 = r3011538 / r3011552;
        double r3011554 = r3011543 / r3011553;
        double r3011555 = -r3011537;
        double r3011556 = r3011542 ? r3011554 : r3011555;
        double r3011557 = r3011535 ? r3011540 : r3011556;
        return r3011557;
}

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.6
Target21.0
Herbie10.4
\[\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 < -2.1144981103869975e+131

    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 2.6

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

    if -2.1144981103869975e+131 < b < 4.5810084990875205e-68

    1. Initial program 13.3

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

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

      \[\leadsto \left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \color{blue}{\frac{\frac{1}{2}}{a}}\]
    5. Using strategy rm
    6. Applied associate-*r/13.3

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

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

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

      \[\leadsto \frac{\frac{\sqrt{\color{blue}{b \cdot b - 4 \cdot \left(a \cdot c\right)}} - b}{2}}{a}\]
    10. Using strategy rm
    11. Applied clear-num13.4

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

    if 4.5810084990875205e-68 < b

    1. Initial program 52.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 div-inv52.0

      \[\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}}\]
    4. Simplified52.0

      \[\leadsto \left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \color{blue}{\frac{\frac{1}{2}}{a}}\]
    5. Using strategy rm
    6. Applied associate-*r/52.0

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.1144981103869975 \cdot 10^{+131}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 4.5810084990875205 \cdot 10^{-68}:\\ \;\;\;\;\frac{1}{\frac{a}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2}}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019163 
(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)))