Average Error: 34.0 → 10.6
Time: 18.6s
Precision: 64
\[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
\[\begin{array}{l} \mathbf{if}\;b_2 \le -9.332433396832084322962138528577137922234 \cdot 10^{-58}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{c}{b_2}\\ \mathbf{elif}\;b_2 \le 2.875629862348269923009864799258754597338 \cdot 10^{107}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\sqrt[3]{b_2} \cdot \sqrt[3]{b_2}, -\sqrt[3]{b_2}, -\sqrt{b_2 \cdot b_2 - c \cdot a}\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{c}{b_2}, \frac{1}{2}, \frac{-2 \cdot b_2}{a}\right)\\ \end{array}\]
\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}
\begin{array}{l}
\mathbf{if}\;b_2 \le -9.332433396832084322962138528577137922234 \cdot 10^{-58}:\\
\;\;\;\;\frac{-1}{2} \cdot \frac{c}{b_2}\\

\mathbf{elif}\;b_2 \le 2.875629862348269923009864799258754597338 \cdot 10^{107}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\sqrt[3]{b_2} \cdot \sqrt[3]{b_2}, -\sqrt[3]{b_2}, -\sqrt{b_2 \cdot b_2 - c \cdot a}\right)}{a}\\

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

\end{array}
double f(double a, double b_2, double c) {
        double r731812 = b_2;
        double r731813 = -r731812;
        double r731814 = r731812 * r731812;
        double r731815 = a;
        double r731816 = c;
        double r731817 = r731815 * r731816;
        double r731818 = r731814 - r731817;
        double r731819 = sqrt(r731818);
        double r731820 = r731813 - r731819;
        double r731821 = r731820 / r731815;
        return r731821;
}

double f(double a, double b_2, double c) {
        double r731822 = b_2;
        double r731823 = -9.332433396832084e-58;
        bool r731824 = r731822 <= r731823;
        double r731825 = -0.5;
        double r731826 = c;
        double r731827 = r731826 / r731822;
        double r731828 = r731825 * r731827;
        double r731829 = 2.87562986234827e+107;
        bool r731830 = r731822 <= r731829;
        double r731831 = cbrt(r731822);
        double r731832 = r731831 * r731831;
        double r731833 = -r731831;
        double r731834 = r731822 * r731822;
        double r731835 = a;
        double r731836 = r731826 * r731835;
        double r731837 = r731834 - r731836;
        double r731838 = sqrt(r731837);
        double r731839 = -r731838;
        double r731840 = fma(r731832, r731833, r731839);
        double r731841 = r731840 / r731835;
        double r731842 = 0.5;
        double r731843 = -2.0;
        double r731844 = r731843 * r731822;
        double r731845 = r731844 / r731835;
        double r731846 = fma(r731827, r731842, r731845);
        double r731847 = r731830 ? r731841 : r731846;
        double r731848 = r731824 ? r731828 : r731847;
        return r731848;
}

Error

Bits error versus a

Bits error versus b_2

Bits error versus c

Derivation

  1. Split input into 3 regimes
  2. if b_2 < -9.332433396832084e-58

    1. Initial program 53.5

      \[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
    2. Taylor expanded around -inf 8.7

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot \frac{c}{b_2}}\]

    if -9.332433396832084e-58 < b_2 < 2.87562986234827e+107

    1. Initial program 14.0

      \[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
    2. Using strategy rm
    3. Applied add-cube-cbrt14.2

      \[\leadsto \frac{\left(-\color{blue}{\left(\sqrt[3]{b_2} \cdot \sqrt[3]{b_2}\right) \cdot \sqrt[3]{b_2}}\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
    4. Applied distribute-rgt-neg-in14.2

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{b_2} \cdot \sqrt[3]{b_2}\right) \cdot \left(-\sqrt[3]{b_2}\right)} - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
    5. Applied fma-neg14.2

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\sqrt[3]{b_2} \cdot \sqrt[3]{b_2}, -\sqrt[3]{b_2}, -\sqrt{b_2 \cdot b_2 - a \cdot c}\right)}}{a}\]

    if 2.87562986234827e+107 < b_2

    1. Initial program 49.0

      \[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
    2. Taylor expanded around inf 3.4

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{c}{b_2} - 2 \cdot \frac{b_2}{a}}\]
    3. Simplified3.5

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{c}{b_2}, \frac{1}{2}, \frac{-2 \cdot b_2}{a}\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification10.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \le -9.332433396832084322962138528577137922234 \cdot 10^{-58}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{c}{b_2}\\ \mathbf{elif}\;b_2 \le 2.875629862348269923009864799258754597338 \cdot 10^{107}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\sqrt[3]{b_2} \cdot \sqrt[3]{b_2}, -\sqrt[3]{b_2}, -\sqrt{b_2 \cdot b_2 - c \cdot a}\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{c}{b_2}, \frac{1}{2}, \frac{-2 \cdot b_2}{a}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019171 +o rules:numerics
(FPCore (a b_2 c)
  :name "quad2m (problem 3.2.1, negative)"
  (/ (- (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))