Average Error: 34.6 → 9.8
Time: 4.6s
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.9358923729233266 \cdot 10^{149}:\\ \;\;\;\;1 \cdot \left(1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\right)\\ \mathbf{elif}\;b \le 9.39036747108992214 \cdot 10^{-69}:\\ \;\;\;\;1 \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{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.9358923729233266 \cdot 10^{149}:\\
\;\;\;\;1 \cdot \left(1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r73521 = b;
        double r73522 = -r73521;
        double r73523 = r73521 * r73521;
        double r73524 = 4.0;
        double r73525 = a;
        double r73526 = r73524 * r73525;
        double r73527 = c;
        double r73528 = r73526 * r73527;
        double r73529 = r73523 - r73528;
        double r73530 = sqrt(r73529);
        double r73531 = r73522 + r73530;
        double r73532 = 2.0;
        double r73533 = r73532 * r73525;
        double r73534 = r73531 / r73533;
        return r73534;
}

double f(double a, double b, double c) {
        double r73535 = b;
        double r73536 = -2.9358923729233266e+149;
        bool r73537 = r73535 <= r73536;
        double r73538 = 1.0;
        double r73539 = 1.0;
        double r73540 = c;
        double r73541 = r73540 / r73535;
        double r73542 = a;
        double r73543 = r73535 / r73542;
        double r73544 = r73541 - r73543;
        double r73545 = r73539 * r73544;
        double r73546 = r73538 * r73545;
        double r73547 = 9.390367471089922e-69;
        bool r73548 = r73535 <= r73547;
        double r73549 = -r73535;
        double r73550 = r73535 * r73535;
        double r73551 = 4.0;
        double r73552 = r73551 * r73542;
        double r73553 = r73552 * r73540;
        double r73554 = r73550 - r73553;
        double r73555 = sqrt(r73554);
        double r73556 = r73549 + r73555;
        double r73557 = 2.0;
        double r73558 = r73557 * r73542;
        double r73559 = r73556 / r73558;
        double r73560 = r73538 * r73559;
        double r73561 = -1.0;
        double r73562 = r73561 * r73541;
        double r73563 = r73548 ? r73560 : r73562;
        double r73564 = r73537 ? r73546 : r73563;
        return r73564;
}

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.6
Target21.2
Herbie9.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 3 regimes
  2. if b < -2.9358923729233266e+149

    1. Initial program 62.1

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

      \[\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 *-un-lft-identity62.1

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

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

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

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

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

    if -2.9358923729233266e+149 < b < 9.390367471089922e-69

    1. Initial program 12.5

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

      \[\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 *-un-lft-identity12.7

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

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

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

    if 9.390367471089922e-69 < b

    1. Initial program 53.5

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

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

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

Reproduce

herbie shell --seed 2020018 
(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)))