Average Error: 33.8 → 9.1
Time: 6.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 -8.959285179359827 \cdot 10^{+136}:\\ \;\;\;\;\frac{2 \cdot \left(\frac{a \cdot c}{b} - b\right)}{2 \cdot a}\\ \mathbf{elif}\;b \leq 1.1385720630965241 \cdot 10^{-296}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2 \cdot a}\\ \mathbf{elif}\;b \leq 1.435883796381114 \cdot 10^{+111}:\\ \;\;\;\;\frac{1}{\frac{0.5}{\frac{c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{0.5}{\frac{c}{2 \cdot \left(\frac{a \cdot c}{b} - b\right)}}}\\ \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 -8.959285179359827 \cdot 10^{+136}:\\
\;\;\;\;\frac{2 \cdot \left(\frac{a \cdot c}{b} - b\right)}{2 \cdot a}\\

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

\mathbf{elif}\;b \leq 1.435883796381114 \cdot 10^{+111}:\\
\;\;\;\;\frac{1}{\frac{0.5}{\frac{c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{0.5}{\frac{c}{2 \cdot \left(\frac{a \cdot c}{b} - b\right)}}}\\

\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 -8.959285179359827e+136)
   (/ (* 2.0 (- (/ (* a c) b) b)) (* 2.0 a))
   (if (<= b 1.1385720630965241e-296)
     (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* 2.0 a))
     (if (<= b 1.435883796381114e+111)
       (/ 1.0 (/ 0.5 (/ c (- (- b) (sqrt (- (* b b) (* c (* a 4.0))))))))
       (/ 1.0 (/ 0.5 (/ c (* 2.0 (- (/ (* a c) b) b)))))))))
double code(double a, double b, double c) {
	return (-b + sqrt((b * b) - ((4.0 * a) * c))) / (2.0 * a);
}
double code(double a, double b, double c) {
	double tmp;
	if (b <= -8.959285179359827e+136) {
		tmp = (2.0 * (((a * c) / b) - b)) / (2.0 * a);
	} else if (b <= 1.1385720630965241e-296) {
		tmp = (sqrt((b * b) - (c * (a * 4.0))) - b) / (2.0 * a);
	} else if (b <= 1.435883796381114e+111) {
		tmp = 1.0 / (0.5 / (c / (-b - sqrt((b * b) - (c * (a * 4.0))))));
	} else {
		tmp = 1.0 / (0.5 / (c / (2.0 * (((a * c) / b) - b))));
	}
	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 < -8.9592851793598274e136

    1. Initial program 56.2

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Taylor expanded around -inf 11.5

      \[\leadsto \frac{\color{blue}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}}{2 \cdot a}\]
    3. Simplified11.5

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

    if -8.9592851793598274e136 < b < 1.1385720630965241e-296

    1. Initial program 9.5

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

    if 1.1385720630965241e-296 < b < 1.43588379638111404e111

    1. Initial program 33.2

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied flip-+_binary6433.3

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

      \[\leadsto \frac{\frac{\color{blue}{\left(4 \cdot a\right) \cdot c}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
    5. Using strategy rm
    6. Applied associate-/r*_binary6415.7

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

      \[\leadsto \frac{\color{blue}{\left(a \cdot 2\right) \cdot \frac{c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{a}\]
    8. Using strategy rm
    9. Applied clear-num_binary6413.6

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

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

    if 1.43588379638111404e111 < b

    1. Initial program 60.9

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

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

      \[\leadsto \frac{\frac{\color{blue}{\left(4 \cdot a\right) \cdot c}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
    5. Using strategy rm
    6. Applied associate-/r*_binary6434.4

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\frac{0.5}{\frac{c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}}\]
    11. Taylor expanded around inf 8.2

      \[\leadsto \frac{1}{\frac{0.5}{\frac{c}{\color{blue}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}}}}\]
    12. Simplified8.2

      \[\leadsto \frac{1}{\frac{0.5}{\frac{c}{\color{blue}{2 \cdot \left(\frac{a \cdot c}{b} - b\right)}}}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification9.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -8.959285179359827 \cdot 10^{+136}:\\ \;\;\;\;\frac{2 \cdot \left(\frac{a \cdot c}{b} - b\right)}{2 \cdot a}\\ \mathbf{elif}\;b \leq 1.1385720630965241 \cdot 10^{-296}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2 \cdot a}\\ \mathbf{elif}\;b \leq 1.435883796381114 \cdot 10^{+111}:\\ \;\;\;\;\frac{1}{\frac{0.5}{\frac{c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{0.5}{\frac{c}{2 \cdot \left(\frac{a \cdot c}{b} - b\right)}}}\\ \end{array}\]

Reproduce

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