Average Error: 34.2 → 8.6
Time: 4.5s
Precision: 64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -2.7863758169125638 \cdot 10^{138}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -8.7810627886272542 \cdot 10^{-225}:\\ \;\;\;\;\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\\ \mathbf{elif}\;b \le 1.74082702562304839 \cdot 10^{101}:\\ \;\;\;\;\frac{\frac{\frac{\sqrt[3]{1}}{2} \cdot \left(\left({b}^{2} - {b}^{2}\right) + 4 \cdot \left(a \cdot c\right)\right)}{a}}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]
\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \le -2.7863758169125638 \cdot 10^{138}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\mathbf{elif}\;b \le -8.7810627886272542 \cdot 10^{-225}:\\
\;\;\;\;\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\\

\mathbf{elif}\;b \le 1.74082702562304839 \cdot 10^{101}:\\
\;\;\;\;\frac{\frac{\frac{\sqrt[3]{1}}{2} \cdot \left(\left({b}^{2} - {b}^{2}\right) + 4 \cdot \left(a \cdot c\right)\right)}{a}}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\\

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

\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 * ((c / b) - (b / a)));
	} else {
		double VAR_1;
		if ((b <= -8.781062788627254e-225)) {
			VAR_1 = ((cbrt(1.0) * cbrt(1.0)) / ((2.0 * a) / (-b + sqrt(((b * b) - (4.0 * (a * c)))))));
		} else {
			double VAR_2;
			if ((b <= 1.7408270256230484e+101)) {
				VAR_2 = ((((cbrt(1.0) / 2.0) * ((pow(b, 2.0) - pow(b, 2.0)) + (4.0 * (a * c)))) / a) / (-b - sqrt(((b * b) - (4.0 * (a * c))))));
			} else {
				VAR_2 = (-1.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

Target

Original34.2
Target20.9
Herbie8.6
\[\begin{array}{l} \mathbf{if}\;b \lt 0.0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \end{array}\]

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 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around -inf 2.6

      \[\leadsto \color{blue}{1 \cdot \frac{c}{b} - 1 \cdot \frac{b}{a}}\]
    3. Simplified2.6

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

    if -2.7863758169125638e+138 < b < -8.781062788627254e-225

    1. Initial program 6.6

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

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}\]
    4. Using strategy rm
    5. Applied add-cube-cbrt6.8

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

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

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

    if -8.781062788627254e-225 < b < 1.7408270256230484e+101

    1. Initial program 30.7

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

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}\]
    4. Using strategy rm
    5. Applied add-cube-cbrt30.8

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

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

      \[\leadsto \frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\color{blue}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}\]
    8. Using strategy rm
    9. Applied flip-+30.8

      \[\leadsto \frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\frac{2 \cdot a}{\color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} \cdot \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}}\]
    10. Applied associate-/r/30.9

      \[\leadsto \frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\color{blue}{\frac{2 \cdot a}{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} \cdot \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}}\]
    11. Applied associate-/r*30.9

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

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

    if 1.7408270256230484e+101 < b

    1. Initial program 60.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.7863758169125638 \cdot 10^{138}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -8.7810627886272542 \cdot 10^{-225}:\\ \;\;\;\;\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\\ \mathbf{elif}\;b \le 1.74082702562304839 \cdot 10^{101}:\\ \;\;\;\;\frac{\frac{\frac{\sqrt[3]{1}}{2} \cdot \left(\left({b}^{2} - {b}^{2}\right) + 4 \cdot \left(a \cdot c\right)\right)}{a}}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2020078 
(FPCore (a b c)
  :name "quadp (p42, positive)"
  :precision binary64

  :herbie-target
  (if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))))

  (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))