Average Error: 19.7 → 13.2
Time: 34.5s
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 3.7440019496974325 \cdot 10^{-305}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{-\frac{\mathsf{fma}\left(b, b \cdot b, \mathsf{fma}\left(a \cdot c, -4, b \cdot b\right) \cdot \sqrt{\mathsf{fma}\left(a \cdot c, -4, b \cdot b\right)}\right)}{\mathsf{fma}\left(\sqrt{\mathsf{fma}\left(a \cdot c, -4, b \cdot b\right)} - b, \sqrt{\mathsf{fma}\left(a \cdot c, -4, b \cdot b\right)}, b \cdot b\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{\frac{\sqrt{\mathsf{fma}\left(c, -4 \cdot a, b \cdot b\right)} - b}{2}}\\ \end{array}\\ \mathbf{elif}\;b \le 7.548494687587984 \cdot 10^{+83}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(c, -4 \cdot a, b \cdot b\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{0}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \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 3.7440019496974325 \cdot 10^{-305}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0:\\
\;\;\;\;\frac{-\frac{\mathsf{fma}\left(b, b \cdot b, \mathsf{fma}\left(a \cdot c, -4, b \cdot b\right) \cdot \sqrt{\mathsf{fma}\left(a \cdot c, -4, b \cdot b\right)}\right)}{\mathsf{fma}\left(\sqrt{\mathsf{fma}\left(a \cdot c, -4, b \cdot b\right)} - b, \sqrt{\mathsf{fma}\left(a \cdot c, -4, b \cdot b\right)}, b \cdot b\right)}}{a \cdot 2}\\

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

\end{array}\\

\mathbf{elif}\;b \le 7.548494687587984 \cdot 10^{+83}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(c, -4 \cdot a, b \cdot b\right)}}{a \cdot 2}\\

\mathbf{else}:\\
\;\;\;\;\frac{c}{0}\\

\end{array}\\

\mathbf{elif}\;b \ge 0:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

\end{array}
double f(double a, double b, double c) {
        double r736732 = b;
        double r736733 = 0.0;
        bool r736734 = r736732 >= r736733;
        double r736735 = -r736732;
        double r736736 = r736732 * r736732;
        double r736737 = 4.0;
        double r736738 = a;
        double r736739 = r736737 * r736738;
        double r736740 = c;
        double r736741 = r736739 * r736740;
        double r736742 = r736736 - r736741;
        double r736743 = sqrt(r736742);
        double r736744 = r736735 - r736743;
        double r736745 = 2.0;
        double r736746 = r736745 * r736738;
        double r736747 = r736744 / r736746;
        double r736748 = r736745 * r736740;
        double r736749 = r736735 + r736743;
        double r736750 = r736748 / r736749;
        double r736751 = r736734 ? r736747 : r736750;
        return r736751;
}

double f(double a, double b, double c) {
        double r736752 = b;
        double r736753 = 3.7440019496974325e-305;
        bool r736754 = r736752 <= r736753;
        double r736755 = 0.0;
        bool r736756 = r736752 >= r736755;
        double r736757 = r736752 * r736752;
        double r736758 = a;
        double r736759 = c;
        double r736760 = r736758 * r736759;
        double r736761 = -4.0;
        double r736762 = fma(r736760, r736761, r736757);
        double r736763 = sqrt(r736762);
        double r736764 = r736762 * r736763;
        double r736765 = fma(r736752, r736757, r736764);
        double r736766 = r736763 - r736752;
        double r736767 = fma(r736766, r736763, r736757);
        double r736768 = r736765 / r736767;
        double r736769 = -r736768;
        double r736770 = 2.0;
        double r736771 = r736758 * r736770;
        double r736772 = r736769 / r736771;
        double r736773 = r736761 * r736758;
        double r736774 = fma(r736759, r736773, r736757);
        double r736775 = sqrt(r736774);
        double r736776 = r736775 - r736752;
        double r736777 = r736776 / r736770;
        double r736778 = r736759 / r736777;
        double r736779 = r736756 ? r736772 : r736778;
        double r736780 = 7.548494687587984e+83;
        bool r736781 = r736752 <= r736780;
        double r736782 = -r736752;
        double r736783 = r736782 - r736775;
        double r736784 = r736783 / r736771;
        double r736785 = r736759 / r736755;
        double r736786 = r736756 ? r736784 : r736785;
        double r736787 = r736759 / r736752;
        double r736788 = r736752 / r736758;
        double r736789 = r736787 - r736788;
        double r736790 = r736782 / r736758;
        double r736791 = r736756 ? r736789 : r736790;
        double r736792 = r736781 ? r736786 : r736791;
        double r736793 = r736754 ? r736779 : r736792;
        return r736793;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 3 regimes
  2. if b < 3.7440019496974325e-305

    1. Initial program 18.2

      \[\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. Simplified18.2

      \[\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 flip3--18.2

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

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

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

    1. Initial program 9.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. Simplified9.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 9.1

      \[\leadsto \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{\color{blue}{c}}{\frac{0}{2}}\\ \end{array}\]

    if 7.548494687587984e+83 < b

    1. Initial program 42.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. Simplified42.4

      \[\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 inf 9.9

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\color{blue}{2 \cdot \left(\frac{a}{\frac{b}{c}} - 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. Taylor expanded around 0 4.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le 3.7440019496974325 \cdot 10^{-305}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{-\frac{\mathsf{fma}\left(b, b \cdot b, \mathsf{fma}\left(a \cdot c, -4, b \cdot b\right) \cdot \sqrt{\mathsf{fma}\left(a \cdot c, -4, b \cdot b\right)}\right)}{\mathsf{fma}\left(\sqrt{\mathsf{fma}\left(a \cdot c, -4, b \cdot b\right)} - b, \sqrt{\mathsf{fma}\left(a \cdot c, -4, b \cdot b\right)}, b \cdot b\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{\frac{\sqrt{\mathsf{fma}\left(c, -4 \cdot a, b \cdot b\right)} - b}{2}}\\ \end{array}\\ \mathbf{elif}\;b \le 7.548494687587984 \cdot 10^{+83}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(c, -4 \cdot a, b \cdot b\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{0}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]

Reproduce

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