Average Error: 34.3 → 8.6
Time: 11.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 -1.569310777886352095486911207889814773134 \cdot 10^{111}:\\ \;\;\;\;\frac{1}{2} \cdot \left(2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}\right)\\ \mathbf{elif}\;b \le \frac{-8633006810733365}{2.808895523222368605827039360607851146278 \cdot 10^{306}}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a}\\ \mathbf{elif}\;b \le 1.447939350868406385811948663168665665979 \cdot 10^{78}:\\ \;\;\;\;\frac{\frac{\left({b}^{2} - {b}^{2}\right) + 4 \cdot \left(a \cdot c\right)}{2 \cdot a}}{\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 -1.569310777886352095486911207889814773134 \cdot 10^{111}:\\
\;\;\;\;\frac{1}{2} \cdot \left(2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}\right)\\

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

\mathbf{elif}\;b \le 1.447939350868406385811948663168665665979 \cdot 10^{78}:\\
\;\;\;\;\frac{\frac{\left({b}^{2} - {b}^{2}\right) + 4 \cdot \left(a \cdot c\right)}{2 \cdot a}}{\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 r116960 = b;
        double r116961 = -r116960;
        double r116962 = r116960 * r116960;
        double r116963 = 4.0;
        double r116964 = a;
        double r116965 = r116963 * r116964;
        double r116966 = c;
        double r116967 = r116965 * r116966;
        double r116968 = r116962 - r116967;
        double r116969 = sqrt(r116968);
        double r116970 = r116961 + r116969;
        double r116971 = 2.0;
        double r116972 = r116971 * r116964;
        double r116973 = r116970 / r116972;
        return r116973;
}

double f(double a, double b, double c) {
        double r116974 = b;
        double r116975 = -1.569310777886352e+111;
        bool r116976 = r116974 <= r116975;
        double r116977 = 1.0;
        double r116978 = 2.0;
        double r116979 = r116977 / r116978;
        double r116980 = c;
        double r116981 = r116980 / r116974;
        double r116982 = r116978 * r116981;
        double r116983 = 2.0;
        double r116984 = a;
        double r116985 = r116974 / r116984;
        double r116986 = r116983 * r116985;
        double r116987 = r116982 - r116986;
        double r116988 = r116979 * r116987;
        double r116989 = -8633006810733365.0;
        double r116990 = 2.8088955232223686e+306;
        double r116991 = r116989 / r116990;
        bool r116992 = r116974 <= r116991;
        double r116993 = -r116974;
        double r116994 = r116974 * r116974;
        double r116995 = 4.0;
        double r116996 = r116995 * r116984;
        double r116997 = r116996 * r116980;
        double r116998 = r116994 - r116997;
        double r116999 = sqrt(r116998);
        double r117000 = r116993 + r116999;
        double r117001 = r117000 / r116984;
        double r117002 = r116979 * r117001;
        double r117003 = 1.4479393508684064e+78;
        bool r117004 = r116974 <= r117003;
        double r117005 = pow(r116974, r116983);
        double r117006 = r117005 - r117005;
        double r117007 = r116984 * r116980;
        double r117008 = r116995 * r117007;
        double r117009 = r117006 + r117008;
        double r117010 = r116978 * r116984;
        double r117011 = r117009 / r117010;
        double r117012 = r116993 - r116999;
        double r117013 = r117011 / r117012;
        double r117014 = -1.0;
        double r117015 = r117014 * r116981;
        double r117016 = r117004 ? r117013 : r117015;
        double r117017 = r116992 ? r117002 : r117016;
        double r117018 = r116976 ? r116988 : r117017;
        return r117018;
}

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.3
Target21.1
Herbie8.6
\[\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 < -1.569310777886352e+111

    1. Initial program 50.4

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

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

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

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

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

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

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

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

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

    if -1.569310777886352e+111 < b < -3.07345244398039e-291

    1. Initial program 8.4

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied clear-num8.6

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

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

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

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

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

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

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

    if -3.07345244398039e-291 < b < 1.4479393508684064e+78

    1. Initial program 30.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 clear-num30.7

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}\]
    4. Using strategy rm
    5. Applied flip-+30.8

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\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}}}}}\]
    6. Applied associate-/r/30.8

      \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot a}{\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}} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\]
    7. Applied associate-/r*30.9

      \[\leadsto \color{blue}{\frac{\frac{1}{\frac{2 \cdot a}{\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}}}\]
    8. Simplified15.9

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

    if 1.4479393508684064e+78 < b

    1. Initial program 58.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.569310777886352095486911207889814773134 \cdot 10^{111}:\\ \;\;\;\;\frac{1}{2} \cdot \left(2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}\right)\\ \mathbf{elif}\;b \le \frac{-8633006810733365}{2.808895523222368605827039360607851146278 \cdot 10^{306}}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a}\\ \mathbf{elif}\;b \le 1.447939350868406385811948663168665665979 \cdot 10^{78}:\\ \;\;\;\;\frac{\frac{\left({b}^{2} - {b}^{2}\right) + 4 \cdot \left(a \cdot c\right)}{2 \cdot a}}{\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 2019303 
(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)))