Average Error: 34.4 → 10.0
Time: 5.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 -9.91243958875386880555748684589545292526 \cdot 10^{101}:\\ \;\;\;\;\frac{1}{2} \cdot \left(2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.209120745343099452134664059704875392955 \cdot 10^{-70}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2} \cdot \left(-2 \cdot \frac{c}{b}\right)\\ \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 -9.91243958875386880555748684589545292526 \cdot 10^{101}:\\
\;\;\;\;\frac{1}{2} \cdot \left(2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}\right)\\

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{2} \cdot \left(-2 \cdot \frac{c}{b}\right)\\

\end{array}
double f(double a, double b, double c) {
        double r199447 = b;
        double r199448 = -r199447;
        double r199449 = r199447 * r199447;
        double r199450 = 4.0;
        double r199451 = a;
        double r199452 = r199450 * r199451;
        double r199453 = c;
        double r199454 = r199452 * r199453;
        double r199455 = r199449 - r199454;
        double r199456 = sqrt(r199455);
        double r199457 = r199448 + r199456;
        double r199458 = 2.0;
        double r199459 = r199458 * r199451;
        double r199460 = r199457 / r199459;
        return r199460;
}

double f(double a, double b, double c) {
        double r199461 = b;
        double r199462 = -9.912439588753869e+101;
        bool r199463 = r199461 <= r199462;
        double r199464 = 1.0;
        double r199465 = 2.0;
        double r199466 = r199464 / r199465;
        double r199467 = c;
        double r199468 = r199467 / r199461;
        double r199469 = r199465 * r199468;
        double r199470 = 2.0;
        double r199471 = a;
        double r199472 = r199461 / r199471;
        double r199473 = r199470 * r199472;
        double r199474 = r199469 - r199473;
        double r199475 = r199466 * r199474;
        double r199476 = 1.2091207453430995e-70;
        bool r199477 = r199461 <= r199476;
        double r199478 = -r199461;
        double r199479 = r199461 * r199461;
        double r199480 = 4.0;
        double r199481 = r199471 * r199467;
        double r199482 = r199480 * r199481;
        double r199483 = r199479 - r199482;
        double r199484 = sqrt(r199483);
        double r199485 = r199478 + r199484;
        double r199486 = r199485 / r199471;
        double r199487 = r199466 * r199486;
        double r199488 = -2.0;
        double r199489 = r199488 * r199468;
        double r199490 = r199466 * r199489;
        double r199491 = r199477 ? r199487 : r199490;
        double r199492 = r199463 ? r199475 : r199491;
        return r199492;
}

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.4
Target21.0
Herbie10.0
\[\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 < -9.912439588753869e+101

    1. Initial program 46.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 associate-*l*46.9

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

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

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

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

    if -9.912439588753869e+101 < b < 1.2091207453430995e-70

    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 associate-*l*13.3

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

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

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

    if 1.2091207453430995e-70 < b

    1. Initial program 53.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied associate-*l*53.7

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

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

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

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

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

Reproduce

herbie shell --seed 2020002 +o rules:numerics
(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)))