Average Error: 34.3 → 8.9
Time: 4.8s
Precision: 64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -2.7863758169125638 \cdot 10^{138}:\\ \;\;\;\;\frac{1}{2} \cdot \left(2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 2.20848854156636544 \cdot 10^{-130}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\\ \mathbf{elif}\;b \le 1.9844148556213612 \cdot 10^{72}:\\ \;\;\;\;\frac{\frac{0 + 4 \cdot \left(a \cdot c\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2} \cdot \left(-2 \cdot \frac{c}{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 \le -2.7863758169125638 \cdot 10^{138}:\\
\;\;\;\;\frac{1}{2} \cdot \left(2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}\right)\\

\mathbf{elif}\;b \le 2.20848854156636544 \cdot 10^{-130}:\\
\;\;\;\;\frac{1}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\\

\mathbf{elif}\;b \le 1.9844148556213612 \cdot 10^{72}:\\
\;\;\;\;\frac{\frac{0 + 4 \cdot \left(a \cdot c\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{2} \cdot \left(-2 \cdot \frac{c}{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 VAR;
	if ((b <= -2.7863758169125638e+138)) {
		VAR = ((1.0 / 2.0) * ((2.0 * (c / b)) - (2.0 * (b / a))));
	} else {
		double VAR_1;
		if ((b <= 2.2084885415663654e-130)) {
			VAR_1 = (1.0 / ((2.0 * a) / (-b + sqrt(((b * b) - ((4.0 * a) * c))))));
		} else {
			double VAR_2;
			if ((b <= 1.9844148556213612e+72)) {
				VAR_2 = (((0.0 + (4.0 * (a * c))) / (-b - sqrt(((b * b) - ((4.0 * a) * c))))) / (2.0 * a));
			} else {
				VAR_2 = ((1.0 / 2.0) * (-2.0 * (c / b)));
			}
			VAR_1 = VAR_2;
		}
		VAR = VAR_1;
	}
	return VAR;
}

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 < -2.7863758169125638e+138

    1. Initial program 58.6

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

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity58.6

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

      \[\leadsto \frac{1}{\color{blue}{\frac{2}{1} \cdot \frac{a}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}\]
    7. Applied add-cube-cbrt58.6

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

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

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

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

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

    if -2.7863758169125638e+138 < b < 2.2084885415663654e-130

    1. Initial program 10.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 clear-num11.0

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

    if 2.2084885415663654e-130 < b < 1.9844148556213612e+72

    1. Initial program 39.5

      \[\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-+39.5

      \[\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. Simplified16.9

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

    if 1.9844148556213612e+72 < b

    1. Initial program 58.4

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

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity58.4

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

      \[\leadsto \frac{1}{\color{blue}{\frac{2}{1} \cdot \frac{a}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}\]
    7. Applied add-cube-cbrt58.4

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.7863758169125638 \cdot 10^{138}:\\ \;\;\;\;\frac{1}{2} \cdot \left(2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 2.20848854156636544 \cdot 10^{-130}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\\ \mathbf{elif}\;b \le 1.9844148556213612 \cdot 10^{72}:\\ \;\;\;\;\frac{\frac{0 + 4 \cdot \left(a \cdot c\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2} \cdot \left(-2 \cdot \frac{c}{b}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020078 +o rules:numerics
(FPCore (a b c)
  :name "Quadratic roots, full range"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))