Average Error: 19.0 → 6.5
Time: 57.0s
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 -7.702550992737937 \cdot 10^{+129}:\\ \;\;\;\;\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{c \cdot 2}{2 \cdot \left(a \cdot \frac{c}{b} - b\right)}\\ \end{array}\\ \mathbf{elif}\;b \le 9.567411701732677 \cdot 10^{+88}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{-\left(b + \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)}}\right)}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{\sqrt{\mathsf{fma}\left(\left(a \cdot -4\right), c, \left(b \cdot b\right)\right)} - b} \cdot 2\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot \left(a \cdot \frac{c}{b} - b\right)}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{\sqrt{\mathsf{fma}\left(\left(a \cdot -4\right), c, \left(b \cdot b\right)\right)} - b} \cdot 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 -7.702550992737937 \cdot 10^{+129}:\\
\;\;\;\;\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{c \cdot 2}{2 \cdot \left(a \cdot \frac{c}{b} - b\right)}\\

\end{array}\\

\mathbf{elif}\;b \le 9.567411701732677 \cdot 10^{+88}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0:\\
\;\;\;\;\frac{-\left(b + \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)}}\right)}{2 \cdot a}\\

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

\end{array}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r1489456 = b;
        double r1489457 = 0.0;
        bool r1489458 = r1489456 >= r1489457;
        double r1489459 = -r1489456;
        double r1489460 = r1489456 * r1489456;
        double r1489461 = 4.0;
        double r1489462 = a;
        double r1489463 = r1489461 * r1489462;
        double r1489464 = c;
        double r1489465 = r1489463 * r1489464;
        double r1489466 = r1489460 - r1489465;
        double r1489467 = sqrt(r1489466);
        double r1489468 = r1489459 - r1489467;
        double r1489469 = 2.0;
        double r1489470 = r1489469 * r1489462;
        double r1489471 = r1489468 / r1489470;
        double r1489472 = r1489469 * r1489464;
        double r1489473 = r1489459 + r1489467;
        double r1489474 = r1489472 / r1489473;
        double r1489475 = r1489458 ? r1489471 : r1489474;
        return r1489475;
}

double f(double a, double b, double c) {
        double r1489476 = b;
        double r1489477 = -7.702550992737937e+129;
        bool r1489478 = r1489476 <= r1489477;
        double r1489479 = 0.0;
        bool r1489480 = r1489476 >= r1489479;
        double r1489481 = -r1489476;
        double r1489482 = r1489476 * r1489476;
        double r1489483 = 4.0;
        double r1489484 = a;
        double r1489485 = r1489483 * r1489484;
        double r1489486 = c;
        double r1489487 = r1489485 * r1489486;
        double r1489488 = r1489482 - r1489487;
        double r1489489 = sqrt(r1489488);
        double r1489490 = r1489481 - r1489489;
        double r1489491 = 2.0;
        double r1489492 = r1489491 * r1489484;
        double r1489493 = r1489490 / r1489492;
        double r1489494 = r1489486 * r1489491;
        double r1489495 = r1489486 / r1489476;
        double r1489496 = r1489484 * r1489495;
        double r1489497 = r1489496 - r1489476;
        double r1489498 = r1489491 * r1489497;
        double r1489499 = r1489494 / r1489498;
        double r1489500 = r1489480 ? r1489493 : r1489499;
        double r1489501 = 9.567411701732677e+88;
        bool r1489502 = r1489476 <= r1489501;
        double r1489503 = -4.0;
        double r1489504 = r1489484 * r1489503;
        double r1489505 = fma(r1489504, r1489486, r1489482);
        double r1489506 = sqrt(r1489505);
        double r1489507 = sqrt(r1489506);
        double r1489508 = r1489507 * r1489507;
        double r1489509 = r1489476 + r1489508;
        double r1489510 = -r1489509;
        double r1489511 = r1489510 / r1489492;
        double r1489512 = r1489506 - r1489476;
        double r1489513 = r1489486 / r1489512;
        double r1489514 = r1489513 * r1489491;
        double r1489515 = r1489480 ? r1489511 : r1489514;
        double r1489516 = r1489498 / r1489492;
        double r1489517 = r1489480 ? r1489516 : r1489514;
        double r1489518 = r1489502 ? r1489515 : r1489517;
        double r1489519 = r1489478 ? r1489500 : r1489518;
        return r1489519;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 3 regimes
  2. if b < -7.702550992737937e+129

    1. Initial program 33.5

      \[\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. Taylor expanded around -inf 5.5

      \[\leadsto \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}:\\ \;\;\;\;\color{blue}{\frac{2 \cdot c}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}}\\ \end{array}\]
    3. Simplified1.6

      \[\leadsto \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}:\\ \;\;\;\;\color{blue}{\frac{2 \cdot c}{\left(\frac{c}{b} \cdot a - b\right) \cdot 2}}\\ \end{array}\]

    if -7.702550992737937e+129 < b < 9.567411701732677e+88

    1. Initial program 8.5

      \[\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. Simplified8.5

      \[\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}:\\ \;\;\;\;2 \cdot \frac{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-sqrt8.5

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

      \[\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}:\\ \;\;\;\;2 \cdot \frac{c}{\sqrt{\mathsf{fma}\left(\left(-4 \cdot a\right), c, \left(b \cdot b\right)\right)} - b}\\ \end{array}\]
    6. Using strategy rm
    7. Applied neg-sub08.6

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

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

    if 9.567411701732677e+88 < b

    1. Initial program 41.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. Simplified41.8

      \[\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}:\\ \;\;\;\;2 \cdot \frac{c}{\sqrt{\mathsf{fma}\left(\left(-4 \cdot a\right), c, \left(b \cdot b\right)\right)} - b}\\ \end{array}}\]
    3. Taylor expanded around inf 9.6

      \[\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}:\\ \;\;\;\;2 \cdot \frac{c}{\sqrt{\mathsf{fma}\left(\left(-4 \cdot a\right), c, \left(b \cdot b\right)\right)} - b}\\ \end{array}\]
    4. Simplified4.3

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

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

Reproduce

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