Average Error: 34.6 → 10.2
Time: 40.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.270528699455007486596308100489334356636 \cdot 10^{152}:\\ \;\;\;\;\mathsf{fma}\left(-2, \frac{b_2}{a}, \frac{\frac{c}{b_2}}{2}\right)\\ \mathbf{elif}\;b_2 \le 1.744031351412432972171902712116585209201 \cdot 10^{-142}:\\ \;\;\;\;\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.270528699455007486596308100489334356636 \cdot 10^{152}:\\
\;\;\;\;\mathsf{fma}\left(-2, \frac{b_2}{a}, \frac{\frac{c}{b_2}}{2}\right)\\

\mathbf{elif}\;b_2 \le 1.744031351412432972171902712116585209201 \cdot 10^{-142}:\\
\;\;\;\;\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 r844335 = b_2;
        double r844336 = -r844335;
        double r844337 = r844335 * r844335;
        double r844338 = a;
        double r844339 = c;
        double r844340 = r844338 * r844339;
        double r844341 = r844337 - r844340;
        double r844342 = sqrt(r844341);
        double r844343 = r844336 + r844342;
        double r844344 = r844343 / r844338;
        return r844344;
}

double f(double a, double b_2, double c) {
        double r844345 = b_2;
        double r844346 = -1.2705286994550075e+152;
        bool r844347 = r844345 <= r844346;
        double r844348 = -2.0;
        double r844349 = a;
        double r844350 = r844345 / r844349;
        double r844351 = c;
        double r844352 = r844351 / r844345;
        double r844353 = 2.0;
        double r844354 = r844352 / r844353;
        double r844355 = fma(r844348, r844350, r844354);
        double r844356 = 1.744031351412433e-142;
        bool r844357 = r844345 <= r844356;
        double r844358 = r844345 * r844345;
        double r844359 = r844351 * r844349;
        double r844360 = r844358 - r844359;
        double r844361 = sqrt(r844360);
        double r844362 = r844361 - r844345;
        double r844363 = r844362 / r844349;
        double r844364 = -0.5;
        double r844365 = r844364 * r844352;
        double r844366 = r844357 ? r844363 : r844365;
        double r844367 = r844347 ? r844355 : r844366;
        return r844367;
}

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.2705286994550075e+152

    1. Initial program 62.9

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

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}}\]
    3. Using strategy rm
    4. Applied div-inv62.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 1.6

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

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

    if -1.2705286994550075e+152 < b_2 < 1.744031351412433e-142

    1. Initial program 10.4

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

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

      \[\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-inv10.4

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

    if 1.744031351412433e-142 < b_2

    1. Initial program 50.7

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

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

      \[\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 -1.270528699455007486596308100489334356636 \cdot 10^{152}:\\ \;\;\;\;\mathsf{fma}\left(-2, \frac{b_2}{a}, \frac{\frac{c}{b_2}}{2}\right)\\ \mathbf{elif}\;b_2 \le 1.744031351412432972171902712116585209201 \cdot 10^{-142}:\\ \;\;\;\;\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 2019168 +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))