Average Error: 19.6 → 6.6
Time: 4.9s
Precision: binary64
\[\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
\[\begin{array}{l} \mathbf{if}\;b \leq -7.906974219198102 \cdot 10^{+158}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + \left(b - 2 \cdot \left(a \cdot \frac{c}{b}\right)\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{2 \cdot \left(a \cdot \frac{c}{b} - b\right)}\\ \end{array}\\ \mathbf{elif}\;b \leq -8.240572048097193 \cdot 10^{-292}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{\frac{c \cdot \left(a \cdot 4\right)}{b - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}\\ \end{array}\\ \mathbf{elif}\;b \leq 1.575494962430441 \cdot 10^{+134}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\frac{a \cdot \left(c \cdot -4\right)}{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + \left(b - 2 \cdot \left(a \cdot \frac{c}{b}\right)\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{2 \cdot \left(a \cdot \frac{c}{b} - b\right)}\\ \end{array}\]
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\

\end{array}
\begin{array}{l}
\mathbf{if}\;b \leq -7.906974219198102 \cdot 10^{+158}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{b + \left(b - 2 \cdot \left(a \cdot \frac{c}{b}\right)\right)}{a}\\

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

\end{array}\\

\mathbf{elif}\;b \leq -8.240572048097193 \cdot 10^{-292}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{\frac{c \cdot \left(a \cdot 4\right)}{b - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}\\

\end{array}\\

\mathbf{elif}\;b \leq 1.575494962430441 \cdot 10^{+134}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\frac{a \cdot \left(c \cdot -4\right)}{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}\\

\end{array}\\

\mathbf{elif}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{b + \left(b - 2 \cdot \left(a \cdot \frac{c}{b}\right)\right)}{a}\\

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

\end{array}
(FPCore (a b c)
 :precision binary64
 (if (>= b 0.0)
   (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a))
   (/ (* 2.0 c) (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))))))
(FPCore (a b c)
 :precision binary64
 (if (<= b -7.906974219198102e+158)
   (if (>= b 0.0)
     (* -0.5 (/ (+ b (- b (* 2.0 (* a (/ c b))))) a))
     (/ (* 2.0 c) (* 2.0 (- (* a (/ c b)) b))))
   (if (<= b -8.240572048097193e-292)
     (if (>= b 0.0)
       (*
        -0.5
        (/ (/ (* c (* a 4.0)) (- b (sqrt (- (* b b) (* c (* a 4.0)))))) a))
       (/ (* 2.0 c) (- (sqrt (- (* b b) (* c (* a 4.0)))) b)))
     (if (<= b 1.575494962430441e+134)
       (if (>= b 0.0)
         (* -0.5 (/ (+ b (sqrt (- (* b b) (* c (* a 4.0))))) a))
         (/
          (* 2.0 c)
          (/ (* a (* c -4.0)) (+ b (sqrt (- (* b b) (* c (* a 4.0))))))))
       (if (>= b 0.0)
         (* -0.5 (/ (+ b (- b (* 2.0 (* a (/ c b))))) a))
         (/ (* 2.0 c) (* 2.0 (- (* a (/ c b)) b))))))))
double code(double a, double b, double c) {
	double tmp;
	if (b >= 0.0) {
		tmp = (-b - sqrt((b * b) - ((4.0 * a) * c))) / (2.0 * a);
	} else {
		tmp = (2.0 * c) / (-b + sqrt((b * b) - ((4.0 * a) * c)));
	}
	return tmp;
}
double code(double a, double b, double c) {
	double tmp;
	if (b <= -7.906974219198102e+158) {
		double tmp_1;
		if (b >= 0.0) {
			tmp_1 = -0.5 * ((b + (b - (2.0 * (a * (c / b))))) / a);
		} else {
			tmp_1 = (2.0 * c) / (2.0 * ((a * (c / b)) - b));
		}
		tmp = tmp_1;
	} else if (b <= -8.240572048097193e-292) {
		double tmp_2;
		if (b >= 0.0) {
			tmp_2 = -0.5 * (((c * (a * 4.0)) / (b - sqrt((b * b) - (c * (a * 4.0))))) / a);
		} else {
			tmp_2 = (2.0 * c) / (sqrt((b * b) - (c * (a * 4.0))) - b);
		}
		tmp = tmp_2;
	} else if (b <= 1.575494962430441e+134) {
		double tmp_3;
		if (b >= 0.0) {
			tmp_3 = -0.5 * ((b + sqrt((b * b) - (c * (a * 4.0)))) / a);
		} else {
			tmp_3 = (2.0 * c) / ((a * (c * -4.0)) / (b + sqrt((b * b) - (c * (a * 4.0)))));
		}
		tmp = tmp_3;
	} else if (b >= 0.0) {
		tmp = -0.5 * ((b + (b - (2.0 * (a * (c / b))))) / a);
	} else {
		tmp = (2.0 * c) / (2.0 * ((a * (c / b)) - b));
	}
	return tmp;
}

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

Derivation

  1. Split input into 3 regimes
  2. if b < -7.90697421919810219e158 or 1.575494962430441e134 < b

    1. Initial program 46.0

      \[\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
    2. Simplified46.0

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}\\ \end{array}}\]
    3. Taylor expanded around -inf 27.3

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a}\\ \mathbf{else}:\\ \;\;\;\;\color{blue}{\frac{c \cdot 2}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}}\\ \end{array}\]
    4. Simplified27.3

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a}\\ \mathbf{else}:\\ \;\;\;\;\color{blue}{\frac{c \cdot 2}{2 \cdot \left(\frac{a \cdot c}{b} - b\right)}}\\ \end{array}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity_binary6427.3

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{2 \cdot \left(\frac{a \cdot c}{1 \cdot b} - b\right)}\\ \end{array}\]
    7. Applied times-frac_binary6424.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\color{blue}{2} \cdot \left(\frac{a}{1} \cdot \frac{c}{b} - b\right)}\\ \end{array}\]
    8. Simplified24.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{2 \cdot \left(a \cdot \frac{c}{b} - b\right)}\\ \end{array}\]
    9. Taylor expanded around inf 5.8

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + \color{blue}{\left(b - 2 \cdot \frac{a \cdot c}{b}\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{2 \cdot \left(a \cdot \frac{c}{b} - b\right)}\\ \end{array}\]
    10. Simplified2.2

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + \color{blue}{\left(b - 2 \cdot \left(a \cdot \frac{c}{b}\right)\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{2 \cdot \left(a \cdot \frac{c}{b} - b\right)}\\ \end{array}\]

    if -7.90697421919810219e158 < b < -8.2405720480971928e-292

    1. Initial program 7.6

      \[\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
    2. Simplified7.6

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}\\ \end{array}}\]
    3. Using strategy rm
    4. Applied flip-+_binary647.6

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{\color{blue}{\frac{b \cdot b - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{b - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}\\ \end{array}\]
    5. Simplified7.6

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{\frac{\color{blue}{\left(4 \cdot a\right) \cdot c}}{b - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}\\ \end{array}\]

    if -8.2405720480971928e-292 < b < 1.575494962430441e134

    1. Initial program 9.3

      \[\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
    2. Simplified9.4

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}\\ \end{array}}\]
    3. Using strategy rm
    4. Applied flip--_binary649.4

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a}\\ \mathbf{else}:\\ \;\;\;\;\color{blue}{\frac{c \cdot 2}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b \cdot b}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}}}\\ \end{array}\]
    5. Simplified9.4

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{\color{blue}{c \cdot 2}}{\frac{a \cdot \left(c \cdot -4\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}}\\ \end{array}\]
    6. Simplified9.4

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\color{blue}{\frac{a \cdot \left(c \cdot -4\right)}{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}\\ \end{array}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification6.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -7.906974219198102 \cdot 10^{+158}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + \left(b - 2 \cdot \left(a \cdot \frac{c}{b}\right)\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{2 \cdot \left(a \cdot \frac{c}{b} - b\right)}\\ \end{array}\\ \mathbf{elif}\;b \leq -8.240572048097193 \cdot 10^{-292}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{\frac{c \cdot \left(a \cdot 4\right)}{b - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}\\ \end{array}\\ \mathbf{elif}\;b \leq 1.575494962430441 \cdot 10^{+134}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\frac{a \cdot \left(c \cdot -4\right)}{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{b + \left(b - 2 \cdot \left(a \cdot \frac{c}{b}\right)\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{2 \cdot \left(a \cdot \frac{c}{b} - b\right)}\\ \end{array}\]

Reproduce

herbie shell --seed 2020260 
(FPCore (a b c)
  :name "jeff quadratic root 1"
  :precision binary64
  (if (>= b 0.0) (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ (* 2.0 c) (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))))))