Average Error: 33.7 → 10.0
Time: 20.4s
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.1982115506822474 \cdot 10^{+126}:\\ \;\;\;\;\mathsf{fma}\left(\frac{b_2}{a}, -2, \frac{\frac{1}{2}}{b_2} \cdot c\right)\\ \mathbf{elif}\;b_2 \le 2.6443485350724205 \cdot 10^{-92}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - c \cdot a} - 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.1982115506822474 \cdot 10^{+126}:\\
\;\;\;\;\mathsf{fma}\left(\frac{b_2}{a}, -2, \frac{\frac{1}{2}}{b_2} \cdot c\right)\\

\mathbf{elif}\;b_2 \le 2.6443485350724205 \cdot 10^{-92}:\\
\;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - c \cdot a} - 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 r628717 = b_2;
        double r628718 = -r628717;
        double r628719 = r628717 * r628717;
        double r628720 = a;
        double r628721 = c;
        double r628722 = r628720 * r628721;
        double r628723 = r628719 - r628722;
        double r628724 = sqrt(r628723);
        double r628725 = r628718 + r628724;
        double r628726 = r628725 / r628720;
        return r628726;
}

double f(double a, double b_2, double c) {
        double r628727 = b_2;
        double r628728 = -4.1982115506822474e+126;
        bool r628729 = r628727 <= r628728;
        double r628730 = a;
        double r628731 = r628727 / r628730;
        double r628732 = -2.0;
        double r628733 = 0.5;
        double r628734 = r628733 / r628727;
        double r628735 = c;
        double r628736 = r628734 * r628735;
        double r628737 = fma(r628731, r628732, r628736);
        double r628738 = 2.6443485350724205e-92;
        bool r628739 = r628727 <= r628738;
        double r628740 = r628727 * r628727;
        double r628741 = r628735 * r628730;
        double r628742 = r628740 - r628741;
        double r628743 = sqrt(r628742);
        double r628744 = r628743 - r628727;
        double r628745 = r628744 / r628730;
        double r628746 = -0.5;
        double r628747 = r628735 / r628727;
        double r628748 = r628746 * r628747;
        double r628749 = r628739 ? r628745 : r628748;
        double r628750 = r628729 ? r628737 : r628749;
        return r628750;
}

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.1982115506822474e+126

    1. Initial program 51.7

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

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}}\]
    3. Taylor expanded around -inf 51.7

      \[\leadsto \frac{\sqrt{\color{blue}{{b_2}^{2} - a \cdot c}} - b_2}{a}\]
    4. Simplified51.7

      \[\leadsto \frac{\sqrt{\color{blue}{b_2 \cdot b_2 - a \cdot c}} - b_2}{a}\]
    5. Taylor expanded around -inf 3.4

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

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

    if -4.1982115506822474e+126 < b_2 < 2.6443485350724205e-92

    1. Initial program 12.2

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

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}}\]
    3. Taylor expanded around -inf 12.2

      \[\leadsto \frac{\sqrt{\color{blue}{{b_2}^{2} - a \cdot c}} - b_2}{a}\]
    4. Simplified12.2

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

    if 2.6443485350724205e-92 < b_2

    1. Initial program 51.9

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

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

      \[\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.6

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

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

Reproduce

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