Average Error: 19.9 → 7.8
Time: 18.7s
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 -1.35190676294417 \cdot 10^{154}:\\ \;\;\;\;\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{\mathsf{fma}\left(2, \frac{a \cdot c}{b}, b \cdot -2\right)}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \le 2.34940293042711077 \cdot 10^{98}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left|\sqrt{\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}}\right| \cdot \sqrt{\sqrt[3]{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}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, \frac{a}{\sqrt[3]{b} \cdot \sqrt[3]{b}} \cdot \frac{c}{\sqrt[3]{b}}, b \cdot -2\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 -1.35190676294417 \cdot 10^{154}:\\
\;\;\;\;\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{\mathsf{fma}\left(2, \frac{a \cdot c}{b}, b \cdot -2\right)}{2 \cdot a}\\

\end{array}\\

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

\mathbf{elif}\;b \ge 0.0:\\
\;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, \frac{a}{\sqrt[3]{b} \cdot \sqrt[3]{b}} \cdot \frac{c}{\sqrt[3]{b}}, b \cdot -2\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 r33842 = b;
        double r33843 = 0.0;
        bool r33844 = r33842 >= r33843;
        double r33845 = 2.0;
        double r33846 = c;
        double r33847 = r33845 * r33846;
        double r33848 = -r33842;
        double r33849 = r33842 * r33842;
        double r33850 = 4.0;
        double r33851 = a;
        double r33852 = r33850 * r33851;
        double r33853 = r33852 * r33846;
        double r33854 = r33849 - r33853;
        double r33855 = sqrt(r33854);
        double r33856 = r33848 - r33855;
        double r33857 = r33847 / r33856;
        double r33858 = r33848 + r33855;
        double r33859 = r33845 * r33851;
        double r33860 = r33858 / r33859;
        double r33861 = r33844 ? r33857 : r33860;
        return r33861;
}

double f(double a, double b, double c) {
        double r33862 = b;
        double r33863 = -1.35190676294417e+154;
        bool r33864 = r33862 <= r33863;
        double r33865 = 0.0;
        bool r33866 = r33862 >= r33865;
        double r33867 = 2.0;
        double r33868 = c;
        double r33869 = r33867 * r33868;
        double r33870 = -r33862;
        double r33871 = r33862 * r33862;
        double r33872 = 4.0;
        double r33873 = a;
        double r33874 = r33872 * r33873;
        double r33875 = r33874 * r33868;
        double r33876 = r33871 - r33875;
        double r33877 = sqrt(r33876);
        double r33878 = r33870 - r33877;
        double r33879 = r33869 / r33878;
        double r33880 = r33873 * r33868;
        double r33881 = r33880 / r33862;
        double r33882 = -2.0;
        double r33883 = r33862 * r33882;
        double r33884 = fma(r33867, r33881, r33883);
        double r33885 = r33867 * r33873;
        double r33886 = r33884 / r33885;
        double r33887 = r33866 ? r33879 : r33886;
        double r33888 = 2.3494029304271108e+98;
        bool r33889 = r33862 <= r33888;
        double r33890 = cbrt(r33876);
        double r33891 = sqrt(r33890);
        double r33892 = r33891 * r33891;
        double r33893 = fabs(r33892);
        double r33894 = r33893 * r33891;
        double r33895 = r33870 - r33894;
        double r33896 = r33869 / r33895;
        double r33897 = r33870 + r33877;
        double r33898 = r33897 / r33885;
        double r33899 = r33866 ? r33896 : r33898;
        double r33900 = cbrt(r33862);
        double r33901 = r33900 * r33900;
        double r33902 = r33873 / r33901;
        double r33903 = r33868 / r33900;
        double r33904 = r33902 * r33903;
        double r33905 = fma(r33867, r33904, r33883);
        double r33906 = r33869 / r33905;
        double r33907 = r33866 ? r33906 : r33898;
        double r33908 = r33889 ? r33899 : r33907;
        double r33909 = r33864 ? r33887 : r33908;
        return r33909;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 3 regimes
  2. if b < -1.35190676294417e+154

    1. Initial program 64.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. Taylor expanded around -inf 10.8

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

      \[\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{\mathsf{fma}\left(2, \frac{a \cdot c}{b}, b \cdot -2\right)}{2 \cdot a}\\ \end{array}\]

    if -1.35190676294417e+154 < b < 2.3494029304271108e+98

    1. Initial program 8.9

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

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{\left|\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}\right|} \cdot \sqrt{\sqrt[3]{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}\]
    6. Using strategy rm
    7. Applied add-sqr-sqrt9.1

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

    if 2.3494029304271108e+98 < b

    1. Initial program 30.1

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\color{blue}{\mathsf{fma}\left(2, \frac{a \cdot c}{b}, b \cdot -2\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
    4. Using strategy rm
    5. Applied add-cube-cbrt6.4

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, \frac{a \cdot c}{\color{blue}{\left(\sqrt[3]{b} \cdot \sqrt[3]{b}\right) \cdot \sqrt[3]{b}}}, b \cdot -2\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
    6. Applied times-frac2.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, \color{blue}{\frac{a}{\sqrt[3]{b} \cdot \sqrt[3]{b}} \cdot \frac{c}{\sqrt[3]{b}}}, b \cdot -2\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\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 simplification7.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.35190676294417 \cdot 10^{154}:\\ \;\;\;\;\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{\mathsf{fma}\left(2, \frac{a \cdot c}{b}, b \cdot -2\right)}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \le 2.34940293042711077 \cdot 10^{98}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left|\sqrt{\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}}\right| \cdot \sqrt{\sqrt[3]{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}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, \frac{a}{\sqrt[3]{b} \cdot \sqrt[3]{b}} \cdot \frac{c}{\sqrt[3]{b}}, b \cdot -2\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 2019195 +o rules:numerics
(FPCore (a b c)
  :name "jeff quadratic root 2"
  (if (>= b 0.0) (/ (* 2.0 c) (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c))))) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a))))