Average Error: 19.1 → 13.3
Time: 18.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 2.6220942974526774 \cdot 10^{+104}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\sqrt[3]{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}} \cdot \sqrt{\sqrt[3]{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)} \cdot \sqrt[3]{\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}{0}\\ \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.6220942974526774 \cdot 10^{+104}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\sqrt[3]{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}} \cdot \sqrt{\sqrt[3]{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)} \cdot \sqrt[3]{\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}{0}\\

\end{array}
double f(double a, double b, double c) {
        double r468499 = b;
        double r468500 = 0.0;
        bool r468501 = r468499 >= r468500;
        double r468502 = -r468499;
        double r468503 = r468499 * r468499;
        double r468504 = 4.0;
        double r468505 = a;
        double r468506 = r468504 * r468505;
        double r468507 = c;
        double r468508 = r468506 * r468507;
        double r468509 = r468503 - r468508;
        double r468510 = sqrt(r468509);
        double r468511 = r468502 - r468510;
        double r468512 = 2.0;
        double r468513 = r468512 * r468505;
        double r468514 = r468511 / r468513;
        double r468515 = r468512 * r468507;
        double r468516 = r468502 + r468510;
        double r468517 = r468515 / r468516;
        double r468518 = r468501 ? r468514 : r468517;
        return r468518;
}

double f(double a, double b, double c) {
        double r468519 = b;
        double r468520 = 2.6220942974526774e+104;
        bool r468521 = r468519 <= r468520;
        double r468522 = 0.0;
        bool r468523 = r468519 >= r468522;
        double r468524 = -r468519;
        double r468525 = c;
        double r468526 = a;
        double r468527 = -4.0;
        double r468528 = r468526 * r468527;
        double r468529 = r468519 * r468519;
        double r468530 = fma(r468525, r468528, r468529);
        double r468531 = cbrt(r468530);
        double r468532 = sqrt(r468531);
        double r468533 = r468531 * r468531;
        double r468534 = sqrt(r468533);
        double r468535 = r468532 * r468534;
        double r468536 = r468524 - r468535;
        double r468537 = 2.0;
        double r468538 = r468526 * r468537;
        double r468539 = r468536 / r468538;
        double r468540 = sqrt(r468530);
        double r468541 = r468540 - r468519;
        double r468542 = r468541 / r468537;
        double r468543 = r468525 / r468542;
        double r468544 = r468523 ? r468539 : r468543;
        double r468545 = r468524 - r468519;
        double r468546 = r468545 / r468538;
        double r468547 = r468525 / r468522;
        double r468548 = r468523 ? r468546 : r468547;
        double r468549 = r468521 ? r468544 : r468548;
        return r468549;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 2 regimes
  2. if b < 2.6220942974526774e+104

    1. Initial program 14.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. Simplified14.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. Using strategy rm
    4. Applied add-cube-cbrt15.0

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

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

    1. Initial program 44.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. Simplified44.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. Taylor expanded around 0 3.1

      \[\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}\]
    4. Taylor expanded around 0 3.1

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

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

Reproduce

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