Average Error: 33.6 → 9.6
Time: 24.5s
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 -4.1672202318347805 \cdot 10^{+152}:\\ \;\;\;\;\mathsf{fma}\left(-2, \frac{b_2}{a}, \frac{c}{b_2} \cdot \frac{1}{2}\right)\\ \mathbf{elif}\;b_2 \le 5.69412176017963 \cdot 10^{-84}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - c \cdot a}}{a} - \frac{b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{c}{b_2}\\ \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 -4.1672202318347805 \cdot 10^{+152}:\\
\;\;\;\;\mathsf{fma}\left(-2, \frac{b_2}{a}, \frac{c}{b_2} \cdot \frac{1}{2}\right)\\

\mathbf{elif}\;b_2 \le 5.69412176017963 \cdot 10^{-84}:\\
\;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - c \cdot a}}{a} - \frac{b_2}{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{-1}{2} \cdot \frac{c}{b_2}\\

\end{array}
double f(double a, double b_2, double c) {
        double r467764 = b_2;
        double r467765 = -r467764;
        double r467766 = r467764 * r467764;
        double r467767 = a;
        double r467768 = c;
        double r467769 = r467767 * r467768;
        double r467770 = r467766 - r467769;
        double r467771 = sqrt(r467770);
        double r467772 = r467765 + r467771;
        double r467773 = r467772 / r467767;
        return r467773;
}

double f(double a, double b_2, double c) {
        double r467774 = b_2;
        double r467775 = -4.1672202318347805e+152;
        bool r467776 = r467774 <= r467775;
        double r467777 = -2.0;
        double r467778 = a;
        double r467779 = r467774 / r467778;
        double r467780 = c;
        double r467781 = r467780 / r467774;
        double r467782 = 0.5;
        double r467783 = r467781 * r467782;
        double r467784 = fma(r467777, r467779, r467783);
        double r467785 = 5.69412176017963e-84;
        bool r467786 = r467774 <= r467785;
        double r467787 = r467774 * r467774;
        double r467788 = r467780 * r467778;
        double r467789 = r467787 - r467788;
        double r467790 = sqrt(r467789);
        double r467791 = r467790 / r467778;
        double r467792 = r467791 - r467779;
        double r467793 = -0.5;
        double r467794 = r467793 * r467781;
        double r467795 = r467786 ? r467792 : r467794;
        double r467796 = r467776 ? r467784 : r467795;
        return r467796;
}

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 < -4.1672202318347805e+152

    1. Initial program 60.5

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
    2. Simplified60.5

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}}\]
    3. Using strategy rm
    4. Applied div-inv60.5

      \[\leadsto \color{blue}{\left(\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2\right) \cdot \frac{1}{a}}\]
    5. Taylor expanded around -inf 1.7

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{c}{b_2} - 2 \cdot \frac{b_2}{a}}\]
    6. Simplified1.7

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

    if -4.1672202318347805e+152 < b_2 < 5.69412176017963e-84

    1. Initial program 11.7

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
    2. Simplified11.7

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}}\]
    3. Using strategy rm
    4. Applied div-sub11.7

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c}}{a} - \frac{b_2}{a}}\]

    if 5.69412176017963e-84 < b_2

    1. Initial program 52.1

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
    2. Simplified52.1

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}}\]
    3. Using strategy rm
    4. Applied div-inv52.2

      \[\leadsto \color{blue}{\left(\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2\right) \cdot \frac{1}{a}}\]
    5. Taylor expanded around inf 9.2

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot \frac{c}{b_2}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification9.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \le -4.1672202318347805 \cdot 10^{+152}:\\ \;\;\;\;\mathsf{fma}\left(-2, \frac{b_2}{a}, \frac{c}{b_2} \cdot \frac{1}{2}\right)\\ \mathbf{elif}\;b_2 \le 5.69412176017963 \cdot 10^{-84}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - c \cdot a}}{a} - \frac{b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{c}{b_2}\\ \end{array}\]

Reproduce

herbie shell --seed 2019144 +o rules:numerics
(FPCore (a b_2 c)
  :name "quad2p (problem 3.2.1, positive)"
  (/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))