Average Error: 33.8 → 6.5
Time: 30.9s
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.1061641587957725 \cdot 10^{+142}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{c}{b_2} - \frac{b_2}{a} \cdot 2\\ \mathbf{elif}\;b_2 \le 5.6646816643665726 \cdot 10^{-285}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - c \cdot a} - b_2}{a}\\ \mathbf{elif}\;b_2 \le 1.4653326993720654 \cdot 10^{+110}:\\ \;\;\;\;-\frac{c}{\sqrt{b_2 \cdot b_2 - c \cdot a} + b_2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b_2} \cdot \frac{-1}{2}\\ \end{array}\]
double f(double a, double b_2, double c) {
        double r1024396 = b_2;
        double r1024397 = -r1024396;
        double r1024398 = r1024396 * r1024396;
        double r1024399 = a;
        double r1024400 = c;
        double r1024401 = r1024399 * r1024400;
        double r1024402 = r1024398 - r1024401;
        double r1024403 = sqrt(r1024402);
        double r1024404 = r1024397 + r1024403;
        double r1024405 = r1024404 / r1024399;
        return r1024405;
}

double f(double a, double b_2, double c) {
        double r1024406 = b_2;
        double r1024407 = -4.1061641587957725e+142;
        bool r1024408 = r1024406 <= r1024407;
        double r1024409 = 0.5;
        double r1024410 = c;
        double r1024411 = r1024410 / r1024406;
        double r1024412 = r1024409 * r1024411;
        double r1024413 = a;
        double r1024414 = r1024406 / r1024413;
        double r1024415 = 2.0;
        double r1024416 = r1024414 * r1024415;
        double r1024417 = r1024412 - r1024416;
        double r1024418 = 5.6646816643665726e-285;
        bool r1024419 = r1024406 <= r1024418;
        double r1024420 = r1024406 * r1024406;
        double r1024421 = r1024410 * r1024413;
        double r1024422 = r1024420 - r1024421;
        double r1024423 = sqrt(r1024422);
        double r1024424 = r1024423 - r1024406;
        double r1024425 = r1024424 / r1024413;
        double r1024426 = 1.4653326993720654e+110;
        bool r1024427 = r1024406 <= r1024426;
        double r1024428 = r1024423 + r1024406;
        double r1024429 = r1024410 / r1024428;
        double r1024430 = -r1024429;
        double r1024431 = -0.5;
        double r1024432 = r1024411 * r1024431;
        double r1024433 = r1024427 ? r1024430 : r1024432;
        double r1024434 = r1024419 ? r1024425 : r1024433;
        double r1024435 = r1024408 ? r1024417 : r1024434;
        return r1024435;
}

\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}
\begin{array}{l}
\mathbf{if}\;b_2 \le -4.1061641587957725 \cdot 10^{+142}:\\
\;\;\;\;\frac{1}{2} \cdot \frac{c}{b_2} - \frac{b_2}{a} \cdot 2\\

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

\mathbf{elif}\;b_2 \le 1.4653326993720654 \cdot 10^{+110}:\\
\;\;\;\;-\frac{c}{\sqrt{b_2 \cdot b_2 - c \cdot a} + b_2}\\

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

\end{array}

Error

Bits error versus a

Bits error versus b_2

Bits error versus c

Derivation

  1. Split input into 4 regimes
  2. if b_2 < -4.1061641587957725e+142

    1. Initial program 56.5

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

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

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

    if -4.1061641587957725e+142 < b_2 < 5.6646816643665726e-285

    1. Initial program 9.0

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

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

    if 5.6646816643665726e-285 < b_2 < 1.4653326993720654e+110

    1. Initial program 33.5

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

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

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} \cdot \sqrt{b_2 \cdot b_2 - a \cdot c} - b_2 \cdot b_2}{\sqrt{b_2 \cdot b_2 - a \cdot c} + b_2}} \cdot \frac{1}{a}\]
    7. Applied associate-*l/33.6

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

      \[\leadsto \frac{\color{blue}{\frac{0 - a \cdot c}{a}}}{\sqrt{b_2 \cdot b_2 - a \cdot c} + b_2}\]
    9. Taylor expanded around inf 8.6

      \[\leadsto \frac{\color{blue}{-1 \cdot c}}{\sqrt{b_2 \cdot b_2 - a \cdot c} + b_2}\]
    10. Simplified8.6

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

    if 1.4653326993720654e+110 < b_2

    1. Initial program 59.7

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \le -4.1061641587957725 \cdot 10^{+142}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{c}{b_2} - \frac{b_2}{a} \cdot 2\\ \mathbf{elif}\;b_2 \le 5.6646816643665726 \cdot 10^{-285}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - c \cdot a} - b_2}{a}\\ \mathbf{elif}\;b_2 \le 1.4653326993720654 \cdot 10^{+110}:\\ \;\;\;\;-\frac{c}{\sqrt{b_2 \cdot b_2 - c \cdot a} + b_2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b_2} \cdot \frac{-1}{2}\\ \end{array}\]

Reproduce

herbie shell --seed 2019102 
(FPCore (a b_2 c)
  :name "quad2p (problem 3.2.1, positive)"
  (/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))