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

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

\end{array}\\

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

\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 r1277222 = b;
        double r1277223 = 0.0;
        bool r1277224 = r1277222 >= r1277223;
        double r1277225 = -r1277222;
        double r1277226 = r1277222 * r1277222;
        double r1277227 = 4.0;
        double r1277228 = a;
        double r1277229 = r1277227 * r1277228;
        double r1277230 = c;
        double r1277231 = r1277229 * r1277230;
        double r1277232 = r1277226 - r1277231;
        double r1277233 = sqrt(r1277232);
        double r1277234 = r1277225 - r1277233;
        double r1277235 = 2.0;
        double r1277236 = r1277235 * r1277228;
        double r1277237 = r1277234 / r1277236;
        double r1277238 = r1277235 * r1277230;
        double r1277239 = r1277225 + r1277233;
        double r1277240 = r1277238 / r1277239;
        double r1277241 = r1277224 ? r1277237 : r1277240;
        return r1277241;
}

double f(double a, double b, double c) {
        double r1277242 = b;
        double r1277243 = 8.748494799376129e+63;
        bool r1277244 = r1277242 <= r1277243;
        double r1277245 = 0.0;
        bool r1277246 = r1277242 >= r1277245;
        double r1277247 = -r1277242;
        double r1277248 = c;
        double r1277249 = a;
        double r1277250 = -4.0;
        double r1277251 = r1277249 * r1277250;
        double r1277252 = r1277242 * r1277242;
        double r1277253 = fma(r1277248, r1277251, r1277252);
        double r1277254 = sqrt(r1277253);
        double r1277255 = sqrt(r1277254);
        double r1277256 = r1277255 * r1277255;
        double r1277257 = r1277247 - r1277256;
        double r1277258 = 2.0;
        double r1277259 = r1277249 * r1277258;
        double r1277260 = r1277257 / r1277259;
        double r1277261 = r1277254 - r1277242;
        double r1277262 = r1277261 / r1277258;
        double r1277263 = r1277248 / r1277262;
        double r1277264 = r1277246 ? r1277260 : r1277263;
        double r1277265 = r1277247 - r1277242;
        double r1277266 = r1277265 / r1277259;
        double r1277267 = r1277246 ? r1277266 : r1277263;
        double r1277268 = r1277244 ? r1277264 : r1277267;
        return r1277268;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 2 regimes
  2. if b < 8.748494799376129e+63

    1. Initial program 15.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. Simplified15.1

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\color{blue}{\sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)} \cdot \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}\]
    5. Applied sqrt-prod15.2

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

    if 8.748494799376129e+63 < b

    1. Initial program 37.9

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

      \[\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 0 6.2

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \color{blue}{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}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification13.5

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