Average Error: 33.8 → 10.0
Time: 4.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 -1.45334315236151028 \cdot 10^{-64}:\\ \;\;\;\;{\left(-1 \cdot \frac{c}{b}\right)}^{1}\\ \mathbf{elif}\;b \le 7.516025817305246 \cdot 10^{102}:\\ \;\;\;\;{\left(\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\right)}^{1}\\ \mathbf{else}:\\ \;\;\;\;{\left(1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\right)}^{1}\\ \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 -1.45334315236151028 \cdot 10^{-64}:\\
\;\;\;\;{\left(-1 \cdot \frac{c}{b}\right)}^{1}\\

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

\mathbf{else}:\\
\;\;\;\;{\left(1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\right)}^{1}\\

\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.4533431523615103e-64)) {
		VAR = pow((-1.0 * (c / b)), 1.0);
	} else {
		double VAR_1;
		if ((b <= 7.516025817305246e+102)) {
			VAR_1 = pow(((-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)), 1.0);
		} else {
			VAR_1 = pow((1.0 * ((c / b) - (b / a))), 1.0);
		}
		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.8
Target20.6
Herbie10.0
\[\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 3 regimes
  2. if b < -1.4533431523615103e-64

    1. Initial program 53.1

      \[\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-inv53.1

      \[\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 pow153.1

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

      \[\leadsto \color{blue}{{\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}^{1}} \cdot {\left(\frac{1}{2 \cdot a}\right)}^{1}\]
    7. Applied pow-prod-down53.1

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

      \[\leadsto {\color{blue}{\left(\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\right)}}^{1}\]
    9. Taylor expanded around -inf 8.7

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

    if -1.4533431523615103e-64 < b < 7.516025817305246e+102

    1. Initial program 13.2

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

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

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

      \[\leadsto \color{blue}{{\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}^{1}} \cdot {\left(\frac{1}{2 \cdot a}\right)}^{1}\]
    7. Applied pow-prod-down13.3

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

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

    if 7.516025817305246e+102 < b

    1. Initial program 47.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 div-inv47.6

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

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

      \[\leadsto \color{blue}{{\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}^{1}} \cdot {\left(\frac{1}{2 \cdot a}\right)}^{1}\]
    7. Applied pow-prod-down47.6

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

      \[\leadsto {\color{blue}{\left(\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\right)}}^{1}\]
    9. Taylor expanded around inf 3.5

      \[\leadsto {\color{blue}{\left(1 \cdot \frac{c}{b} - 1 \cdot \frac{b}{a}\right)}}^{1}\]
    10. Simplified3.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.45334315236151028 \cdot 10^{-64}:\\ \;\;\;\;{\left(-1 \cdot \frac{c}{b}\right)}^{1}\\ \mathbf{elif}\;b \le 7.516025817305246 \cdot 10^{102}:\\ \;\;\;\;{\left(\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\right)}^{1}\\ \mathbf{else}:\\ \;\;\;\;{\left(1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\right)}^{1}\\ \end{array}\]

Reproduce

herbie shell --seed 2020078 +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)))