Average Error: 19.0 → 13.1
Time: 16.3s
Precision: 64
\[\begin{array}{l} \mathbf{if}\;b \ge 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 2.428102982638899 \cdot 10^{+100}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{\frac{\sqrt{\mathsf{fma}\left(\sqrt{\sqrt[3]{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)} \cdot \sqrt[3]{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}, \sqrt{\sqrt[3]{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}, -b\right)} \cdot \sqrt{\sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)} - b}}{2}}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot \left(c \cdot \frac{a}{b} - b\right)}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{\frac{\sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)} - b}{2}}\\ \end{array}\]
\begin{array}{l}
\mathbf{if}\;b \ge 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 2.428102982638899 \cdot 10^{+100}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}{2 \cdot a}\\

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

\end{array}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r492192 = b;
        double r492193 = 0.0;
        bool r492194 = r492192 >= r492193;
        double r492195 = -r492192;
        double r492196 = r492192 * r492192;
        double r492197 = 4.0;
        double r492198 = a;
        double r492199 = r492197 * r492198;
        double r492200 = c;
        double r492201 = r492199 * r492200;
        double r492202 = r492196 - r492201;
        double r492203 = sqrt(r492202);
        double r492204 = r492195 - r492203;
        double r492205 = 2.0;
        double r492206 = r492205 * r492198;
        double r492207 = r492204 / r492206;
        double r492208 = r492205 * r492200;
        double r492209 = r492195 + r492203;
        double r492210 = r492208 / r492209;
        double r492211 = r492194 ? r492207 : r492210;
        return r492211;
}

double f(double a, double b, double c) {
        double r492212 = b;
        double r492213 = 2.428102982638899e+100;
        bool r492214 = r492212 <= r492213;
        double r492215 = 0.0;
        bool r492216 = r492212 >= r492215;
        double r492217 = -r492212;
        double r492218 = c;
        double r492219 = a;
        double r492220 = -4.0;
        double r492221 = r492219 * r492220;
        double r492222 = r492212 * r492212;
        double r492223 = fma(r492218, r492221, r492222);
        double r492224 = sqrt(r492223);
        double r492225 = r492217 - r492224;
        double r492226 = 2.0;
        double r492227 = r492226 * r492219;
        double r492228 = r492225 / r492227;
        double r492229 = cbrt(r492223);
        double r492230 = r492229 * r492229;
        double r492231 = sqrt(r492230);
        double r492232 = sqrt(r492229);
        double r492233 = fma(r492231, r492232, r492217);
        double r492234 = sqrt(r492233);
        double r492235 = r492224 - r492212;
        double r492236 = sqrt(r492235);
        double r492237 = r492234 * r492236;
        double r492238 = r492237 / r492226;
        double r492239 = r492218 / r492238;
        double r492240 = r492216 ? r492228 : r492239;
        double r492241 = r492219 / r492212;
        double r492242 = r492218 * r492241;
        double r492243 = r492242 - r492212;
        double r492244 = r492226 * r492243;
        double r492245 = r492244 / r492227;
        double r492246 = r492235 / r492226;
        double r492247 = r492218 / r492246;
        double r492248 = r492216 ? r492245 : r492247;
        double r492249 = r492214 ? r492240 : r492248;
        return r492249;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 2 regimes
  2. if b < 2.428102982638899e+100

    1. Initial program 14.6

      \[\begin{array}{l} \mathbf{if}\;b \ge 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. Simplified14.6

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

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{\frac{\sqrt{\sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)} - b} \cdot \sqrt{\sqrt{\sqrt[3]{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)} \cdot \sqrt[3]{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}} \cdot \sqrt{\sqrt[3]{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}} - b}}{2}}\\ \end{array}\]
    8. Applied fma-neg14.7

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

    if 2.428102982638899e+100 < b

    1. Initial program 43.6

      \[\begin{array}{l} \mathbf{if}\;b \ge 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. Simplified43.5

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

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

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

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

Reproduce

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