Average Error: 33.4 → 6.6
Time: 5.5s
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 -3.060976138917674342180206539993786896862 \cdot 10^{65}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -5.269237409668851033931621618066544269281 \cdot 10^{-239}:\\ \;\;\;\;\frac{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2} \cdot \frac{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{a}\\ \mathbf{elif}\;b \le 4.059864939717054460242095466484063430125 \cdot 10^{128}:\\ \;\;\;\;\frac{1}{\frac{2}{\frac{c \cdot 4}{1}} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \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 -3.060976138917674342180206539993786896862 \cdot 10^{65}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r59245 = b;
        double r59246 = -r59245;
        double r59247 = r59245 * r59245;
        double r59248 = 4.0;
        double r59249 = a;
        double r59250 = r59248 * r59249;
        double r59251 = c;
        double r59252 = r59250 * r59251;
        double r59253 = r59247 - r59252;
        double r59254 = sqrt(r59253);
        double r59255 = r59246 + r59254;
        double r59256 = 2.0;
        double r59257 = r59256 * r59249;
        double r59258 = r59255 / r59257;
        return r59258;
}

double f(double a, double b, double c) {
        double r59259 = b;
        double r59260 = -3.0609761389176743e+65;
        bool r59261 = r59259 <= r59260;
        double r59262 = 1.0;
        double r59263 = c;
        double r59264 = r59263 / r59259;
        double r59265 = a;
        double r59266 = r59259 / r59265;
        double r59267 = r59264 - r59266;
        double r59268 = r59262 * r59267;
        double r59269 = -5.269237409668851e-239;
        bool r59270 = r59259 <= r59269;
        double r59271 = -r59259;
        double r59272 = r59259 * r59259;
        double r59273 = 4.0;
        double r59274 = r59273 * r59265;
        double r59275 = r59274 * r59263;
        double r59276 = r59272 - r59275;
        double r59277 = sqrt(r59276);
        double r59278 = r59271 + r59277;
        double r59279 = sqrt(r59278);
        double r59280 = 2.0;
        double r59281 = r59279 / r59280;
        double r59282 = r59279 / r59265;
        double r59283 = r59281 * r59282;
        double r59284 = 4.0598649397170545e+128;
        bool r59285 = r59259 <= r59284;
        double r59286 = 1.0;
        double r59287 = r59263 * r59273;
        double r59288 = r59287 / r59286;
        double r59289 = r59280 / r59288;
        double r59290 = r59271 - r59277;
        double r59291 = r59289 * r59290;
        double r59292 = r59286 / r59291;
        double r59293 = -1.0;
        double r59294 = r59293 * r59264;
        double r59295 = r59285 ? r59292 : r59294;
        double r59296 = r59270 ? r59283 : r59295;
        double r59297 = r59261 ? r59268 : r59296;
        return r59297;
}

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 4 regimes
  2. if b < -3.0609761389176743e+65

    1. Initial program 40.1

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

      \[\leadsto \color{blue}{1 \cdot \frac{c}{b} - 1 \cdot \frac{b}{a}}\]
    3. Simplified4.4

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

    if -3.0609761389176743e+65 < b < -5.269237409668851e-239

    1. Initial program 7.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 add-sqr-sqrt8.0

      \[\leadsto \frac{\color{blue}{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{2 \cdot a}\]
    4. Applied times-frac8.0

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

    if -5.269237409668851e-239 < b < 4.0598649397170545e+128

    1. Initial program 31.1

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

      \[\leadsto \frac{\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}}}}{2 \cdot a}\]
    4. Simplified15.4

      \[\leadsto \frac{\frac{\color{blue}{0 + 4 \cdot \left(a \cdot c\right)}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity15.4

      \[\leadsto \frac{\frac{0 + 4 \cdot \left(a \cdot c\right)}{\color{blue}{1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}}{2 \cdot a}\]
    7. Applied *-un-lft-identity15.4

      \[\leadsto \frac{\frac{\color{blue}{1 \cdot \left(0 + 4 \cdot \left(a \cdot c\right)\right)}}{1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}{2 \cdot a}\]
    8. Applied times-frac15.4

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

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

      \[\leadsto \frac{\frac{1}{1}}{\color{blue}{\frac{2 \cdot a}{4 \cdot \left(a \cdot c\right)} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\]
    11. Using strategy rm
    12. Applied associate-/l*14.7

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

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

    if 4.0598649397170545e+128 < b

    1. Initial program 61.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.060976138917674342180206539993786896862 \cdot 10^{65}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -5.269237409668851033931621618066544269281 \cdot 10^{-239}:\\ \;\;\;\;\frac{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2} \cdot \frac{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{a}\\ \mathbf{elif}\;b \le 4.059864939717054460242095466484063430125 \cdot 10^{128}:\\ \;\;\;\;\frac{1}{\frac{2}{\frac{c \cdot 4}{1}} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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