Average Error: 34.3 → 8.3
Time: 4.9s
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 -1.44435856646914502 \cdot 10^{87}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -8.94672295773202446 \cdot 10^{-284}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;b \le 1.74631986093255956 \cdot 10^{58}:\\ \;\;\;\;\frac{1 \cdot \frac{4 \cdot a}{\frac{-\left(b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}{c}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \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 \le -1.44435856646914502 \cdot 10^{87}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\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 <= -1.444358566469145e+87)) {
		VAR = (1.0 * ((c / b) - (b / a)));
	} else {
		double VAR_1;
		if ((b <= -8.946722957732024e-284)) {
			VAR_1 = ((-b + sqrt(((b * b) - ((4.0 * a) * c)))) * (1.0 / (2.0 * a)));
		} else {
			double VAR_2;
			if ((b <= 1.7463198609325596e+58)) {
				VAR_2 = ((1.0 * ((4.0 * a) / (-(b + sqrt(((b * b) - ((4.0 * a) * c)))) / c))) / (2.0 * a));
			} 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.3
Target21.2
Herbie8.3
\[\begin{array}{l} \mathbf{if}\;b \lt 0.0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if b < -1.444358566469145e+87

    1. Initial program 43.8

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

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

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

    if -1.444358566469145e+87 < b < -8.946722957732024e-284

    1. Initial program 9.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 div-inv9.8

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

    if -8.946722957732024e-284 < b < 1.7463198609325596e+58

    1. Initial program 29.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 add-sqr-sqrt29.5

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

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

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

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

      \[\leadsto \frac{\frac{0 + \left(4 \cdot a\right) \cdot c}{\color{blue}{-\left(b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}}{2 \cdot a}\]
    9. Using strategy rm
    10. Applied *-un-lft-identity17.3

      \[\leadsto \frac{\frac{0 + \left(4 \cdot a\right) \cdot c}{\color{blue}{1 \cdot \left(-\left(b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)\right)}}}{2 \cdot a}\]
    11. Applied *-un-lft-identity17.3

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

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

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

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

    if 1.7463198609325596e+58 < b

    1. Initial program 57.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.44435856646914502 \cdot 10^{87}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -8.94672295773202446 \cdot 10^{-284}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;b \le 1.74631986093255956 \cdot 10^{58}:\\ \;\;\;\;\frac{1 \cdot \frac{4 \cdot a}{\frac{-\left(b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}{c}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2020075 
(FPCore (a b c)
  :name "The quadratic formula (r1)"
  :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)))