Average Error: 34.3 → 6.2
Time: 6.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 -8.00336887744975224 \cdot 10^{118}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -3.72191682831812008 \cdot 10^{-246}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 5.54044500863652378 \cdot 10^{145}:\\ \;\;\;\;\frac{\frac{1}{\frac{2}{4}} \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 -8.00336887744975224 \cdot 10^{118}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

\mathbf{elif}\;b \le 5.54044500863652378 \cdot 10^{145}:\\
\;\;\;\;\frac{\frac{1}{\frac{2}{4}} \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 r178853 = b;
        double r178854 = -r178853;
        double r178855 = r178853 * r178853;
        double r178856 = 4.0;
        double r178857 = a;
        double r178858 = r178856 * r178857;
        double r178859 = c;
        double r178860 = r178858 * r178859;
        double r178861 = r178855 - r178860;
        double r178862 = sqrt(r178861);
        double r178863 = r178854 + r178862;
        double r178864 = 2.0;
        double r178865 = r178864 * r178857;
        double r178866 = r178863 / r178865;
        return r178866;
}

double f(double a, double b, double c) {
        double r178867 = b;
        double r178868 = -8.003368877449752e+118;
        bool r178869 = r178867 <= r178868;
        double r178870 = 1.0;
        double r178871 = c;
        double r178872 = r178871 / r178867;
        double r178873 = a;
        double r178874 = r178867 / r178873;
        double r178875 = r178872 - r178874;
        double r178876 = r178870 * r178875;
        double r178877 = -3.72191682831812e-246;
        bool r178878 = r178867 <= r178877;
        double r178879 = -r178867;
        double r178880 = r178867 * r178867;
        double r178881 = 4.0;
        double r178882 = r178881 * r178873;
        double r178883 = r178882 * r178871;
        double r178884 = r178880 - r178883;
        double r178885 = sqrt(r178884);
        double r178886 = r178879 + r178885;
        double r178887 = 2.0;
        double r178888 = r178887 * r178873;
        double r178889 = r178886 / r178888;
        double r178890 = 5.540445008636524e+145;
        bool r178891 = r178867 <= r178890;
        double r178892 = 1.0;
        double r178893 = r178887 / r178881;
        double r178894 = r178892 / r178893;
        double r178895 = r178894 * r178871;
        double r178896 = r178879 - r178885;
        double r178897 = r178895 / r178896;
        double r178898 = -1.0;
        double r178899 = r178898 * r178872;
        double r178900 = r178891 ? r178897 : r178899;
        double r178901 = r178878 ? r178889 : r178900;
        double r178902 = r178869 ? r178876 : r178901;
        return r178902;
}

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
Herbie6.2
\[\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.003368877449752e+118

    1. Initial program 52.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.9

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

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

    if -8.003368877449752e+118 < b < -3.72191682831812e-246

    1. Initial program 7.5

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

    if -3.72191682831812e-246 < b < 5.540445008636524e+145

    1. Initial program 32.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 flip-+32.5

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

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

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

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

      \[\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*8.6

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

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

    if 5.540445008636524e+145 < b

    1. Initial program 63.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -8.00336887744975224 \cdot 10^{118}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -3.72191682831812008 \cdot 10^{-246}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 5.54044500863652378 \cdot 10^{145}:\\ \;\;\;\;\frac{\frac{1}{\frac{2}{4}} \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 2020049 +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)))