Average Error: 33.7 → 7.3
Time: 3.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 -110883243782.23416:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -4.61052798615193 \cdot 10^{-299}:\\ \;\;\;\;\left(\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b\right) \cdot \frac{0.5}{a}\\ \mathbf{elif}\;b \leq 1.0321611733451932 \cdot 10^{+121}:\\ \;\;\;\;\left(c \cdot -4\right) \cdot \frac{0.5}{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}\\ \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 -110883243782.23416:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

\mathbf{elif}\;b \leq -4.61052798615193 \cdot 10^{-299}:\\
\;\;\;\;\left(\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b\right) \cdot \frac{0.5}{a}\\

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

\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 -110883243782.23416)
   (- (/ c b) (/ b a))
   (if (<= b -4.61052798615193e-299)
     (* (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (/ 0.5 a))
     (if (<= b 1.0321611733451932e+121)
       (* (* c -4.0) (/ 0.5 (+ b (sqrt (+ (* b b) (* a (* c -4.0)))))))
       (- (/ 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 <= -110883243782.23416) {
		tmp = (c / b) - (b / a);
	} else if (b <= -4.61052798615193e-299) {
		tmp = (sqrt((b * b) - (c * (a * 4.0))) - b) * (0.5 / a);
	} else if (b <= 1.0321611733451932e+121) {
		tmp = (c * -4.0) * (0.5 / (b + sqrt((b * b) + (a * (c * -4.0)))));
	} 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 < -110883243782.23416

    1. Initial program 32.1

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

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

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

    if -110883243782.23416 < b < -4.61052798615192997e-299

    1. Initial program 10.6

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

      \[\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_binary6410.7

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

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

    if -4.61052798615192997e-299 < b < 1.03216117334519319e121

    1. Initial program 32.5

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

      \[\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 flip--_binary6432.5

      \[\leadsto \frac{\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}}}{a \cdot 2}\]
    5. Simplified16.2

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

      \[\leadsto \frac{\frac{a \cdot \left(c \cdot -4\right)}{\color{blue}{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{a \cdot 2}\]
    7. Using strategy rm
    8. Applied div-inv_binary6416.2

      \[\leadsto \frac{\color{blue}{\left(a \cdot \left(c \cdot -4\right)\right) \cdot \frac{1}{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{a \cdot 2}\]
    9. Applied times-frac_binary6415.2

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

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

      \[\leadsto \left(c \cdot -4\right) \cdot \color{blue}{\frac{0.5}{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\]
    12. Using strategy rm
    13. Applied sub-neg_binary648.8

      \[\leadsto \left(c \cdot -4\right) \cdot \frac{0.5}{b + \sqrt{\color{blue}{b \cdot b + \left(-\left(4 \cdot a\right) \cdot c\right)}}}\]
    14. Simplified8.8

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

    if 1.03216117334519319e121 < b

    1. Initial program 60.7

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    4. Simplified1.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -110883243782.23416:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -4.61052798615193 \cdot 10^{-299}:\\ \;\;\;\;\left(\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b\right) \cdot \frac{0.5}{a}\\ \mathbf{elif}\;b \leq 1.0321611733451932 \cdot 10^{+121}:\\ \;\;\;\;\left(c \cdot -4\right) \cdot \frac{0.5}{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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