Average Error: 33.8 → 6.7
Time: 1.5m
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 -4.3671561050226844 \cdot 10^{+101}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 5.6646816643665726 \cdot 10^{-285}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}\right) \cdot \frac{1}{a \cdot 2}\\ \mathbf{elif}\;b \le 2.8546456093447043 \cdot 10^{+107}:\\ \;\;\;\;\frac{c \cdot 2}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{2 \cdot \left(\frac{c}{b} \cdot a - b\right)}\\ \end{array}\]
double f(double a, double b, double c) {
        double r6049172 = b;
        double r6049173 = -r6049172;
        double r6049174 = r6049172 * r6049172;
        double r6049175 = 4.0;
        double r6049176 = a;
        double r6049177 = r6049175 * r6049176;
        double r6049178 = c;
        double r6049179 = r6049177 * r6049178;
        double r6049180 = r6049174 - r6049179;
        double r6049181 = sqrt(r6049180);
        double r6049182 = r6049173 + r6049181;
        double r6049183 = 2.0;
        double r6049184 = r6049183 * r6049176;
        double r6049185 = r6049182 / r6049184;
        return r6049185;
}

double f(double a, double b, double c) {
        double r6049186 = b;
        double r6049187 = -4.3671561050226844e+101;
        bool r6049188 = r6049186 <= r6049187;
        double r6049189 = c;
        double r6049190 = r6049189 / r6049186;
        double r6049191 = a;
        double r6049192 = r6049186 / r6049191;
        double r6049193 = r6049190 - r6049192;
        double r6049194 = 5.6646816643665726e-285;
        bool r6049195 = r6049186 <= r6049194;
        double r6049196 = -r6049186;
        double r6049197 = r6049186 * r6049186;
        double r6049198 = 4.0;
        double r6049199 = r6049198 * r6049191;
        double r6049200 = r6049189 * r6049199;
        double r6049201 = r6049197 - r6049200;
        double r6049202 = sqrt(r6049201);
        double r6049203 = r6049196 + r6049202;
        double r6049204 = 1.0;
        double r6049205 = 2.0;
        double r6049206 = r6049191 * r6049205;
        double r6049207 = r6049204 / r6049206;
        double r6049208 = r6049203 * r6049207;
        double r6049209 = 2.8546456093447043e+107;
        bool r6049210 = r6049186 <= r6049209;
        double r6049211 = r6049189 * r6049205;
        double r6049212 = r6049196 - r6049202;
        double r6049213 = r6049211 / r6049212;
        double r6049214 = r6049190 * r6049191;
        double r6049215 = r6049214 - r6049186;
        double r6049216 = r6049205 * r6049215;
        double r6049217 = r6049211 / r6049216;
        double r6049218 = r6049210 ? r6049213 : r6049217;
        double r6049219 = r6049195 ? r6049208 : r6049218;
        double r6049220 = r6049188 ? r6049193 : r6049219;
        return r6049220;
}

\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 -4.3671561050226844 \cdot 10^{+101}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

\mathbf{elif}\;b \le 5.6646816643665726 \cdot 10^{-285}:\\
\;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}\right) \cdot \frac{1}{a \cdot 2}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{2 \cdot \left(\frac{c}{b} \cdot a - b\right)}\\

\end{array}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 4 regimes
  2. if b < -4.3671561050226844e+101

    1. Initial program 44.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied div-inv44.8

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

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

    if -4.3671561050226844e+101 < b < 5.6646816643665726e-285

    1. Initial program 9.6

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied div-inv9.7

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

    if 5.6646816643665726e-285 < b < 2.8546456093447043e+107

    1. Initial program 33.4

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied div-inv33.5

      \[\leadsto \color{blue}{\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}}\]
    4. Using strategy rm
    5. Applied flip-+33.6

      \[\leadsto \color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}} \cdot \frac{1}{2 \cdot a}\]
    6. Applied associate-*l/33.6

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

      \[\leadsto \frac{\color{blue}{-\frac{\frac{c \cdot a}{\frac{-1}{2}}}{a}}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\]
    8. Taylor expanded around 0 8.7

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

    if 2.8546456093447043e+107 < b

    1. Initial program 59.5

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied div-inv59.5

      \[\leadsto \color{blue}{\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}}\]
    4. Using strategy rm
    5. Applied flip-+59.6

      \[\leadsto \color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}} \cdot \frac{1}{2 \cdot a}\]
    6. Applied associate-*l/59.6

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

      \[\leadsto \frac{\color{blue}{-\frac{\frac{c \cdot a}{\frac{-1}{2}}}{a}}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\]
    8. Taylor expanded around 0 31.4

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

      \[\leadsto \frac{--2 \cdot c}{\color{blue}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}}\]
    10. Simplified2.1

      \[\leadsto \frac{--2 \cdot c}{\color{blue}{\left(\frac{c}{b} \cdot a - b\right) \cdot 2}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification6.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.3671561050226844 \cdot 10^{+101}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 5.6646816643665726 \cdot 10^{-285}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}\right) \cdot \frac{1}{a \cdot 2}\\ \mathbf{elif}\;b \le 2.8546456093447043 \cdot 10^{+107}:\\ \;\;\;\;\frac{c \cdot 2}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{2 \cdot \left(\frac{c}{b} \cdot a - b\right)}\\ \end{array}\]

Reproduce

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