Average Error: 34.1 → 9.3
Time: 6.2s
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 -0.04248736169027556:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le -7.2720221422685763 \cdot 10^{-101}:\\ \;\;\;\;\frac{\sqrt[3]{\frac{1}{2 \cdot a}} \cdot \sqrt[3]{\frac{1}{2 \cdot a}}}{\frac{\frac{1}{\frac{0 + 4 \cdot \left(a \cdot c\right)}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}}}{\sqrt[3]{\frac{1}{2 \cdot a}}}}\\ \mathbf{elif}\;b \le 5.3362850167303113 \cdot 10^{150}:\\ \;\;\;\;\frac{\frac{1}{2 \cdot a}}{\frac{1}{\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 -0.04248736169027556:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\

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

\mathbf{elif}\;b \le 5.3362850167303113 \cdot 10^{150}:\\
\;\;\;\;\frac{\frac{1}{2 \cdot a}}{\frac{1}{\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 <= -0.04248736169027556)) {
		VAR = (-1.0 * (c / b));
	} else {
		double VAR_1;
		if ((b <= -7.272022142268576e-101)) {
			VAR_1 = ((cbrt((1.0 / (2.0 * a))) * cbrt((1.0 / (2.0 * a)))) / ((1.0 / ((0.0 + (4.0 * (a * c))) / (sqrt(((b * b) - (4.0 * (a * c)))) - b))) / cbrt((1.0 / (2.0 * a)))));
		} else {
			double VAR_2;
			if ((b <= 5.336285016730311e+150)) {
				VAR_2 = ((1.0 / (2.0 * a)) / (1.0 / (-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

Original34.1
Target20.9
Herbie9.3
\[\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 < -0.04248736169027556

    1. Initial program 56.1

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]

    if -0.04248736169027556 < b < -7.272022142268576e-101

    1. Initial program 37.3

      \[\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-num37.3

      \[\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 div-inv37.3

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

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

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

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

      \[\leadsto \frac{\sqrt[3]{\frac{1}{2 \cdot a}} \cdot \sqrt[3]{\frac{1}{2 \cdot a}}}{\frac{\frac{1}{\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)}}}}}{\sqrt[3]{\frac{1}{2 \cdot a}}}}\]
    12. Simplified17.4

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

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

    if -7.272022142268576e-101 < b < 5.336285016730311e+150

    1. Initial program 11.9

      \[\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.0

      \[\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 div-inv12.0

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

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

    if 5.336285016730311e+150 < b

    1. Initial program 62.8

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -0.04248736169027556:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le -7.2720221422685763 \cdot 10^{-101}:\\ \;\;\;\;\frac{\sqrt[3]{\frac{1}{2 \cdot a}} \cdot \sqrt[3]{\frac{1}{2 \cdot a}}}{\frac{\frac{1}{\frac{0 + 4 \cdot \left(a \cdot c\right)}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}}}{\sqrt[3]{\frac{1}{2 \cdot a}}}}\\ \mathbf{elif}\;b \le 5.3362850167303113 \cdot 10^{150}:\\ \;\;\;\;\frac{\frac{1}{2 \cdot a}}{\frac{1}{\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 2020105 +o rules:numerics
(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)))