Average Error: 34.0 → 10.2
Time: 19.3s
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 -8.035809894237901445931970544225072398237 \cdot 10^{152}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{2}, \frac{c}{b_2}, \frac{b_2 \cdot -2}{a}\right)\\ \mathbf{elif}\;b_2 \le 6.407662420749314643846659194387390530859 \cdot 10^{-35}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - c \cdot a}}{a} - \frac{b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b_2} \cdot \frac{-1}{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 -8.035809894237901445931970544225072398237 \cdot 10^{152}:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{2}, \frac{c}{b_2}, \frac{b_2 \cdot -2}{a}\right)\\

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

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

\end{array}
double f(double a, double b_2, double c) {
        double r864707 = b_2;
        double r864708 = -r864707;
        double r864709 = r864707 * r864707;
        double r864710 = a;
        double r864711 = c;
        double r864712 = r864710 * r864711;
        double r864713 = r864709 - r864712;
        double r864714 = sqrt(r864713);
        double r864715 = r864708 + r864714;
        double r864716 = r864715 / r864710;
        return r864716;
}

double f(double a, double b_2, double c) {
        double r864717 = b_2;
        double r864718 = -8.035809894237901e+152;
        bool r864719 = r864717 <= r864718;
        double r864720 = 0.5;
        double r864721 = c;
        double r864722 = r864721 / r864717;
        double r864723 = -2.0;
        double r864724 = r864717 * r864723;
        double r864725 = a;
        double r864726 = r864724 / r864725;
        double r864727 = fma(r864720, r864722, r864726);
        double r864728 = 6.407662420749315e-35;
        bool r864729 = r864717 <= r864728;
        double r864730 = r864717 * r864717;
        double r864731 = r864721 * r864725;
        double r864732 = r864730 - r864731;
        double r864733 = sqrt(r864732);
        double r864734 = r864733 / r864725;
        double r864735 = r864717 / r864725;
        double r864736 = r864734 - r864735;
        double r864737 = -0.5;
        double r864738 = r864722 * r864737;
        double r864739 = r864729 ? r864736 : r864738;
        double r864740 = r864719 ? r864727 : r864739;
        return r864740;
}

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

    1. Initial program 63.6

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

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

      \[\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 2.0

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

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

    if -8.035809894237901e+152 < b_2 < 6.407662420749315e-35

    1. Initial program 13.9

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

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

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

    if 6.407662420749315e-35 < b_2

    1. Initial program 54.6

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

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

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

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

Reproduce

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