Average Error: 34.4 → 10.0
Time: 5.4s
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 -9.91243958875386880555748684589545292526 \cdot 10^{101}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.209120745343099452134664059704875392955 \cdot 10^{-70}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - {\left(4 \cdot \left(a \cdot c\right)\right)}^{1}}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2} \cdot \left(-2 \cdot \frac{c}{b}\right)\\ \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 -9.91243958875386880555748684589545292526 \cdot 10^{101}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r54063 = b;
        double r54064 = -r54063;
        double r54065 = r54063 * r54063;
        double r54066 = 4.0;
        double r54067 = a;
        double r54068 = r54066 * r54067;
        double r54069 = c;
        double r54070 = r54068 * r54069;
        double r54071 = r54065 - r54070;
        double r54072 = sqrt(r54071);
        double r54073 = r54064 + r54072;
        double r54074 = 2.0;
        double r54075 = r54074 * r54067;
        double r54076 = r54073 / r54075;
        return r54076;
}

double f(double a, double b, double c) {
        double r54077 = b;
        double r54078 = -9.912439588753869e+101;
        bool r54079 = r54077 <= r54078;
        double r54080 = 1.0;
        double r54081 = c;
        double r54082 = r54081 / r54077;
        double r54083 = a;
        double r54084 = r54077 / r54083;
        double r54085 = r54082 - r54084;
        double r54086 = r54080 * r54085;
        double r54087 = 1.2091207453430995e-70;
        bool r54088 = r54077 <= r54087;
        double r54089 = 1.0;
        double r54090 = 2.0;
        double r54091 = r54089 / r54090;
        double r54092 = -r54077;
        double r54093 = r54077 * r54077;
        double r54094 = 4.0;
        double r54095 = r54083 * r54081;
        double r54096 = r54094 * r54095;
        double r54097 = pow(r54096, r54089);
        double r54098 = r54093 - r54097;
        double r54099 = sqrt(r54098);
        double r54100 = r54092 + r54099;
        double r54101 = r54100 / r54083;
        double r54102 = r54091 * r54101;
        double r54103 = -2.0;
        double r54104 = r54103 * r54082;
        double r54105 = r54091 * r54104;
        double r54106 = r54088 ? r54102 : r54105;
        double r54107 = r54079 ? r54086 : r54106;
        return r54107;
}

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 < -9.912439588753869e+101

    1. Initial program 46.9

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

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

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

    if -9.912439588753869e+101 < b < 1.2091207453430995e-70

    1. Initial program 13.3

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

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

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

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(\color{blue}{{4}^{1}} \cdot {a}^{1}\right) \cdot {c}^{1}}}{2 \cdot a}\]
    6. Applied pow-prod-down13.3

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \color{blue}{{\left(4 \cdot a\right)}^{1}} \cdot {c}^{1}}}{2 \cdot a}\]
    7. Applied pow-prod-down13.3

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

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - {\color{blue}{\left(4 \cdot \left(a \cdot c\right)\right)}}^{1}}}{2 \cdot a}\]
    9. Using strategy rm
    10. Applied *-un-lft-identity13.3

      \[\leadsto \frac{\color{blue}{1 \cdot \left(\left(-b\right) + \sqrt{b \cdot b - {\left(4 \cdot \left(a \cdot c\right)\right)}^{1}}\right)}}{2 \cdot a}\]
    11. Applied times-frac13.3

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

    if 1.2091207453430995e-70 < b

    1. Initial program 53.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 pow153.7

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

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot \color{blue}{{a}^{1}}\right) \cdot {c}^{1}}}{2 \cdot a}\]
    5. Applied pow153.7

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(\color{blue}{{4}^{1}} \cdot {a}^{1}\right) \cdot {c}^{1}}}{2 \cdot a}\]
    6. Applied pow-prod-down53.7

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \color{blue}{{\left(4 \cdot a\right)}^{1}} \cdot {c}^{1}}}{2 \cdot a}\]
    7. Applied pow-prod-down53.7

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

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - {\color{blue}{\left(4 \cdot \left(a \cdot c\right)\right)}}^{1}}}{2 \cdot a}\]
    9. Using strategy rm
    10. Applied *-un-lft-identity53.7

      \[\leadsto \frac{\color{blue}{1 \cdot \left(\left(-b\right) + \sqrt{b \cdot b - {\left(4 \cdot \left(a \cdot c\right)\right)}^{1}}\right)}}{2 \cdot a}\]
    11. Applied times-frac53.7

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

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

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

Reproduce

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