Average Error: 33.7 → 6.6
Time: 15.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.847204280282031663920354805138023860461 \cdot 10^{48}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -8.441935351115962169406457345797212275167 \cdot 10^{-251}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}\\ \mathbf{elif}\;b \le 1.406682295301811137671309943547484787165 \cdot 10^{103}:\\ \;\;\;\;\frac{2 \cdot c}{\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 -2.847204280282031663920354805138023860461 \cdot 10^{48}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

\mathbf{elif}\;b \le 1.406682295301811137671309943547484787165 \cdot 10^{103}:\\
\;\;\;\;\frac{2 \cdot c}{\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 r117922 = b;
        double r117923 = -r117922;
        double r117924 = r117922 * r117922;
        double r117925 = 4.0;
        double r117926 = a;
        double r117927 = r117925 * r117926;
        double r117928 = c;
        double r117929 = r117927 * r117928;
        double r117930 = r117924 - r117929;
        double r117931 = sqrt(r117930);
        double r117932 = r117923 + r117931;
        double r117933 = 2.0;
        double r117934 = r117933 * r117926;
        double r117935 = r117932 / r117934;
        return r117935;
}

double f(double a, double b, double c) {
        double r117936 = b;
        double r117937 = -2.8472042802820317e+48;
        bool r117938 = r117936 <= r117937;
        double r117939 = 1.0;
        double r117940 = c;
        double r117941 = r117940 / r117936;
        double r117942 = a;
        double r117943 = r117936 / r117942;
        double r117944 = r117941 - r117943;
        double r117945 = r117939 * r117944;
        double r117946 = -8.441935351115962e-251;
        bool r117947 = r117936 <= r117946;
        double r117948 = 1.0;
        double r117949 = 2.0;
        double r117950 = r117949 * r117942;
        double r117951 = r117936 * r117936;
        double r117952 = 4.0;
        double r117953 = r117952 * r117942;
        double r117954 = r117953 * r117940;
        double r117955 = r117951 - r117954;
        double r117956 = sqrt(r117955);
        double r117957 = r117956 - r117936;
        double r117958 = r117950 / r117957;
        double r117959 = r117948 / r117958;
        double r117960 = 1.4066822953018111e+103;
        bool r117961 = r117936 <= r117960;
        double r117962 = r117949 * r117940;
        double r117963 = -r117936;
        double r117964 = r117963 - r117956;
        double r117965 = r117962 / r117964;
        double r117966 = -1.0;
        double r117967 = r117966 * r117941;
        double r117968 = r117961 ? r117965 : r117967;
        double r117969 = r117947 ? r117959 : r117968;
        double r117970 = r117938 ? r117945 : r117969;
        return r117970;
}

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
Target20.6
Herbie6.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 < -2.8472042802820317e+48

    1. Initial program 38.1

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

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

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

    if -2.8472042802820317e+48 < b < -8.441935351115962e-251

    1. Initial program 9.0

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

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

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

    if -8.441935351115962e-251 < b < 1.4066822953018111e+103

    1. Initial program 30.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 flip-+30.1

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

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

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

      \[\leadsto \frac{0 + \left(4 \cdot a\right) \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \color{blue}{{\left(\frac{1}{2 \cdot a}\right)}^{1}}\]
    9. Applied pow115.8

      \[\leadsto \color{blue}{{\left(\frac{0 + \left(4 \cdot a\right) \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\right)}^{1}} \cdot {\left(\frac{1}{2 \cdot a}\right)}^{1}\]
    10. Applied pow-prod-down15.8

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

      \[\leadsto {\color{blue}{\left(\frac{\frac{\left(4 \cdot a\right) \cdot c}{2 \cdot a}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\right)}}^{1}\]
    12. Taylor expanded around 0 8.8

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

    if 1.4066822953018111e+103 < b

    1. Initial program 59.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.847204280282031663920354805138023860461 \cdot 10^{48}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -8.441935351115962169406457345797212275167 \cdot 10^{-251}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}\\ \mathbf{elif}\;b \le 1.406682295301811137671309943547484787165 \cdot 10^{103}:\\ \;\;\;\;\frac{2 \cdot c}{\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 2019212 +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)))