Average Error: 33.7 → 9.4
Time: 5.0s
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 -9.47614345515238625 \cdot 10^{113}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le -4.3690676097323859 \cdot 10^{-164}:\\ \;\;\;\;\frac{\frac{4 \cdot \left(a \cdot c\right)}{2 \cdot a}}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}\\ \mathbf{elif}\;b \le 1.2919983862558445 \cdot 10^{30}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \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 -9.47614345515238625 \cdot 10^{113}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\

\mathbf{elif}\;b \le -4.3690676097323859 \cdot 10^{-164}:\\
\;\;\;\;\frac{\frac{4 \cdot \left(a \cdot c\right)}{2 \cdot a}}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}\\

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

\mathbf{else}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\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 <= -9.476143455152386e+113)) {
		VAR = (-1.0 * (c / b));
	} else {
		double VAR_1;
		if ((b <= -4.369067609732386e-164)) {
			VAR_1 = (((4.0 * (a * c)) / (2.0 * a)) / (sqrt(((b * b) - (4.0 * (a * c)))) - b));
		} else {
			double VAR_2;
			if ((b <= 1.2919983862558445e+30)) {
				VAR_2 = (1.0 / ((2.0 * a) / (-b - sqrt(((b * b) - (4.0 * (a * c)))))));
			} else {
				VAR_2 = (1.0 * ((c / b) - (b / a)));
			}
			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

Original33.7
Target20.5
Herbie9.4
\[\begin{array}{l} \mathbf{if}\;b \lt 0.0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\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 < -9.476143455152386e+113

    1. Initial program 59.9

      \[\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}}\]

    if -9.476143455152386e+113 < b < -4.369067609732386e-164

    1. Initial program 37.8

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

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

      \[\leadsto \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)}}} \cdot \frac{1}{2 \cdot a}\]
    6. Simplified15.4

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

      \[\leadsto \frac{0 + 1 \cdot \left(4 \cdot \left(a \cdot c\right)\right)}{\color{blue}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}} \cdot \frac{1}{2 \cdot a}\]
    8. Using strategy rm
    9. Applied associate-*l/14.0

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

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

    if -4.369067609732386e-164 < b < 1.2919983862558445e+30

    1. Initial program 12.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-num12.7

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

    if 1.2919983862558445e+30 < b

    1. Initial program 34.2

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -9.47614345515238625 \cdot 10^{113}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le -4.3690676097323859 \cdot 10^{-164}:\\ \;\;\;\;\frac{\frac{4 \cdot \left(a \cdot c\right)}{2 \cdot a}}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}\\ \mathbf{elif}\;b \le 1.2919983862558445 \cdot 10^{30}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020100 
(FPCore (a b c)
  :name "The quadratic formula (r2)"
  :precision binary64

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

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