Average Error: 34.3 → 8.7
Time: 8.4s
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 -9.262564350171407 \cdot 10^{-13}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b_2}\\ \mathbf{elif}\;b_2 \leq -7.4406991673960255 \cdot 10^{-261}:\\ \;\;\;\;\frac{\frac{a}{\frac{\sqrt{b_2 \cdot b_2 - c \cdot a} - b_2}{c}}}{a}\\ \mathbf{elif}\;b_2 \leq 2.354428103312287 \cdot 10^{+18}:\\ \;\;\;\;\frac{-b_2}{a} - \frac{\sqrt{b_2 \cdot b_2 - c \cdot a}}{a}\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\ \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 -9.262564350171407 \cdot 10^{-13}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b_2}\\

\mathbf{elif}\;b_2 \leq -7.4406991673960255 \cdot 10^{-261}:\\
\;\;\;\;\frac{\frac{a}{\frac{\sqrt{b_2 \cdot b_2 - c \cdot a} - b_2}{c}}}{a}\\

\mathbf{elif}\;b_2 \leq 2.354428103312287 \cdot 10^{+18}:\\
\;\;\;\;\frac{-b_2}{a} - \frac{\sqrt{b_2 \cdot b_2 - c \cdot a}}{a}\\

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

\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 -9.262564350171407e-13)
   (/ (* -0.5 c) b_2)
   (if (<= b_2 -7.4406991673960255e-261)
     (/ (/ a (/ (- (sqrt (- (* b_2 b_2) (* c a))) b_2) c)) a)
     (if (<= b_2 2.354428103312287e+18)
       (- (/ (- b_2) a) (/ (sqrt (- (* b_2 b_2) (* c a))) a))
       (+ (* -2.0 (/ b_2 a)) (* 0.5 (/ c b_2)))))))
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 <= -9.262564350171407e-13) {
		tmp = (-0.5 * c) / b_2;
	} else if (b_2 <= -7.4406991673960255e-261) {
		tmp = (a / ((sqrt((b_2 * b_2) - (c * a)) - b_2) / c)) / a;
	} else if (b_2 <= 2.354428103312287e+18) {
		tmp = (-b_2 / a) - (sqrt((b_2 * b_2) - (c * a)) / a);
	} else {
		tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
	}
	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 4 regimes
  2. if b_2 < -9.2625643501714075e-13

    1. Initial program 55.2

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b_2}}\]
    3. Using strategy rm
    4. Applied associate-*r/_binary646.5

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

    if -9.2625643501714075e-13 < b_2 < -7.44069916739602553e-261

    1. Initial program 25.8

      \[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
    2. Using strategy rm
    3. Applied flip--_binary6425.8

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

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

      \[\leadsto \frac{\frac{a \cdot c}{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}}{a}\]
    6. Using strategy rm
    7. Applied associate-/l*_binary6412.5

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

    if -7.44069916739602553e-261 < b_2 < 2354428103312287230

    1. Initial program 10.9

      \[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
    2. Using strategy rm
    3. Applied div-sub_binary6410.9

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

    if 2354428103312287230 < b_2

    1. Initial program 34.3

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{c}{b_2} - 2 \cdot \frac{b_2}{a}}\]
    3. Simplified6.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \leq -9.262564350171407 \cdot 10^{-13}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b_2}\\ \mathbf{elif}\;b_2 \leq -7.4406991673960255 \cdot 10^{-261}:\\ \;\;\;\;\frac{\frac{a}{\frac{\sqrt{b_2 \cdot b_2 - c \cdot a} - b_2}{c}}}{a}\\ \mathbf{elif}\;b_2 \leq 2.354428103312287 \cdot 10^{+18}:\\ \;\;\;\;\frac{-b_2}{a} - \frac{\sqrt{b_2 \cdot b_2 - c \cdot a}}{a}\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\ \end{array}\]

Reproduce

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