Average Error: 33.0 → 10.6
Time: 20.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 -3.794505329565205 \cdot 10^{+146}:\\ \;\;\;\;\mathsf{fma}\left(\left(\frac{b_2}{a}\right), -2, \left(\frac{\frac{1}{2}}{b_2} \cdot c\right)\right)\\ \mathbf{elif}\;b_2 \le 1.6194276288860963:\\ \;\;\;\;\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 -3.794505329565205 \cdot 10^{+146}:\\
\;\;\;\;\mathsf{fma}\left(\left(\frac{b_2}{a}\right), -2, \left(\frac{\frac{1}{2}}{b_2} \cdot c\right)\right)\\

\mathbf{elif}\;b_2 \le 1.6194276288860963:\\
\;\;\;\;\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 r684426 = b_2;
        double r684427 = -r684426;
        double r684428 = r684426 * r684426;
        double r684429 = a;
        double r684430 = c;
        double r684431 = r684429 * r684430;
        double r684432 = r684428 - r684431;
        double r684433 = sqrt(r684432);
        double r684434 = r684427 + r684433;
        double r684435 = r684434 / r684429;
        return r684435;
}

double f(double a, double b_2, double c) {
        double r684436 = b_2;
        double r684437 = -3.794505329565205e+146;
        bool r684438 = r684436 <= r684437;
        double r684439 = a;
        double r684440 = r684436 / r684439;
        double r684441 = -2.0;
        double r684442 = 0.5;
        double r684443 = r684442 / r684436;
        double r684444 = c;
        double r684445 = r684443 * r684444;
        double r684446 = fma(r684440, r684441, r684445);
        double r684447 = 1.6194276288860963;
        bool r684448 = r684436 <= r684447;
        double r684449 = r684436 * r684436;
        double r684450 = r684444 * r684439;
        double r684451 = r684449 - r684450;
        double r684452 = sqrt(r684451);
        double r684453 = r684452 - r684436;
        double r684454 = r684453 / r684439;
        double r684455 = -0.5;
        double r684456 = r684444 / r684436;
        double r684457 = r684455 * r684456;
        double r684458 = r684448 ? r684454 : r684457;
        double r684459 = r684438 ? r684446 : r684458;
        return r684459;
}

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 < -3.794505329565205e+146

    1. Initial program 58.0

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

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

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

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

    if -3.794505329565205e+146 < b_2 < 1.6194276288860963

    1. Initial program 15.0

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

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

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

      \[\leadsto \frac{\sqrt{\color{blue}{b_2 \cdot b_2 - a \cdot c}} - b_2}{a}\]
    5. Using strategy rm
    6. Applied div-inv15.1

      \[\leadsto \color{blue}{\left(\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2\right) \cdot \frac{1}{a}}\]
    7. Using strategy rm
    8. Applied associate-*r/15.0

      \[\leadsto \color{blue}{\frac{\left(\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2\right) \cdot 1}{a}}\]
    9. Simplified15.0

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

    if 1.6194276288860963 < b_2

    1. Initial program 54.4

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \le -3.794505329565205 \cdot 10^{+146}:\\ \;\;\;\;\mathsf{fma}\left(\left(\frac{b_2}{a}\right), -2, \left(\frac{\frac{1}{2}}{b_2} \cdot c\right)\right)\\ \mathbf{elif}\;b_2 \le 1.6194276288860963:\\ \;\;\;\;\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 2019129 +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))