Average Error: 19.9 → 13.0
Time: 18.0s
Precision: 64
\[\begin{array}{l} \mathbf{if}\;b \ge 0.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.070196910432930661212410040231827918751 \cdot 10^{84}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-\left(\sqrt{\sqrt[3]{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)}} \cdot \left|\sqrt[3]{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)}\right| + b\right)\right) + \sqrt{\sqrt[3]{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)}} \cdot \left(\left(-\left|\sqrt[3]{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)}\right|\right) + \left|\sqrt[3]{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)}\right|\right)}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)} - b}\\ \end{array}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot \frac{b}{a}}{c} \cdot \left(c \cdot 2\right)\\ \end{array}\]
\begin{array}{l}
\mathbf{if}\;b \ge 0.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.070196910432930661212410040231827918751 \cdot 10^{84}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{\left(-\left(\sqrt{\sqrt[3]{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)}} \cdot \left|\sqrt[3]{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)}\right| + b\right)\right) + \sqrt{\sqrt[3]{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)}} \cdot \left(\left(-\left|\sqrt[3]{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)}\right|\right) + \left|\sqrt[3]{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)}\right|\right)}{a \cdot 2}\\

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

\end{array}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{-0.5 \cdot \frac{b}{a}}{c} \cdot \left(c \cdot 2\right)\\

\end{array}
double f(double a, double b, double c) {
        double r35387 = b;
        double r35388 = 0.0;
        bool r35389 = r35387 >= r35388;
        double r35390 = -r35387;
        double r35391 = r35387 * r35387;
        double r35392 = 4.0;
        double r35393 = a;
        double r35394 = r35392 * r35393;
        double r35395 = c;
        double r35396 = r35394 * r35395;
        double r35397 = r35391 - r35396;
        double r35398 = sqrt(r35397);
        double r35399 = r35390 - r35398;
        double r35400 = 2.0;
        double r35401 = r35400 * r35393;
        double r35402 = r35399 / r35401;
        double r35403 = r35400 * r35395;
        double r35404 = r35390 + r35398;
        double r35405 = r35403 / r35404;
        double r35406 = r35389 ? r35402 : r35405;
        return r35406;
}

double f(double a, double b, double c) {
        double r35407 = b;
        double r35408 = 2.0701969104329307e+84;
        bool r35409 = r35407 <= r35408;
        double r35410 = 0.0;
        bool r35411 = r35407 >= r35410;
        double r35412 = 4.0;
        double r35413 = a;
        double r35414 = r35412 * r35413;
        double r35415 = c;
        double r35416 = -r35415;
        double r35417 = r35407 * r35407;
        double r35418 = fma(r35414, r35416, r35417);
        double r35419 = cbrt(r35418);
        double r35420 = sqrt(r35419);
        double r35421 = fabs(r35419);
        double r35422 = r35420 * r35421;
        double r35423 = r35422 + r35407;
        double r35424 = -r35423;
        double r35425 = -r35421;
        double r35426 = r35425 + r35421;
        double r35427 = r35420 * r35426;
        double r35428 = r35424 + r35427;
        double r35429 = 2.0;
        double r35430 = r35413 * r35429;
        double r35431 = r35428 / r35430;
        double r35432 = r35415 * r35429;
        double r35433 = sqrt(r35418);
        double r35434 = r35433 - r35407;
        double r35435 = r35432 / r35434;
        double r35436 = r35411 ? r35431 : r35435;
        double r35437 = -r35407;
        double r35438 = r35437 - r35407;
        double r35439 = r35438 / r35430;
        double r35440 = -0.5;
        double r35441 = r35407 / r35413;
        double r35442 = r35440 * r35441;
        double r35443 = r35442 / r35415;
        double r35444 = r35443 * r35432;
        double r35445 = r35411 ? r35439 : r35444;
        double r35446 = r35409 ? r35436 : r35445;
        return r35446;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 2 regimes
  2. if b < 2.0701969104329307e+84

    1. Initial program 14.8

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

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

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

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

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

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

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

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

    if 2.0701969104329307e+84 < b

    1. Initial program 43.9

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

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

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

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\color{blue}{\left(2 \cdot c\right) \cdot \left(-0.5 \cdot \frac{b}{a \cdot c}\right)}\\ \end{array}\]
    8. Simplified3.7

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

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

Reproduce

herbie shell --seed 2019194 +o rules:numerics
(FPCore (a b c)
  :name "jeff quadratic root 1"
  (if (>= b 0.0) (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ (* 2.0 c) (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))))))