Average Error: 34.7 → 10.2
Time: 28.4s
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 -1.270528699455007486596308100489334356636 \cdot 10^{152}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \mathbf{elif}\;b \le 1.744031351412432972171902712116585209201 \cdot 10^{-142}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -1\\ \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 -1.270528699455007486596308100489334356636 \cdot 10^{152}:\\
\;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r5620446 = b;
        double r5620447 = -r5620446;
        double r5620448 = r5620446 * r5620446;
        double r5620449 = 4.0;
        double r5620450 = a;
        double r5620451 = r5620449 * r5620450;
        double r5620452 = c;
        double r5620453 = r5620451 * r5620452;
        double r5620454 = r5620448 - r5620453;
        double r5620455 = sqrt(r5620454);
        double r5620456 = r5620447 + r5620455;
        double r5620457 = 2.0;
        double r5620458 = r5620457 * r5620450;
        double r5620459 = r5620456 / r5620458;
        return r5620459;
}

double f(double a, double b, double c) {
        double r5620460 = b;
        double r5620461 = -1.2705286994550075e+152;
        bool r5620462 = r5620460 <= r5620461;
        double r5620463 = c;
        double r5620464 = r5620463 / r5620460;
        double r5620465 = a;
        double r5620466 = r5620460 / r5620465;
        double r5620467 = r5620464 - r5620466;
        double r5620468 = 1.0;
        double r5620469 = r5620467 * r5620468;
        double r5620470 = 1.744031351412433e-142;
        bool r5620471 = r5620460 <= r5620470;
        double r5620472 = r5620460 * r5620460;
        double r5620473 = 4.0;
        double r5620474 = r5620463 * r5620473;
        double r5620475 = r5620474 * r5620465;
        double r5620476 = r5620472 - r5620475;
        double r5620477 = sqrt(r5620476);
        double r5620478 = r5620477 - r5620460;
        double r5620479 = 2.0;
        double r5620480 = r5620465 * r5620479;
        double r5620481 = r5620478 / r5620480;
        double r5620482 = -1.0;
        double r5620483 = r5620464 * r5620482;
        double r5620484 = r5620471 ? r5620481 : r5620483;
        double r5620485 = r5620462 ? r5620469 : r5620484;
        return r5620485;
}

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.7
Target21.1
Herbie10.2
\[\begin{array}{l} \mathbf{if}\;b \lt 0.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 < -1.2705286994550075e+152

    1. Initial program 62.9

      \[\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-inv62.9

      \[\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. Taylor expanded around -inf 1.7

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

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

    if -1.2705286994550075e+152 < b < 1.744031351412433e-142

    1. Initial program 10.4

      \[\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-inv10.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. Using strategy rm
    5. Applied associate-*r/10.4

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

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

    if 1.744031351412433e-142 < b

    1. Initial program 50.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.270528699455007486596308100489334356636 \cdot 10^{152}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \mathbf{elif}\;b \le 1.744031351412432972171902712116585209201 \cdot 10^{-142}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -1\\ \end{array}\]

Reproduce

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

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

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