Average Error: 33.1 → 6.6
Time: 58.7s
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 r9527252 = b;
        double r9527253 = -r9527252;
        double r9527254 = r9527252 * r9527252;
        double r9527255 = 4.0;
        double r9527256 = a;
        double r9527257 = r9527255 * r9527256;
        double r9527258 = c;
        double r9527259 = r9527257 * r9527258;
        double r9527260 = r9527254 - r9527259;
        double r9527261 = sqrt(r9527260);
        double r9527262 = r9527253 + r9527261;
        double r9527263 = 2.0;
        double r9527264 = r9527263 * r9527256;
        double r9527265 = r9527262 / r9527264;
        return r9527265;
}

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

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{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - \color{blue}{1 \cdot b}}{2 \cdot a}\]
    5. Applied *-un-lft-identity31.3

      \[\leadsto \frac{\color{blue}{1 \cdot \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}} - 1 \cdot b}{2 \cdot a}\]
    6. Applied distribute-lft-out--31.3

      \[\leadsto \frac{\color{blue}{1 \cdot \left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b\right)}}{2 \cdot a}\]
    7. 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}}}\]
    8. Using strategy rm
    9. 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}}}}\]
    10. 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)}}\]
    11. 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)}\]
    12. 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}}\]
    13. 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}\]
    14. 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. Using strategy rm
    4. Applied div-sub58.8

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    6. 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)))