Average Error: 33.6 → 6.7
Time: 6.9s
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 -3.215444035007023 \cdot 10^{+149}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \leq -2.0438562332290375 \cdot 10^{-228}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 7.80695497130973 \cdot 10^{+98}:\\ \;\;\;\;\frac{c \cdot -2}{b + \sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \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 -3.215444035007023 \cdot 10^{+149}:\\
\;\;\;\;-\frac{b}{a}\\

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

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

\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\

\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 -3.215444035007023e+149)
   (- (/ b a))
   (if (<= b -2.0438562332290375e-228)
     (/ (- (sqrt (- (* b b) (* (* a 4.0) c))) b) (* a 2.0))
     (if (<= b 7.80695497130973e+98)
       (/ (* c -2.0) (+ b (sqrt (- (* b b) (* (* a 4.0) c)))))
       (- (/ c 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 <= -3.215444035007023e+149) {
		tmp = -(b / a);
	} else if (b <= -2.0438562332290375e-228) {
		tmp = (sqrt((b * b) - ((a * 4.0) * c)) - b) / (a * 2.0);
	} else if (b <= 7.80695497130973e+98) {
		tmp = (c * -2.0) / (b + sqrt((b * b) - ((a * 4.0) * c)));
	} else {
		tmp = -(c / 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 < -3.21544403500702319e149

    1. Initial program 61.9

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot 2}}\]
    3. Taylor expanded around -inf 3.1

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]

    if -3.21544403500702319e149 < b < -2.0438562332290375e-228

    1. Initial program 7.2

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

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

    if -2.0438562332290375e-228 < b < 7.80695497130972954e98

    1. Initial program 30.4

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot 2}}\]
    3. Using strategy rm
    4. Applied div-inv_binary6430.5

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

      \[\leadsto \left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right) \cdot \color{blue}{\frac{0.5}{a}}\]
    6. Using strategy rm
    7. Applied flip--_binary6430.5

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b \cdot b}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}} \cdot \frac{0.5}{a}\]
    8. Applied associate-*l/_binary6430.6

      \[\leadsto \color{blue}{\frac{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b \cdot b\right) \cdot \frac{0.5}{a}}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}}\]
    9. Simplified30.6

      \[\leadsto \frac{\color{blue}{\left(b \cdot b - \left(4 \cdot \left(a \cdot c\right) + b \cdot b\right)\right) \cdot \frac{0.5}{a}}}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}\]
    10. Taylor expanded around 0 10.1

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

    if 7.80695497130972954e98 < b

    1. Initial program 59.2

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot 2}}\]
    3. Taylor expanded around inf 2.4

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification6.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -3.215444035007023 \cdot 10^{+149}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \leq -2.0438562332290375 \cdot 10^{-228}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 7.80695497130973 \cdot 10^{+98}:\\ \;\;\;\;\frac{c \cdot -2}{b + \sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Alternatives

Reproduce

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