Average Error: 33.7 → 10.9
Time: 5.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 -2.61268387266151013 \cdot 10^{141}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.1860189201379418 \cdot 10^{-161}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot 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 -2.61268387266151013 \cdot 10^{141}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r142468 = b;
        double r142469 = -r142468;
        double r142470 = r142468 * r142468;
        double r142471 = 4.0;
        double r142472 = a;
        double r142473 = r142471 * r142472;
        double r142474 = c;
        double r142475 = r142473 * r142474;
        double r142476 = r142470 - r142475;
        double r142477 = sqrt(r142476);
        double r142478 = r142469 + r142477;
        double r142479 = 2.0;
        double r142480 = r142479 * r142472;
        double r142481 = r142478 / r142480;
        return r142481;
}

double f(double a, double b, double c) {
        double r142482 = b;
        double r142483 = -2.61268387266151e+141;
        bool r142484 = r142482 <= r142483;
        double r142485 = 1.0;
        double r142486 = c;
        double r142487 = r142486 / r142482;
        double r142488 = a;
        double r142489 = r142482 / r142488;
        double r142490 = r142487 - r142489;
        double r142491 = r142485 * r142490;
        double r142492 = 1.1860189201379418e-161;
        bool r142493 = r142482 <= r142492;
        double r142494 = r142482 * r142482;
        double r142495 = 4.0;
        double r142496 = r142495 * r142488;
        double r142497 = r142496 * r142486;
        double r142498 = r142494 - r142497;
        double r142499 = sqrt(r142498);
        double r142500 = r142499 - r142482;
        double r142501 = 2.0;
        double r142502 = r142501 * r142488;
        double r142503 = r142500 / r142502;
        double r142504 = -1.0;
        double r142505 = r142504 * r142487;
        double r142506 = r142493 ? r142503 : r142505;
        double r142507 = r142484 ? r142491 : r142506;
        return r142507;
}

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.7
Target21.0
Herbie10.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 < -2.61268387266151e+141

    1. Initial program 59.5

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

      \[\leadsto \color{blue}{1 \cdot \frac{c}{b} - 1 \cdot \frac{b}{a}}\]
    3. Simplified2.9

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

    if -2.61268387266151e+141 < b < 1.1860189201379418e-161

    1. Initial program 10.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 div-inv10.4

      \[\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.3

      \[\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.3

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

    if 1.1860189201379418e-161 < b

    1. Initial program 49.7

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

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

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

Reproduce

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