Average Error: 33.8 → 6.7
Time: 8.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 -8.301687926884188663878043402578250574713 \cdot 10^{98}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le \frac{-1077853067741081}{1.365609355853794155331553646739713596855 \cdot 10^{244}}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 6.208057797080499790536355473922963434123 \cdot 10^{104}:\\ \;\;\;\;\frac{\frac{c}{\frac{2}{4}}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \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 \frac{-1077853067741081}{1.365609355853794155331553646739713596855 \cdot 10^{244}}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r121573 = b;
        double r121574 = -r121573;
        double r121575 = r121573 * r121573;
        double r121576 = 4.0;
        double r121577 = a;
        double r121578 = r121576 * r121577;
        double r121579 = c;
        double r121580 = r121578 * r121579;
        double r121581 = r121575 - r121580;
        double r121582 = sqrt(r121581);
        double r121583 = r121574 + r121582;
        double r121584 = 2.0;
        double r121585 = r121584 * r121577;
        double r121586 = r121583 / r121585;
        return r121586;
}

double f(double a, double b, double c) {
        double r121587 = b;
        double r121588 = -8.301687926884189e+98;
        bool r121589 = r121587 <= r121588;
        double r121590 = 1.0;
        double r121591 = c;
        double r121592 = r121591 / r121587;
        double r121593 = a;
        double r121594 = r121587 / r121593;
        double r121595 = r121592 - r121594;
        double r121596 = r121590 * r121595;
        double r121597 = -1077853067741081.0;
        double r121598 = 1.3656093558537942e+244;
        double r121599 = r121597 / r121598;
        bool r121600 = r121587 <= r121599;
        double r121601 = -r121587;
        double r121602 = r121587 * r121587;
        double r121603 = 4.0;
        double r121604 = r121603 * r121593;
        double r121605 = r121604 * r121591;
        double r121606 = r121602 - r121605;
        double r121607 = sqrt(r121606);
        double r121608 = r121601 + r121607;
        double r121609 = 2.0;
        double r121610 = r121609 * r121593;
        double r121611 = r121608 / r121610;
        double r121612 = 6.2080577970805e+104;
        bool r121613 = r121587 <= r121612;
        double r121614 = r121609 / r121603;
        double r121615 = r121591 / r121614;
        double r121616 = r121601 - r121607;
        double r121617 = r121615 / r121616;
        double r121618 = -1.0;
        double r121619 = r121618 * r121592;
        double r121620 = r121613 ? r121617 : r121619;
        double r121621 = r121600 ? r121611 : r121620;
        double r121622 = r121589 ? r121596 : r121621;
        return r121622;
}

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
Herbie6.7
\[\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. Taylor expanded around -inf 3.6

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

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

    if -8.301687926884189e+98 < b < -7.892835993842436e-230

    1. Initial program 8.1

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

    if -7.892835993842436e-230 < b < 6.2080577970805e+104

    1. Initial program 29.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 flip-+30.0

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot a}{4 \cdot \left(a \cdot c\right)} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\]
    8. Using strategy rm
    9. Applied times-frac15.3

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

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

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

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

    if 6.2080577970805e+104 < b

    1. Initial program 59.4

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

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

    \[\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 \frac{-1077853067741081}{1.365609355853794155331553646739713596855 \cdot 10^{244}}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 6.208057797080499790536355473922963434123 \cdot 10^{104}:\\ \;\;\;\;\frac{\frac{c}{\frac{2}{4}}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \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)))