Average Error: 33.8 → 8.8
Time: 18.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 -8.301687926884188663878043402578250574713 \cdot 10^{98}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 2.718360779562749981995134224969595326993 \cdot 10^{-181}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}{a}\\ \mathbf{elif}\;b \le 1.357284433132494781653830699845499522001 \cdot 10^{61}:\\ \;\;\;\;\frac{\frac{\frac{-\left(4 \cdot a\right) \cdot c}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}}{2}}{a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \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 -8.301687926884188663878043402578250574713 \cdot 10^{98}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r61439 = b;
        double r61440 = -r61439;
        double r61441 = r61439 * r61439;
        double r61442 = 4.0;
        double r61443 = a;
        double r61444 = r61442 * r61443;
        double r61445 = c;
        double r61446 = r61444 * r61445;
        double r61447 = r61441 - r61446;
        double r61448 = sqrt(r61447);
        double r61449 = r61440 + r61448;
        double r61450 = 2.0;
        double r61451 = r61450 * r61443;
        double r61452 = r61449 / r61451;
        return r61452;
}

double f(double a, double b, double c) {
        double r61453 = b;
        double r61454 = -8.301687926884189e+98;
        bool r61455 = r61453 <= r61454;
        double r61456 = 1.0;
        double r61457 = c;
        double r61458 = r61457 / r61453;
        double r61459 = a;
        double r61460 = r61453 / r61459;
        double r61461 = r61458 - r61460;
        double r61462 = r61456 * r61461;
        double r61463 = 2.71836077956275e-181;
        bool r61464 = r61453 <= r61463;
        double r61465 = r61453 * r61453;
        double r61466 = 4.0;
        double r61467 = r61466 * r61459;
        double r61468 = r61467 * r61457;
        double r61469 = r61465 - r61468;
        double r61470 = sqrt(r61469);
        double r61471 = r61470 - r61453;
        double r61472 = 2.0;
        double r61473 = r61471 / r61472;
        double r61474 = r61473 / r61459;
        double r61475 = 1.3572844331324948e+61;
        bool r61476 = r61453 <= r61475;
        double r61477 = -r61468;
        double r61478 = r61470 + r61453;
        double r61479 = r61477 / r61478;
        double r61480 = r61479 / r61472;
        double r61481 = r61480 / r61459;
        double r61482 = -1.0;
        double r61483 = r61482 * r61458;
        double r61484 = r61476 ? r61481 : r61483;
        double r61485 = r61464 ? r61474 : r61484;
        double r61486 = r61455 ? r61462 : r61485;
        return r61486;
}

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.8
Target20.8
Herbie8.8
\[\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 4 regimes
  2. if b < -8.301687926884189e+98

    1. Initial program 46.2

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

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

      \[\leadsto \color{blue}{1 \cdot \frac{c}{b} - 1 \cdot \frac{b}{a}}\]
    4. Simplified3.6

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

    if -8.301687926884189e+98 < b < 2.71836077956275e-181

    1. Initial program 10.9

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

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

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

    if 2.71836077956275e-181 < b < 1.3572844331324948e+61

    1. Initial program 34.8

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

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

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

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

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

    if 1.3572844331324948e+61 < b

    1. Initial program 57.4

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -8.301687926884188663878043402578250574713 \cdot 10^{98}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 2.718360779562749981995134224969595326993 \cdot 10^{-181}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}{a}\\ \mathbf{elif}\;b \le 1.357284433132494781653830699845499522001 \cdot 10^{61}:\\ \;\;\;\;\frac{\frac{\frac{-\left(4 \cdot a\right) \cdot c}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}}{2}}{a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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

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