Average Error: 34.9 → 14.1
Time: 19.6s
Precision: 64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -2.486593375467686151654921844207164570885 \cdot 10^{143}:\\ \;\;\;\;\frac{-2 \cdot b}{2 \cdot a}\\ \mathbf{elif}\;b \le 5.198567300310805542976550787106877171711 \cdot 10^{-33}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2 \cdot \frac{a \cdot c}{b}}{2 \cdot a}\\ \end{array}\]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \le -2.486593375467686151654921844207164570885 \cdot 10^{143}:\\
\;\;\;\;\frac{-2 \cdot b}{2 \cdot a}\\

\mathbf{elif}\;b \le 5.198567300310805542976550787106877171711 \cdot 10^{-33}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;\frac{-2 \cdot \frac{a \cdot c}{b}}{2 \cdot a}\\

\end{array}
double f(double a, double b, double c) {
        double r43086 = b;
        double r43087 = -r43086;
        double r43088 = r43086 * r43086;
        double r43089 = 4.0;
        double r43090 = a;
        double r43091 = r43089 * r43090;
        double r43092 = c;
        double r43093 = r43091 * r43092;
        double r43094 = r43088 - r43093;
        double r43095 = sqrt(r43094);
        double r43096 = r43087 + r43095;
        double r43097 = 2.0;
        double r43098 = r43097 * r43090;
        double r43099 = r43096 / r43098;
        return r43099;
}

double f(double a, double b, double c) {
        double r43100 = b;
        double r43101 = -2.486593375467686e+143;
        bool r43102 = r43100 <= r43101;
        double r43103 = -2.0;
        double r43104 = r43103 * r43100;
        double r43105 = 2.0;
        double r43106 = a;
        double r43107 = r43105 * r43106;
        double r43108 = r43104 / r43107;
        double r43109 = 5.1985673003108055e-33;
        bool r43110 = r43100 <= r43109;
        double r43111 = r43100 * r43100;
        double r43112 = 4.0;
        double r43113 = r43112 * r43106;
        double r43114 = c;
        double r43115 = r43113 * r43114;
        double r43116 = r43111 - r43115;
        double r43117 = sqrt(r43116);
        double r43118 = r43117 - r43100;
        double r43119 = r43118 / r43107;
        double r43120 = -2.0;
        double r43121 = r43106 * r43114;
        double r43122 = r43121 / r43100;
        double r43123 = r43120 * r43122;
        double r43124 = r43123 / r43107;
        double r43125 = r43110 ? r43119 : r43124;
        double r43126 = r43102 ? r43108 : r43125;
        return r43126;
}

Error

Bits error versus a

Bits error versus b

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.486593375467686e+143

    1. Initial program 59.5

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified59.5

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied add-cube-cbrt59.5

      \[\leadsto \frac{\sqrt{\color{blue}{\left(\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}}} - b}{2 \cdot a}\]
    5. Applied sqrt-prod59.5

      \[\leadsto \frac{\color{blue}{\sqrt{\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}}} - b}{2 \cdot a}\]
    6. Applied fma-neg59.6

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\sqrt{\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}}, \sqrt{\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}}, -b\right)}}{2 \cdot a}\]
    7. Taylor expanded around -inf 2.7

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

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

    if -2.486593375467686e+143 < b < 5.1985673003108055e-33

    1. Initial program 14.5

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified14.5

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}}\]

    if 5.1985673003108055e-33 < b

    1. Initial program 55.5

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified55.5

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}}\]
    3. Taylor expanded around inf 17.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.486593375467686151654921844207164570885 \cdot 10^{143}:\\ \;\;\;\;\frac{-2 \cdot b}{2 \cdot a}\\ \mathbf{elif}\;b \le 5.198567300310805542976550787106877171711 \cdot 10^{-33}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2 \cdot \frac{a \cdot c}{b}}{2 \cdot a}\\ \end{array}\]

Reproduce

herbie shell --seed 2019235 +o rules:numerics
(FPCore (a b c)
  :name "Quadratic roots, full range"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))