Average Error: 34.5 → 10.7
Time: 5.6s
Precision: binary64
\[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
\[\begin{array}{l} \mathbf{if}\;b_2 \leq -2.179096873024578 \cdot 10^{-55}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b_2}\\ \mathbf{elif}\;b_2 \leq 3.7738771228718737:\\ \;\;\;\;\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - c \cdot a}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b_2} \cdot 0.5 - 2 \cdot \frac{b_2}{a}\\ \end{array}\]
\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}
\begin{array}{l}
\mathbf{if}\;b_2 \leq -2.179096873024578 \cdot 10^{-55}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b_2}\\

\mathbf{elif}\;b_2 \leq 3.7738771228718737:\\
\;\;\;\;\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - c \cdot a}}{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{c}{b_2} \cdot 0.5 - 2 \cdot \frac{b_2}{a}\\

\end{array}
(FPCore (a b_2 c)
 :precision binary64
 (/ (- (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))
(FPCore (a b_2 c)
 :precision binary64
 (if (<= b_2 -2.179096873024578e-55)
   (* -0.5 (/ c b_2))
   (if (<= b_2 3.7738771228718737)
     (/ (- (- b_2) (sqrt (- (* b_2 b_2) (* c a)))) a)
     (- (* (/ c b_2) 0.5) (* 2.0 (/ b_2 a))))))
double code(double a, double b_2, double c) {
	return (-b_2 - sqrt((b_2 * b_2) - (a * c))) / a;
}
double code(double a, double b_2, double c) {
	double tmp;
	if (b_2 <= -2.179096873024578e-55) {
		tmp = -0.5 * (c / b_2);
	} else if (b_2 <= 3.7738771228718737) {
		tmp = (-b_2 - sqrt((b_2 * b_2) - (c * a))) / a;
	} else {
		tmp = ((c / b_2) * 0.5) - (2.0 * (b_2 / a));
	}
	return tmp;
}

Error

Bits error versus a

Bits error versus b_2

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_2 < -2.17909687302457804e-55

    1. Initial program 54.1

      \[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
    2. Taylor expanded around -inf 8.1

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b_2}}\]

    if -2.17909687302457804e-55 < b_2 < 3.77387712287187371

    1. Initial program 15.9

      \[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]

    if 3.77387712287187371 < b_2

    1. Initial program 32.6

      \[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
    2. Taylor expanded around inf 7.1

      \[\leadsto \color{blue}{0.5 \cdot \frac{c}{b_2} - 2 \cdot \frac{b_2}{a}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification10.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \leq -2.179096873024578 \cdot 10^{-55}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b_2}\\ \mathbf{elif}\;b_2 \leq 3.7738771228718737:\\ \;\;\;\;\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - c \cdot a}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b_2} \cdot 0.5 - 2 \cdot \frac{b_2}{a}\\ \end{array}\]

Reproduce

herbie shell --seed 2020292 
(FPCore (a b_2 c)
  :name "quad2m (problem 3.2.1, negative)"
  :precision binary64
  (/ (- (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))