Average Error: 33.6 → 8.9
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 -1.6236541306877014 \cdot 10^{+56}:\\ \;\;\;\;\frac{2 \cdot \left(\frac{a \cdot c}{b} - b\right)}{2 \cdot a}\\ \mathbf{elif}\;b \leq 7.131198222427231 \cdot 10^{-227}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2 \cdot a}\\ \mathbf{elif}\;b \leq 5.525835260688754 \cdot 10^{+121}:\\ \;\;\;\;\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 -1.6236541306877014 \cdot 10^{+56}:\\
\;\;\;\;\frac{2 \cdot \left(\frac{a \cdot c}{b} - b\right)}{2 \cdot a}\\

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

\mathbf{elif}\;b \leq 5.525835260688754 \cdot 10^{+121}:\\
\;\;\;\;\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 -1.6236541306877014e+56)
   (/ (* 2.0 (- (/ (* a c) b) b)) (* 2.0 a))
   (if (<= b 7.131198222427231e-227)
     (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* 2.0 a))
     (if (<= b 5.525835260688754e+121)
       (/ 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 <= -1.6236541306877014e+56) {
		tmp = (2.0 * (((a * c) / b) - b)) / (2.0 * a);
	} else if (b <= 7.131198222427231e-227) {
		tmp = (sqrt((b * b) - (c * (a * 4.0))) - b) / (2.0 * a);
	} else if (b <= 5.525835260688754e+121) {
		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 < -1.6236541306877014e56

    1. Initial program 38.1

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

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

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

    if -1.6236541306877014e56 < b < 7.131198222427231e-227

    1. Initial program 10.2

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

    if 7.131198222427231e-227 < b < 5.52583526068875372e121

    1. Initial program 36.8

      \[\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-+_binary64_39736.8

      \[\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. Simplified17.1

      \[\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*_binary64_36717.1

      \[\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. Simplified14.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_binary64_42214.7

      \[\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. Simplified7.6

      \[\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 5.52583526068875372e121 < b

    1. Initial program 61.3

      \[\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-+_binary64_39761.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. 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*_binary64_36734.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_binary64_42234.2

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

      \[\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 6.2

      \[\leadsto \frac{1}{\frac{0.5}{\frac{c}{\color{blue}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}}}}\]
    12. Simplified6.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 simplification8.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.6236541306877014 \cdot 10^{+56}:\\ \;\;\;\;\frac{2 \cdot \left(\frac{a \cdot c}{b} - b\right)}{2 \cdot a}\\ \mathbf{elif}\;b \leq 7.131198222427231 \cdot 10^{-227}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2 \cdot a}\\ \mathbf{elif}\;b \leq 5.525835260688754 \cdot 10^{+121}:\\ \;\;\;\;\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 2020281 
(FPCore (a b c)
  :name "Quadratic roots, full range"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))