Average Error: 34.1 → 6.9
Time: 17.0s
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.46337219442650475190360405115215330559 \cdot 10^{111}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -3.104620340175948664814965097441450913118 \cdot 10^{-300}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.201425921513023399093785571786407855582 \cdot 10^{53}:\\ \;\;\;\;\frac{1}{\frac{2}{c} \cdot \frac{a}{\frac{4 \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 -2.46337219442650475190360405115215330559 \cdot 10^{111}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

\mathbf{elif}\;b \le 3.201425921513023399093785571786407855582 \cdot 10^{53}:\\
\;\;\;\;\frac{1}{\frac{2}{c} \cdot \frac{a}{\frac{4 \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 r82945 = b;
        double r82946 = -r82945;
        double r82947 = r82945 * r82945;
        double r82948 = 4.0;
        double r82949 = a;
        double r82950 = r82948 * r82949;
        double r82951 = c;
        double r82952 = r82950 * r82951;
        double r82953 = r82947 - r82952;
        double r82954 = sqrt(r82953);
        double r82955 = r82946 + r82954;
        double r82956 = 2.0;
        double r82957 = r82956 * r82949;
        double r82958 = r82955 / r82957;
        return r82958;
}

double f(double a, double b, double c) {
        double r82959 = b;
        double r82960 = -2.463372194426505e+111;
        bool r82961 = r82959 <= r82960;
        double r82962 = 1.0;
        double r82963 = c;
        double r82964 = r82963 / r82959;
        double r82965 = a;
        double r82966 = r82959 / r82965;
        double r82967 = r82964 - r82966;
        double r82968 = r82962 * r82967;
        double r82969 = -3.1046203401759487e-300;
        bool r82970 = r82959 <= r82969;
        double r82971 = -r82959;
        double r82972 = r82959 * r82959;
        double r82973 = 4.0;
        double r82974 = r82973 * r82965;
        double r82975 = r82974 * r82963;
        double r82976 = r82972 - r82975;
        double r82977 = sqrt(r82976);
        double r82978 = r82971 + r82977;
        double r82979 = 1.0;
        double r82980 = 2.0;
        double r82981 = r82980 * r82965;
        double r82982 = r82979 / r82981;
        double r82983 = r82978 * r82982;
        double r82984 = 3.2014259215130234e+53;
        bool r82985 = r82959 <= r82984;
        double r82986 = r82980 / r82963;
        double r82987 = r82971 - r82977;
        double r82988 = r82974 / r82987;
        double r82989 = r82965 / r82988;
        double r82990 = r82986 * r82989;
        double r82991 = r82979 / r82990;
        double r82992 = -1.0;
        double r82993 = r82992 * r82964;
        double r82994 = r82985 ? r82991 : r82993;
        double r82995 = r82970 ? r82983 : r82994;
        double r82996 = r82961 ? r82968 : r82995;
        return r82996;
}

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.1
Target21.0
Herbie6.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 4 regimes
  2. if b < -2.463372194426505e+111

    1. Initial program 48.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.0

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

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

    if -2.463372194426505e+111 < b < -3.1046203401759487e-300

    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 div-inv8.6

      \[\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}}\]

    if -3.1046203401759487e-300 < b < 3.2014259215130234e+53

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

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

      \[\leadsto \frac{\frac{0 + \left(4 \cdot a\right) \cdot c}{\color{blue}{1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}}{2 \cdot a}\]
    7. Applied *-un-lft-identity17.1

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

      \[\leadsto \frac{\color{blue}{\frac{1}{1} \cdot \frac{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}\]
    9. Applied associate-/l*17.3

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

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

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

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

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

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

    if 3.2014259215130234e+53 < b

    1. Initial program 58.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.46337219442650475190360405115215330559 \cdot 10^{111}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -3.104620340175948664814965097441450913118 \cdot 10^{-300}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.201425921513023399093785571786407855582 \cdot 10^{53}:\\ \;\;\;\;\frac{1}{\frac{2}{c} \cdot \frac{a}{\frac{4 \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 2019326 +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)))