Average Error: 33.9 → 6.5
Time: 5.1s
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.817222120419214 \cdot 10^{+114}:\\ \;\;\;\;\frac{0.5 \cdot \frac{c}{\frac{b_2}{a}} - b_2 \cdot 2}{a}\\ \mathbf{elif}\;b_2 \leq -2.1924358107857753 \cdot 10^{-301}:\\ \;\;\;\;\left(\sqrt{b_2 \cdot b_2 - c \cdot a} - b_2\right) \cdot \frac{1}{a}\\ \mathbf{elif}\;b_2 \leq 4.1131887417592497 \cdot 10^{+117}:\\ \;\;\;\;-\frac{c}{b_2 + \sqrt{b_2 \cdot b_2 - c \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;-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 -2.817222120419214 \cdot 10^{+114}:\\
\;\;\;\;\frac{0.5 \cdot \frac{c}{\frac{b_2}{a}} - b_2 \cdot 2}{a}\\

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

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

\mathbf{else}:\\
\;\;\;\;-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 -2.817222120419214e+114)
   (/ (- (* 0.5 (/ c (/ b_2 a))) (* b_2 2.0)) a)
   (if (<= b_2 -2.1924358107857753e-301)
     (* (- (sqrt (- (* b_2 b_2) (* c a))) b_2) (/ 1.0 a))
     (if (<= b_2 4.1131887417592497e+117)
       (- (/ c (+ b_2 (sqrt (- (* b_2 b_2) (* c 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 <= -2.817222120419214e+114) {
		tmp = ((0.5 * (c / (b_2 / a))) - (b_2 * 2.0)) / a;
	} else if (b_2 <= -2.1924358107857753e-301) {
		tmp = (sqrt((b_2 * b_2) - (c * a)) - b_2) * (1.0 / a);
	} else if (b_2 <= 4.1131887417592497e+117) {
		tmp = -(c / (b_2 + sqrt((b_2 * b_2) - (c * a))));
	} else {
		tmp = -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 < -2.8172221204192137e114

    1. Initial program 50.6

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

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

      \[\leadsto \frac{\color{blue}{0.5 \cdot \frac{a \cdot c}{b_2} - 2 \cdot b_2}}{a}\]
    4. Simplified3.9

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

    if -2.8172221204192137e114 < b_2 < -2.1924358107857753e-301

    1. Initial program 8.4

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

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

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

    if -2.1924358107857753e-301 < b_2 < 4.1131887417592497e117

    1. Initial program 32.6

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

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}}\]
    3. Using strategy rm
    4. Applied flip--_binary6432.7

      \[\leadsto \frac{\color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} \cdot \sqrt{b_2 \cdot b_2 - a \cdot c} - b_2 \cdot b_2}{\sqrt{b_2 \cdot b_2 - a \cdot c} + b_2}}}{a}\]
    5. Simplified15.2

      \[\leadsto \frac{\frac{\color{blue}{-a \cdot c}}{\sqrt{b_2 \cdot b_2 - a \cdot c} + b_2}}{a}\]
    6. Simplified15.2

      \[\leadsto \frac{\frac{-a \cdot c}{\color{blue}{b_2 + \sqrt{b_2 \cdot b_2 - a \cdot c}}}}{a}\]
    7. Using strategy rm
    8. Applied distribute-frac-neg_binary6415.2

      \[\leadsto \frac{\color{blue}{-\frac{a \cdot c}{b_2 + \sqrt{b_2 \cdot b_2 - a \cdot c}}}}{a}\]
    9. Applied distribute-frac-neg_binary6415.2

      \[\leadsto \color{blue}{-\frac{\frac{a \cdot c}{b_2 + \sqrt{b_2 \cdot b_2 - a \cdot c}}}{a}}\]
    10. Simplified8.2

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

    if 4.1131887417592497e117 < b_2

    1. Initial program 61.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \leq -2.817222120419214 \cdot 10^{+114}:\\ \;\;\;\;\frac{0.5 \cdot \frac{c}{\frac{b_2}{a}} - b_2 \cdot 2}{a}\\ \mathbf{elif}\;b_2 \leq -2.1924358107857753 \cdot 10^{-301}:\\ \;\;\;\;\left(\sqrt{b_2 \cdot b_2 - c \cdot a} - b_2\right) \cdot \frac{1}{a}\\ \mathbf{elif}\;b_2 \leq 4.1131887417592497 \cdot 10^{+117}:\\ \;\;\;\;-\frac{c}{b_2 + \sqrt{b_2 \cdot b_2 - c \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b_2}\\ \end{array}\]

Reproduce

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