Average Error: 33.7 → 8.2
Time: 4.6s
Precision: binary64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \leq -1.3667361231028956 \cdot 10^{+152}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -7.59554765878054 \cdot 10^{-309}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a \cdot 2} - \frac{b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 1.1883717871229594 \cdot 10^{+34}:\\ \;\;\;\;\frac{\frac{a}{\sqrt{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}} \cdot \frac{c \cdot -4}{\sqrt{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}}{a \cdot 2}\\ \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 \leq -1.3667361231028956 \cdot 10^{+152}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

\mathbf{elif}\;b \leq -7.59554765878054 \cdot 10^{-309}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a \cdot 2} - \frac{b}{a \cdot 2}\\

\mathbf{elif}\;b \leq 1.1883717871229594 \cdot 10^{+34}:\\
\;\;\;\;\frac{\frac{a}{\sqrt{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}} \cdot \frac{c \cdot -4}{\sqrt{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}}{a \cdot 2}\\

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

\end{array}
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c)
 :precision binary64
 (if (<= b -1.3667361231028956e+152)
   (- (/ c b) (/ b a))
   (if (<= b -7.59554765878054e-309)
     (- (/ (sqrt (- (* b b) (* c (* a 4.0)))) (* a 2.0)) (/ b (* a 2.0)))
     (if (<= b 1.1883717871229594e+34)
       (/
        (*
         (/ a (sqrt (+ b (sqrt (- (* b b) (* c (* a 4.0)))))))
         (/ (* c -4.0) (sqrt (+ b (sqrt (- (* b b) (* c (* a 4.0))))))))
        (* a 2.0))
       (- (/ c b))))))
double code(double a, double b, double c) {
	return (((double) (((double) -(b)) + ((double) sqrt(((double) (((double) (b * b)) - ((double) (((double) (4.0 * a)) * c)))))))) / ((double) (2.0 * a)));
}
double code(double a, double b, double c) {
	double tmp;
	if ((b <= -1.3667361231028956e+152)) {
		tmp = ((double) ((c / b) - (b / a)));
	} else {
		double tmp_1;
		if ((b <= -7.59554765878054e-309)) {
			tmp_1 = ((double) ((((double) sqrt(((double) (((double) (b * b)) - ((double) (c * ((double) (a * 4.0)))))))) / ((double) (a * 2.0))) - (b / ((double) (a * 2.0)))));
		} else {
			double tmp_2;
			if ((b <= 1.1883717871229594e+34)) {
				tmp_2 = (((double) ((a / ((double) sqrt(((double) (b + ((double) sqrt(((double) (((double) (b * b)) - ((double) (c * ((double) (a * 4.0))))))))))))) * (((double) (c * -4.0)) / ((double) sqrt(((double) (b + ((double) sqrt(((double) (((double) (b * b)) - ((double) (c * ((double) (a * 4.0))))))))))))))) / ((double) (a * 2.0)));
			} else {
				tmp_2 = ((double) -((c / b)));
			}
			tmp_1 = tmp_2;
		}
		tmp = tmp_1;
	}
	return tmp;
}

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 < -1.36673612310289565e152

    1. Initial program 63.4

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

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

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

    if -1.36673612310289565e152 < b < -7.5955476587805401e-309

    1. Initial program 8.8

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

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

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

    if -7.5955476587805401e-309 < b < 1.1883717871229594e34

    1. Initial program 27.8

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

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

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

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

      \[\leadsto \frac{\frac{a \cdot \left(c \cdot -4\right)}{\color{blue}{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{a \cdot 2}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt_binary6417.6

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

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

    if 1.1883717871229594e34 < b

    1. Initial program 56.6

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.3667361231028956 \cdot 10^{+152}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -7.59554765878054 \cdot 10^{-309}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a \cdot 2} - \frac{b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 1.1883717871229594 \cdot 10^{+34}:\\ \;\;\;\;\frac{\frac{a}{\sqrt{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}} \cdot \frac{c \cdot -4}{\sqrt{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2020219 
(FPCore (a b c)
  :name "Quadratic roots, full range"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))