Average Error: 20.1 → 7.8
Time: 19.2s
Precision: 64
\[\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
\[\begin{array}{l} \mathbf{if}\;b \le -1.434128173054205306503791529718852543763 \cdot 10^{153}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\frac{{b}^{4} - \left(\left(4 \cdot a\right) \cdot c\right) \cdot \left(\left(4 \cdot a\right) \cdot c\right)}{\mathsf{fma}\left(b, b, \left(4 \cdot a\right) \cdot c\right)}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, a \cdot \frac{c}{b}, b \cdot -2\right)}\\ \end{array}\\ \mathbf{elif}\;b \le -5.066042609614386619694957941213132915138 \cdot 10^{-310} \lor \neg \left(b \le 5.031608061939102936286074782173578716838 \cdot 10^{53}\right):\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \left(b - 2 \cdot \frac{a \cdot c}{b}\right)}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\frac{\left(a \cdot c\right) \cdot 4}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\\ \end{array}\]
\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\

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

\end{array}
\begin{array}{l}
\mathbf{if}\;b \le -1.434128173054205306503791529718852543763 \cdot 10^{153}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\frac{{b}^{4} - \left(\left(4 \cdot a\right) \cdot c\right) \cdot \left(\left(4 \cdot a\right) \cdot c\right)}{\mathsf{fma}\left(b, b, \left(4 \cdot a\right) \cdot c\right)}}}{2 \cdot a}\\

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

\end{array}\\

\mathbf{elif}\;b \le -5.066042609614386619694957941213132915138 \cdot 10^{-310} \lor \neg \left(b \le 5.031608061939102936286074782173578716838 \cdot 10^{53}\right):\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{\left(-b\right) - \left(b - 2 \cdot \frac{a \cdot c}{b}\right)}{2 \cdot a}\\

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

\end{array}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r32982 = b;
        double r32983 = 0.0;
        bool r32984 = r32982 >= r32983;
        double r32985 = -r32982;
        double r32986 = r32982 * r32982;
        double r32987 = 4.0;
        double r32988 = a;
        double r32989 = r32987 * r32988;
        double r32990 = c;
        double r32991 = r32989 * r32990;
        double r32992 = r32986 - r32991;
        double r32993 = sqrt(r32992);
        double r32994 = r32985 - r32993;
        double r32995 = 2.0;
        double r32996 = r32995 * r32988;
        double r32997 = r32994 / r32996;
        double r32998 = r32995 * r32990;
        double r32999 = r32985 + r32993;
        double r33000 = r32998 / r32999;
        double r33001 = r32984 ? r32997 : r33000;
        return r33001;
}

double f(double a, double b, double c) {
        double r33002 = b;
        double r33003 = -1.4341281730542053e+153;
        bool r33004 = r33002 <= r33003;
        double r33005 = 0.0;
        bool r33006 = r33002 >= r33005;
        double r33007 = -r33002;
        double r33008 = 4.0;
        double r33009 = pow(r33002, r33008);
        double r33010 = 4.0;
        double r33011 = a;
        double r33012 = r33010 * r33011;
        double r33013 = c;
        double r33014 = r33012 * r33013;
        double r33015 = r33014 * r33014;
        double r33016 = r33009 - r33015;
        double r33017 = fma(r33002, r33002, r33014);
        double r33018 = r33016 / r33017;
        double r33019 = sqrt(r33018);
        double r33020 = r33007 - r33019;
        double r33021 = 2.0;
        double r33022 = r33021 * r33011;
        double r33023 = r33020 / r33022;
        double r33024 = r33021 * r33013;
        double r33025 = r33013 / r33002;
        double r33026 = r33011 * r33025;
        double r33027 = -2.0;
        double r33028 = r33002 * r33027;
        double r33029 = fma(r33021, r33026, r33028);
        double r33030 = r33024 / r33029;
        double r33031 = r33006 ? r33023 : r33030;
        double r33032 = -5.0660426096144e-310;
        bool r33033 = r33002 <= r33032;
        double r33034 = 5.031608061939103e+53;
        bool r33035 = r33002 <= r33034;
        double r33036 = !r33035;
        bool r33037 = r33033 || r33036;
        double r33038 = r33011 * r33013;
        double r33039 = r33038 / r33002;
        double r33040 = r33021 * r33039;
        double r33041 = r33002 - r33040;
        double r33042 = r33007 - r33041;
        double r33043 = r33042 / r33022;
        double r33044 = r33002 * r33002;
        double r33045 = r33044 - r33014;
        double r33046 = sqrt(r33045);
        double r33047 = r33007 + r33046;
        double r33048 = r33024 / r33047;
        double r33049 = r33006 ? r33043 : r33048;
        double r33050 = r33007 - r33046;
        double r33051 = r33050 / r33022;
        double r33052 = r33038 * r33010;
        double r33053 = r33052 / r33050;
        double r33054 = r33024 / r33053;
        double r33055 = r33006 ? r33051 : r33054;
        double r33056 = r33037 ? r33049 : r33055;
        double r33057 = r33004 ? r33031 : r33056;
        return r33057;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 3 regimes
  2. if b < -1.4341281730542053e+153

    1. Initial program 39.5

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

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

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\color{blue}{\frac{2 \cdot c}{\mathsf{fma}\left(2, \frac{a \cdot c}{b}, b \cdot -2\right)}}\\ \end{array}\]
    7. Using strategy rm
    8. Applied *-un-lft-identity6.6

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

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

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

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

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

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

    if -1.4341281730542053e+153 < b < -5.0660426096144e-310 or 5.031608061939103e+53 < b

    1. Initial program 18.7

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

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

    if -5.0660426096144e-310 < b < 5.031608061939103e+53

    1. Initial program 10.0

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.434128173054205306503791529718852543763 \cdot 10^{153}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\frac{{b}^{4} - \left(\left(4 \cdot a\right) \cdot c\right) \cdot \left(\left(4 \cdot a\right) \cdot c\right)}{\mathsf{fma}\left(b, b, \left(4 \cdot a\right) \cdot c\right)}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, a \cdot \frac{c}{b}, b \cdot -2\right)}\\ \end{array}\\ \mathbf{elif}\;b \le -5.066042609614386619694957941213132915138 \cdot 10^{-310} \lor \neg \left(b \le 5.031608061939102936286074782173578716838 \cdot 10^{53}\right):\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \left(b - 2 \cdot \frac{a \cdot c}{b}\right)}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\frac{\left(a \cdot c\right) \cdot 4}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\\ \end{array}\]

Reproduce

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