Average Error: 34.0 → 7.1
Time: 49.1s
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 -5.089942740476039 \cdot 10^{+37}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.1606217053284985 \cdot 10^{-301}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.9653089193303188 \cdot 10^{+135}:\\ \;\;\;\;\frac{c \cdot -2}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}\\ \mathbf{else}:\\ \;\;\;\;-\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 -5.089942740476039 \cdot 10^{+37}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r4727146 = b;
        double r4727147 = -r4727146;
        double r4727148 = r4727146 * r4727146;
        double r4727149 = 4.0;
        double r4727150 = a;
        double r4727151 = r4727149 * r4727150;
        double r4727152 = c;
        double r4727153 = r4727151 * r4727152;
        double r4727154 = r4727148 - r4727153;
        double r4727155 = sqrt(r4727154);
        double r4727156 = r4727147 + r4727155;
        double r4727157 = 2.0;
        double r4727158 = r4727157 * r4727150;
        double r4727159 = r4727156 / r4727158;
        return r4727159;
}

double f(double a, double b, double c) {
        double r4727160 = b;
        double r4727161 = -5.089942740476039e+37;
        bool r4727162 = r4727160 <= r4727161;
        double r4727163 = c;
        double r4727164 = r4727163 / r4727160;
        double r4727165 = a;
        double r4727166 = r4727160 / r4727165;
        double r4727167 = r4727164 - r4727166;
        double r4727168 = 1.1606217053284985e-301;
        bool r4727169 = r4727160 <= r4727168;
        double r4727170 = r4727160 * r4727160;
        double r4727171 = r4727163 * r4727165;
        double r4727172 = 4.0;
        double r4727173 = r4727171 * r4727172;
        double r4727174 = r4727170 - r4727173;
        double r4727175 = sqrt(r4727174);
        double r4727176 = r4727175 - r4727160;
        double r4727177 = 2.0;
        double r4727178 = r4727165 * r4727177;
        double r4727179 = r4727176 / r4727178;
        double r4727180 = 1.9653089193303188e+135;
        bool r4727181 = r4727160 <= r4727180;
        double r4727182 = -2.0;
        double r4727183 = r4727163 * r4727182;
        double r4727184 = r4727175 + r4727160;
        double r4727185 = r4727183 / r4727184;
        double r4727186 = -r4727164;
        double r4727187 = r4727181 ? r4727185 : r4727186;
        double r4727188 = r4727169 ? r4727179 : r4727187;
        double r4727189 = r4727162 ? r4727167 : r4727188;
        return r4727189;
}

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 < -5.089942740476039e+37

    1. Initial program 34.9

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied div-inv35.0

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

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

    if -5.089942740476039e+37 < b < 1.1606217053284985e-301

    1. Initial program 10.3

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

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

      \[\leadsto \color{blue}{\left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b\right) \cdot \frac{1}{2 \cdot a}}\]
    5. Using strategy rm
    6. Applied un-div-inv10.3

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

    if 1.1606217053284985e-301 < b < 1.9653089193303188e+135

    1. Initial program 34.6

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied div-inv34.6

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

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

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

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

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

    if 1.9653089193303188e+135 < b

    1. Initial program 61.2

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -5.089942740476039 \cdot 10^{+37}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.1606217053284985 \cdot 10^{-301}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.9653089193303188 \cdot 10^{+135}:\\ \;\;\;\;\frac{c \cdot -2}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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