Average Error: 33.9 → 10.5
Time: 5.0s
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 -1.0226793514904988 \cdot 10^{+71}:\\ \;\;\;\;0.5 \cdot \frac{c}{b_2} + \frac{b_2}{a} \cdot -2\\ \mathbf{elif}\;b_2 \leq 5.740357605763107 \cdot 10^{-120}:\\ \;\;\;\;\left(\sqrt{b_2 \cdot b_2 - c \cdot a} - b_2\right) \cdot \frac{1}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b_2} \cdot -0.5\\ \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 -1.0226793514904988 \cdot 10^{+71}:\\
\;\;\;\;0.5 \cdot \frac{c}{b_2} + \frac{b_2}{a} \cdot -2\\

\mathbf{elif}\;b_2 \leq 5.740357605763107 \cdot 10^{-120}:\\
\;\;\;\;\left(\sqrt{b_2 \cdot b_2 - c \cdot a} - b_2\right) \cdot \frac{1}{a}\\

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

\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 -1.0226793514904988e+71)
   (+ (* 0.5 (/ c b_2)) (* (/ b_2 a) -2.0))
   (if (<= b_2 5.740357605763107e-120)
     (* (- (sqrt (- (* b_2 b_2) (* c a))) b_2) (/ 1.0 a))
     (* (/ c b_2) -0.5))))
double code(double a, double b_2, double c) {
	return (((double) (((double) -(b_2)) + ((double) sqrt(((double) (((double) (b_2 * b_2)) - ((double) (a * c)))))))) / a);
}
double code(double a, double b_2, double c) {
	double VAR;
	if ((b_2 <= -1.0226793514904988e+71)) {
		VAR = ((double) (((double) (0.5 * (c / b_2))) + ((double) ((b_2 / a) * -2.0))));
	} else {
		double VAR_1;
		if ((b_2 <= 5.740357605763107e-120)) {
			VAR_1 = ((double) (((double) (((double) sqrt(((double) (((double) (b_2 * b_2)) - ((double) (c * a)))))) - b_2)) * (1.0 / a)));
		} else {
			VAR_1 = ((double) ((c / b_2) * -0.5));
		}
		VAR = VAR_1;
	}
	return VAR;
}

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 < -1.0226793514904988e71

    1. Initial program 41.4

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

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}}\]
    3. Using strategy rm
    4. Applied div-inv41.5

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{c}{b_2} - 2 \cdot \frac{b_2}{a}}\]
    6. Simplified5.0

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

    if -1.0226793514904988e71 < b_2 < 5.740357605763107e-120

    1. Initial program 12.4

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

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}}\]
    3. Using strategy rm
    4. Applied div-inv12.5

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

    if 5.740357605763107e-120 < b_2

    1. Initial program 51.6

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
    2. Simplified51.6

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}}\]
    3. Taylor expanded around inf 11.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \leq -1.0226793514904988 \cdot 10^{+71}:\\ \;\;\;\;0.5 \cdot \frac{c}{b_2} + \frac{b_2}{a} \cdot -2\\ \mathbf{elif}\;b_2 \leq 5.740357605763107 \cdot 10^{-120}:\\ \;\;\;\;\left(\sqrt{b_2 \cdot b_2 - c \cdot a} - b_2\right) \cdot \frac{1}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b_2} \cdot -0.5\\ \end{array}\]

Reproduce

herbie shell --seed 2020198 
(FPCore (a b_2 c)
  :name "quad2p (problem 3.2.1, positive)"
  :precision binary64
  (/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))