Average Error: 19.7 → 7.1
Time: 6.6s
Precision: binary64
\[\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
\[\begin{array}{l} \mathbf{if}\;b \leq -1.6744801799035577 \cdot 10^{+143} \lor \neg \left(b \leq 23.282155229196768\right):\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-2 \cdot \frac{c}{2 \cdot \left(b - \frac{c}{\frac{b}{a}}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(2 \cdot \frac{c}{\frac{b}{a}} - b\right) - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;-2 \cdot \left(\frac{\sqrt[3]{c} \cdot \sqrt[3]{c}}{\sqrt{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}} \cdot \frac{\sqrt[3]{c}}{\sqrt{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2 \cdot a}\\ \end{array}\]
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\

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

\end{array}
\begin{array}{l}
\mathbf{if}\;b \leq -1.6744801799035577 \cdot 10^{+143} \lor \neg \left(b \leq 23.282155229196768\right):\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-2 \cdot \frac{c}{2 \cdot \left(b - \frac{c}{\frac{b}{a}}\right)}\\

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

\end{array}\\

\mathbf{elif}\;b \geq 0:\\
\;\;\;\;-2 \cdot \left(\frac{\sqrt[3]{c} \cdot \sqrt[3]{c}}{\sqrt{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}} \cdot \frac{\sqrt[3]{c}}{\sqrt{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}\right)\\

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

\end{array}
(FPCore (a b c)
 :precision binary64
 (if (>= b 0.0)
   (/ (* 2.0 c) (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))))
   (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a))))
(FPCore (a b c)
 :precision binary64
 (if (or (<= b -1.6744801799035577e+143) (not (<= b 23.282155229196768)))
   (if (>= b 0.0)
     (* -2.0 (/ c (* 2.0 (- b (/ c (/ b a))))))
     (/ (- (- (* 2.0 (/ c (/ b a))) b) b) (* 2.0 a)))
   (if (>= b 0.0)
     (*
      -2.0
      (*
       (/
        (* (cbrt c) (cbrt c))
        (sqrt (+ b (sqrt (- (* b b) (* c (* a 4.0)))))))
       (/ (cbrt c) (sqrt (+ b (sqrt (- (* b b) (* c (* a 4.0)))))))))
     (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* 2.0 a)))))
double code(double a, double b, double c) {
	double tmp;
	if (b >= 0.0) {
		tmp = (2.0 * c) / (-b - sqrt((b * b) - ((4.0 * a) * c)));
	} else {
		tmp = (-b + sqrt((b * b) - ((4.0 * a) * c))) / (2.0 * a);
	}
	return tmp;
}
double code(double a, double b, double c) {
	double tmp;
	if ((b <= -1.6744801799035577e+143) || !(b <= 23.282155229196768)) {
		double tmp_1;
		if (b >= 0.0) {
			tmp_1 = -2.0 * (c / (2.0 * (b - (c / (b / a)))));
		} else {
			tmp_1 = (((2.0 * (c / (b / a))) - b) - b) / (2.0 * a);
		}
		tmp = tmp_1;
	} else if (b >= 0.0) {
		tmp = -2.0 * (((cbrt(c) * cbrt(c)) / sqrt(b + sqrt((b * b) - (c * (a * 4.0))))) * (cbrt(c) / sqrt(b + sqrt((b * b) - (c * (a * 4.0))))));
	} else {
		tmp = (sqrt((b * b) - (c * (a * 4.0))) - b) / (2.0 * a);
	}
	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 2 regimes
  2. if b < -1.6744801799035577e143 or 23.282155229196768 < b

    1. Initial program 32.3

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

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

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

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

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

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

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

    if -1.6744801799035577e143 < b < 23.282155229196768

    1. Initial program 9.1

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.6744801799035577 \cdot 10^{+143} \lor \neg \left(b \leq 23.282155229196768\right):\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-2 \cdot \frac{c}{2 \cdot \left(b - \frac{c}{\frac{b}{a}}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(2 \cdot \frac{c}{\frac{b}{a}} - b\right) - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;-2 \cdot \left(\frac{\sqrt[3]{c} \cdot \sqrt[3]{c}}{\sqrt{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}} \cdot \frac{\sqrt[3]{c}}{\sqrt{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2 \cdot a}\\ \end{array}\]

Reproduce

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