Average Error: 34.5 → 9.6
Time: 43.0s
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 -1.585466010660367 \cdot 10^{+150}:\\ \;\;\;\;\mathsf{fma}\left(-2, \frac{b_2}{a}, \frac{\frac{c}{b_2}}{2}\right)\\ \mathbf{elif}\;b_2 \le 1.3635892865650846 \cdot 10^{-93}:\\ \;\;\;\;\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 -1.585466010660367 \cdot 10^{+150}:\\
\;\;\;\;\mathsf{fma}\left(-2, \frac{b_2}{a}, \frac{\frac{c}{b_2}}{2}\right)\\

\mathbf{elif}\;b_2 \le 1.3635892865650846 \cdot 10^{-93}:\\
\;\;\;\;\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 r844414 = b_2;
        double r844415 = -r844414;
        double r844416 = r844414 * r844414;
        double r844417 = a;
        double r844418 = c;
        double r844419 = r844417 * r844418;
        double r844420 = r844416 - r844419;
        double r844421 = sqrt(r844420);
        double r844422 = r844415 + r844421;
        double r844423 = r844422 / r844417;
        return r844423;
}

double f(double a, double b_2, double c) {
        double r844424 = b_2;
        double r844425 = -1.585466010660367e+150;
        bool r844426 = r844424 <= r844425;
        double r844427 = -2.0;
        double r844428 = a;
        double r844429 = r844424 / r844428;
        double r844430 = c;
        double r844431 = r844430 / r844424;
        double r844432 = 2.0;
        double r844433 = r844431 / r844432;
        double r844434 = fma(r844427, r844429, r844433);
        double r844435 = 1.3635892865650846e-93;
        bool r844436 = r844424 <= r844435;
        double r844437 = r844424 * r844424;
        double r844438 = r844430 * r844428;
        double r844439 = r844437 - r844438;
        double r844440 = sqrt(r844439);
        double r844441 = r844440 - r844424;
        double r844442 = r844441 / r844428;
        double r844443 = -0.5;
        double r844444 = r844443 * r844431;
        double r844445 = r844436 ? r844442 : r844444;
        double r844446 = r844426 ? r844434 : r844445;
        return r844446;
}

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 < -1.585466010660367e+150

    1. Initial program 62.8

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

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

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

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

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

    if -1.585466010660367e+150 < b_2 < 1.3635892865650846e-93

    1. Initial program 11.6

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

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

      \[\leadsto \color{blue}{\left(\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2\right) \cdot \frac{1}{a}}\]
    5. Using strategy rm
    6. Applied un-div-inv11.6

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

    if 1.3635892865650846e-93 < b_2

    1. Initial program 53.0

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

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

      \[\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 -1.585466010660367 \cdot 10^{+150}:\\ \;\;\;\;\mathsf{fma}\left(-2, \frac{b_2}{a}, \frac{\frac{c}{b_2}}{2}\right)\\ \mathbf{elif}\;b_2 \le 1.3635892865650846 \cdot 10^{-93}:\\ \;\;\;\;\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 2019165 +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))