Average Error: 19.5 → 13.3
Time: 20.9s
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.891777552454845 \cdot 10^{+74}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(\left(a \cdot -4\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(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}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\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 2.891777552454845 \cdot 10^{+74}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(\left(a \cdot -4\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(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}{2 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\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 r775430 = b;
        double r775431 = 0.0;
        bool r775432 = r775430 >= r775431;
        double r775433 = -r775430;
        double r775434 = r775430 * r775430;
        double r775435 = 4.0;
        double r775436 = a;
        double r775437 = r775435 * r775436;
        double r775438 = c;
        double r775439 = r775437 * r775438;
        double r775440 = r775434 - r775439;
        double r775441 = sqrt(r775440);
        double r775442 = r775433 - r775441;
        double r775443 = 2.0;
        double r775444 = r775443 * r775436;
        double r775445 = r775442 / r775444;
        double r775446 = r775443 * r775438;
        double r775447 = r775433 + r775441;
        double r775448 = r775446 / r775447;
        double r775449 = r775432 ? r775445 : r775448;
        return r775449;
}

double f(double a, double b, double c) {
        double r775450 = b;
        double r775451 = 2.891777552454845e+74;
        bool r775452 = r775450 <= r775451;
        double r775453 = 0.0;
        bool r775454 = r775450 >= r775453;
        double r775455 = -r775450;
        double r775456 = a;
        double r775457 = -4.0;
        double r775458 = r775456 * r775457;
        double r775459 = c;
        double r775460 = r775450 * r775450;
        double r775461 = fma(r775458, r775459, r775460);
        double r775462 = sqrt(r775461);
        double r775463 = r775455 - r775462;
        double r775464 = 2.0;
        double r775465 = r775464 * r775456;
        double r775466 = r775463 / r775465;
        double r775467 = r775464 * r775459;
        double r775468 = sqrt(r775462);
        double r775469 = fma(r775468, r775468, r775455);
        double r775470 = r775467 / r775469;
        double r775471 = r775454 ? r775466 : r775470;
        double r775472 = r775455 - r775450;
        double r775473 = r775472 / r775465;
        double r775474 = r775462 - r775450;
        double r775475 = r775467 / r775474;
        double r775476 = r775454 ? r775473 : r775475;
        double r775477 = r775452 ? r775471 : r775476;
        return r775477;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 2 regimes
  2. if b < 2.891777552454845e+74

    1. Initial program 15.2

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

      \[\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-sqrt15.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{\mathsf{fma}\left(\left(-4 \cdot a\right), c, \left(b \cdot b\right)\right)}} - b}\\ \end{array}\]
    5. Applied sqrt-prod15.3

      \[\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}\]
    6. Applied fma-neg15.3

      \[\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}\]

    if 2.891777552454845e+74 < b

    1. Initial program 38.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. Simplified38.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 4.5

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

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

Reproduce

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