Average Error: 34.1 → 9.9
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 -1.550162015746626746000974336574470460524 \cdot 10^{150}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.61145084478121505718169973575148582501 \cdot 10^{-34}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}\\ \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 -1.550162015746626746000974336574470460524 \cdot 10^{150}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r94410 = b;
        double r94411 = -r94410;
        double r94412 = r94410 * r94410;
        double r94413 = 4.0;
        double r94414 = a;
        double r94415 = r94413 * r94414;
        double r94416 = c;
        double r94417 = r94415 * r94416;
        double r94418 = r94412 - r94417;
        double r94419 = sqrt(r94418);
        double r94420 = r94411 + r94419;
        double r94421 = 2.0;
        double r94422 = r94421 * r94414;
        double r94423 = r94420 / r94422;
        return r94423;
}

double f(double a, double b, double c) {
        double r94424 = b;
        double r94425 = -1.5501620157466267e+150;
        bool r94426 = r94424 <= r94425;
        double r94427 = 1.0;
        double r94428 = c;
        double r94429 = r94428 / r94424;
        double r94430 = a;
        double r94431 = r94424 / r94430;
        double r94432 = r94429 - r94431;
        double r94433 = r94427 * r94432;
        double r94434 = 1.611450844781215e-34;
        bool r94435 = r94424 <= r94434;
        double r94436 = 1.0;
        double r94437 = 2.0;
        double r94438 = r94437 * r94430;
        double r94439 = r94424 * r94424;
        double r94440 = 4.0;
        double r94441 = r94440 * r94430;
        double r94442 = r94441 * r94428;
        double r94443 = r94439 - r94442;
        double r94444 = sqrt(r94443);
        double r94445 = r94444 - r94424;
        double r94446 = r94438 / r94445;
        double r94447 = r94436 / r94446;
        double r94448 = -1.0;
        double r94449 = r94448 * r94429;
        double r94450 = r94435 ? r94447 : r94449;
        double r94451 = r94426 ? r94433 : r94450;
        return r94451;
}

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.1
Target21.2
Herbie9.9
\[\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.5501620157466267e+150

    1. Initial program 62.9

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

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

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

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

    if -1.5501620157466267e+150 < b < 1.611450844781215e-34

    1. Initial program 13.6

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

      \[\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 clear-num13.7

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

    if 1.611450844781215e-34 < b

    1. Initial program 55.0

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

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

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

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

Reproduce

herbie shell --seed 2019325 +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)))