Average Error: 20.3 → 6.8
Time: 5.8s
Precision: 64
\[\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
\[\begin{array}{l} \mathbf{if}\;b \le -8.414325781162306498501522769992383289429 \cdot 10^{113}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{{\left(-b\right)}^{3} - {\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}^{3}} \cdot \left(\left(-b\right) \cdot \left(-b\right) + \left(\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) \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\\ \mathbf{elif}\;b \le -6.724716266922556499072228000203116587273 \cdot 10^{-252}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left(\frac{1}{b} \cdot b - \left(1 - b\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \le 5.263391352577237531613239682082042403214 \cdot 10^{98}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(b, b, -\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left(\frac{1}{b} \cdot b - \left(1 - b\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\

\end{array}
\begin{array}{l}
\mathbf{if}\;b \le -8.414325781162306498501522769992383289429 \cdot 10^{113}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{2 \cdot c}{{\left(-b\right)}^{3} - {\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}^{3}} \cdot \left(\left(-b\right) \cdot \left(-b\right) + \left(\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) \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\end{array}\\

\mathbf{elif}\;b \le -6.724716266922556499072228000203116587273 \cdot 10^{-252}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left(\frac{1}{b} \cdot b - \left(1 - b\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\

\end{array}\\

\mathbf{elif}\;b \le 5.263391352577237531613239682082042403214 \cdot 10^{98}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(b, b, -\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\

\end{array}\\

\mathbf{elif}\;b \ge 0.0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left(\frac{1}{b} \cdot b - \left(1 - b\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\

\end{array}
double f(double a, double b, double c) {
        double r38885 = b;
        double r38886 = 0.0;
        bool r38887 = r38885 >= r38886;
        double r38888 = 2.0;
        double r38889 = c;
        double r38890 = r38888 * r38889;
        double r38891 = -r38885;
        double r38892 = r38885 * r38885;
        double r38893 = 4.0;
        double r38894 = a;
        double r38895 = r38893 * r38894;
        double r38896 = r38895 * r38889;
        double r38897 = r38892 - r38896;
        double r38898 = sqrt(r38897);
        double r38899 = r38891 - r38898;
        double r38900 = r38890 / r38899;
        double r38901 = r38891 + r38898;
        double r38902 = r38888 * r38894;
        double r38903 = r38901 / r38902;
        double r38904 = r38887 ? r38900 : r38903;
        return r38904;
}

double f(double a, double b, double c) {
        double r38905 = b;
        double r38906 = -8.414325781162306e+113;
        bool r38907 = r38905 <= r38906;
        double r38908 = 0.0;
        bool r38909 = r38905 >= r38908;
        double r38910 = 2.0;
        double r38911 = c;
        double r38912 = r38910 * r38911;
        double r38913 = -r38905;
        double r38914 = 3.0;
        double r38915 = pow(r38913, r38914);
        double r38916 = r38905 * r38905;
        double r38917 = 4.0;
        double r38918 = a;
        double r38919 = r38917 * r38918;
        double r38920 = r38919 * r38911;
        double r38921 = r38916 - r38920;
        double r38922 = sqrt(r38921);
        double r38923 = pow(r38922, r38914);
        double r38924 = r38915 - r38923;
        double r38925 = r38912 / r38924;
        double r38926 = r38913 * r38913;
        double r38927 = r38922 * r38922;
        double r38928 = r38913 * r38922;
        double r38929 = r38927 + r38928;
        double r38930 = r38926 + r38929;
        double r38931 = r38925 * r38930;
        double r38932 = 1.0;
        double r38933 = r38911 / r38905;
        double r38934 = r38905 / r38918;
        double r38935 = r38933 - r38934;
        double r38936 = r38932 * r38935;
        double r38937 = r38909 ? r38931 : r38936;
        double r38938 = -6.7247162669225565e-252;
        bool r38939 = r38905 <= r38938;
        double r38940 = 1.0;
        double r38941 = r38940 / r38905;
        double r38942 = r38941 * r38905;
        double r38943 = r38940 - r38905;
        double r38944 = r38942 - r38943;
        double r38945 = r38913 - r38944;
        double r38946 = r38912 / r38945;
        double r38947 = r38913 + r38922;
        double r38948 = r38910 * r38918;
        double r38949 = r38947 / r38948;
        double r38950 = r38909 ? r38946 : r38949;
        double r38951 = 5.2633913525772375e+98;
        bool r38952 = r38905 <= r38951;
        double r38953 = r38913 - r38922;
        double r38954 = r38912 / r38953;
        double r38955 = -r38921;
        double r38956 = fma(r38905, r38905, r38955);
        double r38957 = r38956 / r38953;
        double r38958 = r38957 / r38948;
        double r38959 = r38909 ? r38954 : r38958;
        double r38960 = r38952 ? r38959 : r38950;
        double r38961 = r38939 ? r38950 : r38960;
        double r38962 = r38907 ? r38937 : r38961;
        return r38962;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 3 regimes
  2. if b < -8.414325781162306e+113

    1. Initial program 50.6

      \[\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
    2. Taylor expanded around -inf 11.1

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}{2 \cdot a}\\ \end{array}\]
    3. Taylor expanded around 0 3.9

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\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} - 1 \cdot \frac{b}{a}\\ \end{array}\]
    4. Simplified3.9

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\]
    5. Using strategy rm
    6. Applied flip3--3.9

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\color{blue}{\frac{{\left(-b\right)}^{3} - {\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}^{3}}{\left(-b\right) \cdot \left(-b\right) + \left(\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) \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\]
    7. Applied associate-/r/3.9

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\color{blue}{\frac{2 \cdot c}{{\left(-b\right)}^{3} - {\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}^{3}} \cdot \left(\left(-b\right) \cdot \left(-b\right) + \left(\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) \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\]

    if -8.414325781162306e+113 < b < -6.7247162669225565e-252 or 5.2633913525772375e+98 < b

    1. Initial program 19.2

      \[\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
    2. Using strategy rm
    3. Applied expm1-log1p-u19.6

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
    4. Taylor expanded around inf 7.7

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{\left(\left(e^{-\log \left(\frac{1}{b}\right)} + \frac{e^{-\log \left(\frac{1}{b}\right)}}{b}\right) - 1\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
    5. Simplified6.2

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{\left(\frac{1}{b} \cdot b - \left(1 - b\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]

    if -6.7247162669225565e-252 < b < 5.2633913525772375e+98

    1. Initial program 9.0

      \[\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
    2. Using strategy rm
    3. Applied flip-+9.0

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\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}\\ \end{array}\]
    4. Simplified9.1

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(b, b, -\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \end{array}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification6.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -8.414325781162306498501522769992383289429 \cdot 10^{113}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{{\left(-b\right)}^{3} - {\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}^{3}} \cdot \left(\left(-b\right) \cdot \left(-b\right) + \left(\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) \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\\ \mathbf{elif}\;b \le -6.724716266922556499072228000203116587273 \cdot 10^{-252}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left(\frac{1}{b} \cdot b - \left(1 - b\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \le 5.263391352577237531613239682082042403214 \cdot 10^{98}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(b, b, -\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left(\frac{1}{b} \cdot b - \left(1 - b\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]

Reproduce

herbie shell --seed 2019353 +o rules:numerics
(FPCore (a b c)
  :name "jeff quadratic root 2"
  :precision binary64
  (if (>= b 0.0) (/ (* 2 c) (- (- b) (sqrt (- (* b b) (* (* 4 a) c))))) (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a))))