Average Error: 32.8 → 9.8
Time: 19.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.3599228730895225 \cdot 10^{+90}:\\ \;\;\;\;\mathsf{fma}\left(-2, \frac{b_2}{a}, \frac{1}{2} \cdot \frac{c}{b_2}\right)\\ \mathbf{elif}\;b_2 \le 3.1295384133612364 \cdot 10^{-73}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - c \cdot a} - b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b_2} \cdot \frac{-1}{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.3599228730895225 \cdot 10^{+90}:\\
\;\;\;\;\mathsf{fma}\left(-2, \frac{b_2}{a}, \frac{1}{2} \cdot \frac{c}{b_2}\right)\\

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

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

\end{array}
double f(double a, double b_2, double c) {
        double r448120 = b_2;
        double r448121 = -r448120;
        double r448122 = r448120 * r448120;
        double r448123 = a;
        double r448124 = c;
        double r448125 = r448123 * r448124;
        double r448126 = r448122 - r448125;
        double r448127 = sqrt(r448126);
        double r448128 = r448121 + r448127;
        double r448129 = r448128 / r448123;
        return r448129;
}

double f(double a, double b_2, double c) {
        double r448130 = b_2;
        double r448131 = -1.3599228730895225e+90;
        bool r448132 = r448130 <= r448131;
        double r448133 = -2.0;
        double r448134 = a;
        double r448135 = r448130 / r448134;
        double r448136 = 0.5;
        double r448137 = c;
        double r448138 = r448137 / r448130;
        double r448139 = r448136 * r448138;
        double r448140 = fma(r448133, r448135, r448139);
        double r448141 = 3.1295384133612364e-73;
        bool r448142 = r448130 <= r448141;
        double r448143 = r448130 * r448130;
        double r448144 = r448137 * r448134;
        double r448145 = r448143 - r448144;
        double r448146 = sqrt(r448145);
        double r448147 = r448146 - r448130;
        double r448148 = r448147 / r448134;
        double r448149 = -0.5;
        double r448150 = r448138 * r448149;
        double r448151 = r448142 ? r448148 : r448150;
        double r448152 = r448132 ? r448140 : r448151;
        return r448152;
}

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.3599228730895225e+90

    1. Initial program 41.6

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

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

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

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

    if -1.3599228730895225e+90 < b_2 < 3.1295384133612364e-73

    1. Initial program 12.8

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

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

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

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

    if 3.1295384133612364e-73 < b_2

    1. Initial program 52.3

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \le -1.3599228730895225 \cdot 10^{+90}:\\ \;\;\;\;\mathsf{fma}\left(-2, \frac{b_2}{a}, \frac{1}{2} \cdot \frac{c}{b_2}\right)\\ \mathbf{elif}\;b_2 \le 3.1295384133612364 \cdot 10^{-73}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - c \cdot a} - b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b_2} \cdot \frac{-1}{2}\\ \end{array}\]

Reproduce

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