Average Error: 33.1 → 6.6
Time: 58.2s
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.1884247920746475 \cdot 10^{+101}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -1.6086609448752587 \cdot 10^{-299}:\\ \;\;\;\;\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} \cdot \frac{1}{a \cdot 2} - \frac{b}{a \cdot 2}\\ \mathbf{elif}\;b \le 9.34348145460108 \cdot 10^{+88}:\\ \;\;\;\;\frac{1}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b} \cdot \left(c \cdot -2\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 -2.1884247920746475 \cdot 10^{+101}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r9527257 = b;
        double r9527258 = -r9527257;
        double r9527259 = r9527257 * r9527257;
        double r9527260 = 4.0;
        double r9527261 = a;
        double r9527262 = r9527260 * r9527261;
        double r9527263 = c;
        double r9527264 = r9527262 * r9527263;
        double r9527265 = r9527259 - r9527264;
        double r9527266 = sqrt(r9527265);
        double r9527267 = r9527258 + r9527266;
        double r9527268 = 2.0;
        double r9527269 = r9527268 * r9527261;
        double r9527270 = r9527267 / r9527269;
        return r9527270;
}

double f(double a, double b, double c) {
        double r9527271 = b;
        double r9527272 = -2.1884247920746475e+101;
        bool r9527273 = r9527271 <= r9527272;
        double r9527274 = c;
        double r9527275 = r9527274 / r9527271;
        double r9527276 = a;
        double r9527277 = r9527271 / r9527276;
        double r9527278 = r9527275 - r9527277;
        double r9527279 = -1.6086609448752587e-299;
        bool r9527280 = r9527271 <= r9527279;
        double r9527281 = r9527271 * r9527271;
        double r9527282 = r9527274 * r9527276;
        double r9527283 = 4.0;
        double r9527284 = r9527282 * r9527283;
        double r9527285 = r9527281 - r9527284;
        double r9527286 = sqrt(r9527285);
        double r9527287 = 1.0;
        double r9527288 = 2.0;
        double r9527289 = r9527276 * r9527288;
        double r9527290 = r9527287 / r9527289;
        double r9527291 = r9527286 * r9527290;
        double r9527292 = r9527271 / r9527289;
        double r9527293 = r9527291 - r9527292;
        double r9527294 = 9.34348145460108e+88;
        bool r9527295 = r9527271 <= r9527294;
        double r9527296 = r9527286 + r9527271;
        double r9527297 = r9527287 / r9527296;
        double r9527298 = -2.0;
        double r9527299 = r9527274 * r9527298;
        double r9527300 = r9527297 * r9527299;
        double r9527301 = -r9527274;
        double r9527302 = r9527301 / r9527271;
        double r9527303 = r9527295 ? r9527300 : r9527302;
        double r9527304 = r9527280 ? r9527293 : r9527303;
        double r9527305 = r9527273 ? r9527278 : r9527304;
        return r9527305;
}

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.1
Target20.3
Herbie6.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 4 regimes
  2. if b < -2.1884247920746475e+101

    1. Initial program 44.5

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified44.5

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

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

    if -2.1884247920746475e+101 < b < -1.6086609448752587e-299

    1. Initial program 8.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified8.7

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

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

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

    if -1.6086609448752587e-299 < b < 9.34348145460108e+88

    1. Initial program 31.3

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified31.3

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity31.3

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

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}}}\]
    6. Using strategy rm
    7. Applied flip--31.5

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\color{blue}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} \cdot \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b \cdot b}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}}}}\]
    8. Applied associate-/r/31.5

      \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} \cdot \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b \cdot b} \cdot \left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b\right)}}\]
    9. Applied *-un-lft-identity31.5

      \[\leadsto \frac{\color{blue}{1 \cdot 1}}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} \cdot \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b \cdot b} \cdot \left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b\right)}\]
    10. Applied times-frac31.5

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

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

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

    if 9.34348145460108e+88 < b

    1. Initial program 57.8

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified57.8

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.1884247920746475 \cdot 10^{+101}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -1.6086609448752587 \cdot 10^{-299}:\\ \;\;\;\;\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} \cdot \frac{1}{a \cdot 2} - \frac{b}{a \cdot 2}\\ \mathbf{elif}\;b \le 9.34348145460108 \cdot 10^{+88}:\\ \;\;\;\;\frac{1}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b} \cdot \left(c \cdot -2\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]

Reproduce

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