Average Error: 33.7 → 7.2
Time: 6.1s
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.6507510594910507 \cdot 10^{86}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -4.9288416493375411 \cdot 10^{-202}:\\ \;\;\;\;\frac{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{\frac{2 \cdot a}{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}\\ \mathbf{elif}\;b \le 1.44876816713565448 \cdot 10^{131}:\\ \;\;\;\;\frac{1}{\frac{0.5}{c} \cdot \left(-b\right) + \frac{0.5}{c} \cdot \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\\ \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.6507510594910507 \cdot 10^{86}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

\mathbf{elif}\;b \le 1.44876816713565448 \cdot 10^{131}:\\
\;\;\;\;\frac{1}{\frac{0.5}{c} \cdot \left(-b\right) + \frac{0.5}{c} \cdot \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \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 <= -1.6507510594910507e+86)) {
		VAR = (1.0 * ((c / b) - (b / a)));
	} else {
		double VAR_1;
		if ((b <= -4.928841649337541e-202)) {
			VAR_1 = (sqrt((-b + sqrt(((b * b) - ((4.0 * a) * c))))) / ((2.0 * a) / sqrt((-b + sqrt(((b * b) - ((4.0 * a) * c)))))));
		} else {
			double VAR_2;
			if ((b <= 1.4487681671356545e+131)) {
				VAR_2 = (1.0 / (((0.5 / c) * -b) + ((0.5 / c) * -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

Original33.7
Target20.9
Herbie7.2
\[\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.6507510594910507e+86

    1. Initial program 42.0

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

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

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

    if -1.6507510594910507e+86 < b < -4.928841649337541e-202

    1. Initial program 7.3

      \[\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-sqrt7.6

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

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

    if -4.928841649337541e-202 < b < 1.4487681671356545e+131

    1. Initial program 31.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 flip-+31.7

      \[\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}\]
    5. Using strategy rm
    6. Applied clear-num17.1

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

      \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot a}{4 \cdot \left(a \cdot c\right)} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\]
    8. Taylor expanded around 0 10.6

      \[\leadsto \frac{1}{\color{blue}{\frac{0.5}{c}} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\]
    9. Using strategy rm
    10. Applied sub-neg10.6

      \[\leadsto \frac{1}{\frac{0.5}{c} \cdot \color{blue}{\left(\left(-b\right) + \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)\right)}}\]
    11. Applied distribute-lft-in10.6

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

    if 1.4487681671356545e+131 < b

    1. Initial program 61.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.6507510594910507 \cdot 10^{86}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -4.9288416493375411 \cdot 10^{-202}:\\ \;\;\;\;\frac{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{\frac{2 \cdot a}{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}\\ \mathbf{elif}\;b \le 1.44876816713565448 \cdot 10^{131}:\\ \;\;\;\;\frac{1}{\frac{0.5}{c} \cdot \left(-b\right) + \frac{0.5}{c} \cdot \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2020100 +o rules:numerics
(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)))