Average Error: 19.2 → 13.2
Time: 1.1m
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 4.765469847044928 \cdot 10^{+77}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \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)}}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \frac{c}{\sqrt{\mathsf{fma}\left(\left(a \cdot -4\right), c, \left(b \cdot b\right)\right)} - b}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \frac{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 4.765469847044928 \cdot 10^{+77}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0:\\
\;\;\;\;\frac{\left(-b\right) - \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)}}}{a \cdot 2}\\

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

\end{array}\\

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

\mathbf{else}:\\
\;\;\;\;2 \cdot \frac{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 r2749734 = b;
        double r2749735 = 0.0;
        bool r2749736 = r2749734 >= r2749735;
        double r2749737 = -r2749734;
        double r2749738 = r2749734 * r2749734;
        double r2749739 = 4.0;
        double r2749740 = a;
        double r2749741 = r2749739 * r2749740;
        double r2749742 = c;
        double r2749743 = r2749741 * r2749742;
        double r2749744 = r2749738 - r2749743;
        double r2749745 = sqrt(r2749744);
        double r2749746 = r2749737 - r2749745;
        double r2749747 = 2.0;
        double r2749748 = r2749747 * r2749740;
        double r2749749 = r2749746 / r2749748;
        double r2749750 = r2749747 * r2749742;
        double r2749751 = r2749737 + r2749745;
        double r2749752 = r2749750 / r2749751;
        double r2749753 = r2749736 ? r2749749 : r2749752;
        return r2749753;
}

double f(double a, double b, double c) {
        double r2749754 = b;
        double r2749755 = 4.765469847044928e+77;
        bool r2749756 = r2749754 <= r2749755;
        double r2749757 = 0.0;
        bool r2749758 = r2749754 >= r2749757;
        double r2749759 = -r2749754;
        double r2749760 = a;
        double r2749761 = -4.0;
        double r2749762 = r2749760 * r2749761;
        double r2749763 = c;
        double r2749764 = r2749754 * r2749754;
        double r2749765 = fma(r2749762, r2749763, r2749764);
        double r2749766 = sqrt(r2749765);
        double r2749767 = sqrt(r2749766);
        double r2749768 = r2749767 * r2749767;
        double r2749769 = r2749759 - r2749768;
        double r2749770 = 2.0;
        double r2749771 = r2749760 * r2749770;
        double r2749772 = r2749769 / r2749771;
        double r2749773 = r2749766 - r2749754;
        double r2749774 = r2749763 / r2749773;
        double r2749775 = r2749770 * r2749774;
        double r2749776 = r2749758 ? r2749772 : r2749775;
        double r2749777 = r2749759 - r2749754;
        double r2749778 = r2749777 / r2749771;
        double r2749779 = r2749758 ? r2749778 : r2749775;
        double r2749780 = r2749756 ? r2749776 : r2749779;
        return r2749780;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 2 regimes
  2. if b < 4.765469847044928e+77

    1. Initial program 14.8

      \[\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.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. Using strategy rm
    4. Applied add-sqr-sqrt14.8

      \[\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-prod14.8

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

    if 4.765469847044928e+77 < b

    1. Initial program 40.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. Simplified40.1

      \[\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 0 5.1

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \color{blue}{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}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification13.2

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

Reproduce

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