Average Error: 18.9 → 12.8
Time: 45.6s
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 5.005151079924739 \cdot 10^{+122}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\sqrt{\mathsf{fma}\left(\left(a \cdot -4\right), c, \left(b \cdot b\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(\left(a \cdot -4\right), c, \left(b \cdot b\right)\right)}}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\mathsf{fma}\left(\left(\sqrt{\sqrt{\mathsf{fma}\left(\left(a \cdot -4\right), c, \left(b \cdot b\right)\right)}}\right), \left(\sqrt{\sqrt{\mathsf{fma}\left(\left(a \cdot -4\right), c, \left(b \cdot b\right)\right)}}\right), \left(-b\right)\right)}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{\mathsf{fma}\left(\left(a \cdot -4\right), c, \left(b \cdot b\right)\right)} - b}\\ \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 5.005151079924739 \cdot 10^{+122}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\sqrt{\mathsf{fma}\left(\left(a \cdot -4\right), c, \left(b \cdot b\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(\left(a \cdot -4\right), c, \left(b \cdot b\right)\right)}}}{a \cdot 2}\\

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

\end{array}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r1207209 = b;
        double r1207210 = 0.0;
        bool r1207211 = r1207209 >= r1207210;
        double r1207212 = -r1207209;
        double r1207213 = r1207209 * r1207209;
        double r1207214 = 4.0;
        double r1207215 = a;
        double r1207216 = r1207214 * r1207215;
        double r1207217 = c;
        double r1207218 = r1207216 * r1207217;
        double r1207219 = r1207213 - r1207218;
        double r1207220 = sqrt(r1207219);
        double r1207221 = r1207212 - r1207220;
        double r1207222 = 2.0;
        double r1207223 = r1207222 * r1207215;
        double r1207224 = r1207221 / r1207223;
        double r1207225 = r1207222 * r1207217;
        double r1207226 = r1207212 + r1207220;
        double r1207227 = r1207225 / r1207226;
        double r1207228 = r1207211 ? r1207224 : r1207227;
        return r1207228;
}

double f(double a, double b, double c) {
        double r1207229 = b;
        double r1207230 = 5.005151079924739e+122;
        bool r1207231 = r1207229 <= r1207230;
        double r1207232 = 0.0;
        bool r1207233 = r1207229 >= r1207232;
        double r1207234 = -r1207229;
        double r1207235 = a;
        double r1207236 = -4.0;
        double r1207237 = r1207235 * r1207236;
        double r1207238 = c;
        double r1207239 = r1207229 * r1207229;
        double r1207240 = fma(r1207237, r1207238, r1207239);
        double r1207241 = sqrt(r1207240);
        double r1207242 = sqrt(r1207241);
        double r1207243 = r1207242 * r1207242;
        double r1207244 = r1207234 - r1207243;
        double r1207245 = 2.0;
        double r1207246 = r1207235 * r1207245;
        double r1207247 = r1207244 / r1207246;
        double r1207248 = r1207238 * r1207245;
        double r1207249 = fma(r1207242, r1207242, r1207234);
        double r1207250 = r1207248 / r1207249;
        double r1207251 = r1207233 ? r1207247 : r1207250;
        double r1207252 = r1207234 - r1207229;
        double r1207253 = r1207252 / r1207246;
        double r1207254 = r1207241 - r1207229;
        double r1207255 = r1207248 / r1207254;
        double r1207256 = r1207233 ? r1207253 : r1207255;
        double r1207257 = r1207231 ? r1207251 : r1207256;
        return r1207257;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 2 regimes
  2. if b < 5.005151079924739e+122

    1. Initial program 14.1

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

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

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

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

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

    if 5.005151079924739e+122 < b

    1. Initial program 50.0

      \[\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. Simplified49.9

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

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

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

Reproduce

herbie shell --seed 2019128 +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)))))))