Average Error: 32.9 → 10.4
Time: 14.7s
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.9358476230749954 \cdot 10^{+137}:\\ \;\;\;\;\frac{-2 \cdot b_2}{a}\\ \mathbf{elif}\;b_2 \le 9.080243787284695 \cdot 10^{-125}:\\ \;\;\;\;\left(\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2\right) \cdot \frac{1}{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.9358476230749954 \cdot 10^{+137}:\\
\;\;\;\;\frac{-2 \cdot b_2}{a}\\

\mathbf{elif}\;b_2 \le 9.080243787284695 \cdot 10^{-125}:\\
\;\;\;\;\left(\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2\right) \cdot \frac{1}{a}\\

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

\end{array}
double f(double a, double b_2, double c) {
        double r309568 = b_2;
        double r309569 = -r309568;
        double r309570 = r309568 * r309568;
        double r309571 = a;
        double r309572 = c;
        double r309573 = r309571 * r309572;
        double r309574 = r309570 - r309573;
        double r309575 = sqrt(r309574);
        double r309576 = r309569 + r309575;
        double r309577 = r309576 / r309571;
        return r309577;
}

double f(double a, double b_2, double c) {
        double r309578 = b_2;
        double r309579 = -1.9358476230749954e+137;
        bool r309580 = r309578 <= r309579;
        double r309581 = -2.0;
        double r309582 = r309581 * r309578;
        double r309583 = a;
        double r309584 = r309582 / r309583;
        double r309585 = 9.080243787284695e-125;
        bool r309586 = r309578 <= r309585;
        double r309587 = r309578 * r309578;
        double r309588 = c;
        double r309589 = r309583 * r309588;
        double r309590 = r309587 - r309589;
        double r309591 = sqrt(r309590);
        double r309592 = r309591 - r309578;
        double r309593 = 1.0;
        double r309594 = r309593 / r309583;
        double r309595 = r309592 * r309594;
        double r309596 = -0.5;
        double r309597 = r309588 / r309578;
        double r309598 = r309596 * r309597;
        double r309599 = r309586 ? r309595 : r309598;
        double r309600 = r309580 ? r309584 : r309599;
        return r309600;
}

Error

Bits error versus a

Bits error versus b_2

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if b_2 < -1.9358476230749954e+137

    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. Using strategy rm
    4. Applied add-sqr-sqrt54.6

      \[\leadsto \frac{\sqrt{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} \cdot \sqrt{b_2 \cdot b_2 - a \cdot c}}} - b_2}{a}\]
    5. Applied sqrt-prod54.7

      \[\leadsto \frac{\color{blue}{\sqrt{\sqrt{b_2 \cdot b_2 - a \cdot c}} \cdot \sqrt{\sqrt{b_2 \cdot b_2 - a \cdot c}}} - b_2}{a}\]
    6. Applied fma-neg54.6

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\sqrt{\sqrt{b_2 \cdot b_2 - a \cdot c}}, \sqrt{\sqrt{b_2 \cdot b_2 - a \cdot c}}, -b_2\right)}}{a}\]
    7. Taylor expanded around -inf 2.2

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

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

    if -1.9358476230749954e+137 < b_2 < 9.080243787284695e-125

    1. Initial program 11.0

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

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

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

    if 9.080243787284695e-125 < b_2

    1. Initial program 49.8

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \le -1.9358476230749954 \cdot 10^{+137}:\\ \;\;\;\;\frac{-2 \cdot b_2}{a}\\ \mathbf{elif}\;b_2 \le 9.080243787284695 \cdot 10^{-125}:\\ \;\;\;\;\left(\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2\right) \cdot \frac{1}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{c}{b_2}\\ \end{array}\]

Reproduce

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