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

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

\end{array}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r38040 = b;
        double r38041 = 0.0;
        bool r38042 = r38040 >= r38041;
        double r38043 = 2.0;
        double r38044 = c;
        double r38045 = r38043 * r38044;
        double r38046 = -r38040;
        double r38047 = r38040 * r38040;
        double r38048 = 4.0;
        double r38049 = a;
        double r38050 = r38048 * r38049;
        double r38051 = r38050 * r38044;
        double r38052 = r38047 - r38051;
        double r38053 = sqrt(r38052);
        double r38054 = r38046 - r38053;
        double r38055 = r38045 / r38054;
        double r38056 = r38046 + r38053;
        double r38057 = r38043 * r38049;
        double r38058 = r38056 / r38057;
        double r38059 = r38042 ? r38055 : r38058;
        return r38059;
}

double f(double a, double b, double c) {
        double r38060 = b;
        double r38061 = 3.756010775197467e+134;
        bool r38062 = r38060 <= r38061;
        double r38063 = 0.0;
        bool r38064 = r38060 >= r38063;
        double r38065 = 2.0;
        double r38066 = c;
        double r38067 = r38065 * r38066;
        double r38068 = -r38060;
        double r38069 = 4.0;
        double r38070 = r38069 * r38066;
        double r38071 = a;
        double r38072 = -r38071;
        double r38073 = r38060 * r38060;
        double r38074 = fma(r38070, r38072, r38073);
        double r38075 = cbrt(r38074);
        double r38076 = sqrt(r38075);
        double r38077 = r38069 * r38071;
        double r38078 = -r38066;
        double r38079 = r38077 * r38078;
        double r38080 = fma(r38060, r38060, r38079);
        double r38081 = cbrt(r38080);
        double r38082 = sqrt(r38081);
        double r38083 = r38082 * r38082;
        double r38084 = fabs(r38083);
        double r38085 = r38076 * r38084;
        double r38086 = r38068 - r38085;
        double r38087 = r38067 / r38086;
        double r38088 = sqrt(r38074);
        double r38089 = r38088 - r38060;
        double r38090 = r38089 / r38065;
        double r38091 = r38090 / r38071;
        double r38092 = r38064 ? r38087 : r38091;
        double r38093 = r38068 - r38060;
        double r38094 = r38067 / r38093;
        double r38095 = r38064 ? r38094 : r38091;
        double r38096 = r38062 ? r38092 : r38095;
        return r38096;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 2 regimes
  2. if b < 3.756010775197467e+134

    1. Initial program 16.3

      \[\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. Simplified16.3

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

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

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

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

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

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

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

    if 3.756010775197467e+134 < b

    1. Initial program 34.7

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

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

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

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