Average Error: 44.0 → 10.6
Time: 7.2s
Precision: 64
\[1.11022 \cdot 10^{-16} \lt a \lt 9.0072 \cdot 10^{15} \land 1.11022 \cdot 10^{-16} \lt b \lt 9.0072 \cdot 10^{15} \land 1.11022 \cdot 10^{-16} \lt c \lt 9.0072 \cdot 10^{15}\]
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \le -180.886209626466126:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(b, b, -\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2 \cdot \frac{c}{1}}{\frac{2 \cdot a}{-a} \cdot \left(-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}\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \le -180.886209626466126:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(b, b, -\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\

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

\end{array}
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 temp;
	if ((((-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)) <= -180.88620962646613)) {
		temp = ((fma(b, b, -((b * b) - ((4.0 * a) * c))) / (-b - sqrt(((b * b) - ((4.0 * a) * c))))) / (2.0 * a));
	} else {
		temp = ((-2.0 * (c / 1.0)) / (((2.0 * a) / -a) * -b));
	}
	return temp;
}

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 2 regimes
  2. if (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) < -180.88620962646613

    1. Initial program 18.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-+18.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. Simplified17.6

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

    if -180.88620962646613 < (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a))

    1. Initial program 46.7

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

      \[\leadsto \frac{\color{blue}{-2 \cdot \frac{a \cdot c}{b}}}{2 \cdot a}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity10.1

      \[\leadsto \frac{-2 \cdot \frac{a \cdot c}{\color{blue}{1 \cdot b}}}{2 \cdot a}\]
    5. Applied *-commutative10.1

      \[\leadsto \frac{-2 \cdot \frac{\color{blue}{c \cdot a}}{1 \cdot b}}{2 \cdot a}\]
    6. Applied times-frac10.1

      \[\leadsto \frac{-2 \cdot \color{blue}{\left(\frac{c}{1} \cdot \frac{a}{b}\right)}}{2 \cdot a}\]
    7. Applied associate-*r*10.1

      \[\leadsto \frac{\color{blue}{\left(-2 \cdot \frac{c}{1}\right) \cdot \frac{a}{b}}}{2 \cdot a}\]
    8. Applied associate-/l*9.9

      \[\leadsto \color{blue}{\frac{-2 \cdot \frac{c}{1}}{\frac{2 \cdot a}{\frac{a}{b}}}}\]
    9. Using strategy rm
    10. Applied frac-2neg9.9

      \[\leadsto \frac{-2 \cdot \frac{c}{1}}{\frac{2 \cdot a}{\color{blue}{\frac{-a}{-b}}}}\]
    11. Applied associate-/r/9.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \le -180.886209626466126:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(b, b, -\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2 \cdot \frac{c}{1}}{\frac{2 \cdot a}{-a} \cdot \left(-b\right)}\\ \end{array}\]

Reproduce

herbie shell --seed 2020066 +o rules:numerics
(FPCore (a b c)
  :name "Quadratic roots, medium range"
  :precision binary64
  :pre (and (< 1.11022e-16 a 9.0072e+15) (< 1.11022e-16 b 9.0072e+15) (< 1.11022e-16 c 9.0072e+15))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))