Average Error: 34.5 → 10.4
Time: 15.7s
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 -63362873442066488610789523456:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{a}, -2, 2 \cdot \frac{c}{b}\right)}{2}\\ \mathbf{elif}\;b \le 6.484072051994263737451444554171174935457 \cdot 10^{-107}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(\sqrt{\sqrt[3]{b \cdot b - a \cdot \left(4 \cdot c\right)} \cdot \sqrt[3]{b \cdot b - a \cdot \left(4 \cdot c\right)}}, \sqrt{\sqrt[3]{b \cdot b - a \cdot \left(4 \cdot c\right)}}, -b\right)}{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c}{b} \cdot -2}{2}\\ \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 -63362873442066488610789523456:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{a}, -2, 2 \cdot \frac{c}{b}\right)}{2}\\

\mathbf{elif}\;b \le 6.484072051994263737451444554171174935457 \cdot 10^{-107}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(\sqrt{\sqrt[3]{b \cdot b - a \cdot \left(4 \cdot c\right)} \cdot \sqrt[3]{b \cdot b - a \cdot \left(4 \cdot c\right)}}, \sqrt{\sqrt[3]{b \cdot b - a \cdot \left(4 \cdot c\right)}}, -b\right)}{a}}{2}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{c}{b} \cdot -2}{2}\\

\end{array}
double f(double a, double b, double c) {
        double r1513877 = b;
        double r1513878 = -r1513877;
        double r1513879 = r1513877 * r1513877;
        double r1513880 = 4.0;
        double r1513881 = a;
        double r1513882 = r1513880 * r1513881;
        double r1513883 = c;
        double r1513884 = r1513882 * r1513883;
        double r1513885 = r1513879 - r1513884;
        double r1513886 = sqrt(r1513885);
        double r1513887 = r1513878 + r1513886;
        double r1513888 = 2.0;
        double r1513889 = r1513888 * r1513881;
        double r1513890 = r1513887 / r1513889;
        return r1513890;
}

double f(double a, double b, double c) {
        double r1513891 = b;
        double r1513892 = -6.336287344206649e+28;
        bool r1513893 = r1513891 <= r1513892;
        double r1513894 = a;
        double r1513895 = r1513891 / r1513894;
        double r1513896 = -2.0;
        double r1513897 = 2.0;
        double r1513898 = c;
        double r1513899 = r1513898 / r1513891;
        double r1513900 = r1513897 * r1513899;
        double r1513901 = fma(r1513895, r1513896, r1513900);
        double r1513902 = r1513901 / r1513897;
        double r1513903 = 6.484072051994264e-107;
        bool r1513904 = r1513891 <= r1513903;
        double r1513905 = r1513891 * r1513891;
        double r1513906 = 4.0;
        double r1513907 = r1513906 * r1513898;
        double r1513908 = r1513894 * r1513907;
        double r1513909 = r1513905 - r1513908;
        double r1513910 = cbrt(r1513909);
        double r1513911 = r1513910 * r1513910;
        double r1513912 = sqrt(r1513911);
        double r1513913 = sqrt(r1513910);
        double r1513914 = -r1513891;
        double r1513915 = fma(r1513912, r1513913, r1513914);
        double r1513916 = r1513915 / r1513894;
        double r1513917 = r1513916 / r1513897;
        double r1513918 = -2.0;
        double r1513919 = r1513899 * r1513918;
        double r1513920 = r1513919 / r1513897;
        double r1513921 = r1513904 ? r1513917 : r1513920;
        double r1513922 = r1513893 ? r1513902 : r1513921;
        return r1513922;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 3 regimes
  2. if b < -6.336287344206649e+28

    1. Initial program 34.8

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

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

      \[\leadsto \frac{\color{blue}{2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}}}{2}\]
    4. Simplified7.0

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

    if -6.336287344206649e+28 < b < 6.484072051994264e-107

    1. Initial program 12.9

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

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}{a}}{2}}\]
    3. Using strategy rm
    4. Applied add-cube-cbrt13.4

      \[\leadsto \frac{\frac{\sqrt{\color{blue}{\left(\sqrt[3]{b \cdot b - \left(4 \cdot c\right) \cdot a} \cdot \sqrt[3]{b \cdot b - \left(4 \cdot c\right) \cdot a}\right) \cdot \sqrt[3]{b \cdot b - \left(4 \cdot c\right) \cdot a}}} - b}{a}}{2}\]
    5. Applied sqrt-prod13.4

      \[\leadsto \frac{\frac{\color{blue}{\sqrt{\sqrt[3]{b \cdot b - \left(4 \cdot c\right) \cdot a} \cdot \sqrt[3]{b \cdot b - \left(4 \cdot c\right) \cdot a}} \cdot \sqrt{\sqrt[3]{b \cdot b - \left(4 \cdot c\right) \cdot a}}} - b}{a}}{2}\]
    6. Applied fma-neg13.4

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

    if 6.484072051994264e-107 < b

    1. Initial program 52.5

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -63362873442066488610789523456:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{a}, -2, 2 \cdot \frac{c}{b}\right)}{2}\\ \mathbf{elif}\;b \le 6.484072051994263737451444554171174935457 \cdot 10^{-107}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(\sqrt{\sqrt[3]{b \cdot b - a \cdot \left(4 \cdot c\right)} \cdot \sqrt[3]{b \cdot b - a \cdot \left(4 \cdot c\right)}}, \sqrt{\sqrt[3]{b \cdot b - a \cdot \left(4 \cdot c\right)}}, -b\right)}{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c}{b} \cdot -2}{2}\\ \end{array}\]

Reproduce

herbie shell --seed 2019192 +o rules:numerics
(FPCore (a b c)
  :name "Quadratic roots, full range"
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))