Average Error: 19.5 → 7.2
Time: 20.5s
Precision: 64
\[\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
\[\begin{array}{l} \mathbf{if}\;b \le -1.2969712652290727 \cdot 10^{130}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-2 \cdot b}{2}}{a}\\ \end{array}\\ \mathbf{elif}\;b \le 6.215531586102827 \cdot 10^{101}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(\sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}, \sqrt{\left|\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}\right| \cdot \sqrt{\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}}}, -b\right)}{2}}{a}\\ \end{array}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left(b - 2 \cdot \frac{a \cdot c}{b}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}{a}\\ \end{array}\]
\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\

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

\end{array}
\begin{array}{l}
\mathbf{if}\;b \le -1.2969712652290727 \cdot 10^{130}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{-2 \cdot b}{2}}{a}\\

\end{array}\\

\mathbf{elif}\;b \le 6.215531586102827 \cdot 10^{101}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\

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

\end{array}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r32561 = b;
        double r32562 = 0.0;
        bool r32563 = r32561 >= r32562;
        double r32564 = 2.0;
        double r32565 = c;
        double r32566 = r32564 * r32565;
        double r32567 = -r32561;
        double r32568 = r32561 * r32561;
        double r32569 = 4.0;
        double r32570 = a;
        double r32571 = r32569 * r32570;
        double r32572 = r32571 * r32565;
        double r32573 = r32568 - r32572;
        double r32574 = sqrt(r32573);
        double r32575 = r32567 - r32574;
        double r32576 = r32566 / r32575;
        double r32577 = r32567 + r32574;
        double r32578 = r32564 * r32570;
        double r32579 = r32577 / r32578;
        double r32580 = r32563 ? r32576 : r32579;
        return r32580;
}

double f(double a, double b, double c) {
        double r32581 = b;
        double r32582 = -1.2969712652290727e+130;
        bool r32583 = r32581 <= r32582;
        double r32584 = 0.0;
        bool r32585 = r32581 >= r32584;
        double r32586 = 2.0;
        double r32587 = c;
        double r32588 = r32586 * r32587;
        double r32589 = -r32581;
        double r32590 = r32581 * r32581;
        double r32591 = 4.0;
        double r32592 = a;
        double r32593 = r32591 * r32592;
        double r32594 = r32593 * r32587;
        double r32595 = r32590 - r32594;
        double r32596 = sqrt(r32595);
        double r32597 = r32589 - r32596;
        double r32598 = r32588 / r32597;
        double r32599 = -2.0;
        double r32600 = r32599 * r32581;
        double r32601 = r32600 / r32586;
        double r32602 = r32601 / r32592;
        double r32603 = r32585 ? r32598 : r32602;
        double r32604 = 6.215531586102827e+101;
        bool r32605 = r32581 <= r32604;
        double r32606 = sqrt(r32596);
        double r32607 = cbrt(r32595);
        double r32608 = fabs(r32607);
        double r32609 = sqrt(r32607);
        double r32610 = r32608 * r32609;
        double r32611 = sqrt(r32610);
        double r32612 = fma(r32606, r32611, r32589);
        double r32613 = r32612 / r32586;
        double r32614 = r32613 / r32592;
        double r32615 = r32585 ? r32598 : r32614;
        double r32616 = r32592 * r32587;
        double r32617 = r32616 / r32581;
        double r32618 = r32586 * r32617;
        double r32619 = r32581 - r32618;
        double r32620 = r32589 - r32619;
        double r32621 = r32588 / r32620;
        double r32622 = r32596 - r32581;
        double r32623 = r32622 / r32586;
        double r32624 = r32623 / r32592;
        double r32625 = r32585 ? r32621 : r32624;
        double r32626 = r32605 ? r32615 : r32625;
        double r32627 = r32583 ? r32603 : r32626;
        return r32627;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 3 regimes
  2. if b < -1.2969712652290727e+130

    1. Initial program 55.2

      \[\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
    2. Simplified55.2

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

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

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

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

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

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

    if -1.2969712652290727e+130 < b < 6.215531586102827e+101

    1. Initial program 8.2

      \[\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
    2. Simplified8.2

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

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

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

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

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

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

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

    if 6.215531586102827e+101 < b

    1. Initial program 30.7

      \[\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
    2. Simplified30.7

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

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

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

Reproduce

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