Average Error: 19.6 → 6.5
Time: 10.6s
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 -3.281222392987421 \cdot 10^{+142} \lor \neg \left(b \leq 8.332598834170677 \cdot 10^{+99}\right):\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{2 \cdot \left(b - \frac{c}{b} \cdot a\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{\frac{a}{\sqrt[3]{b} \cdot \sqrt[3]{b}} \cdot \frac{c}{\sqrt[3]{b}} - b}\\ \end{array}\\ \mathbf{elif}\;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}{\left|\sqrt[3]{b \cdot b - c \cdot \left(a \cdot 4\right)}\right| \cdot \sqrt{\sqrt[3]{b \cdot b - c \cdot \left(a \cdot 4\right)}} - b}\\ \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 -3.281222392987421 \cdot 10^{+142} \lor \neg \left(b \leq 8.332598834170677 \cdot 10^{+99}\right):\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{2 \cdot \left(b - \frac{c}{b} \cdot a\right)}{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{c}{\frac{a}{\sqrt[3]{b} \cdot \sqrt[3]{b}} \cdot \frac{c}{\sqrt[3]{b}} - b}\\

\end{array}\\

\mathbf{elif}\;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}{\left|\sqrt[3]{b \cdot b - c \cdot \left(a \cdot 4\right)}\right| \cdot \sqrt{\sqrt[3]{b \cdot b - c \cdot \left(a \cdot 4\right)}} - b}\\

\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 (or (<= b -3.281222392987421e+142) (not (<= b 8.332598834170677e+99)))
   (if (>= b 0.0)
     (* -0.5 (/ (* 2.0 (- b (* (/ c b) a))) a))
     (/ c (- (* (/ a (* (cbrt b) (cbrt b))) (/ c (cbrt b))) b)))
   (if (>= b 0.0)
     (* -0.5 (/ (+ b (sqrt (- (* b b) (* c (* a 4.0))))) a))
     (/
      (* 2.0 c)
      (-
       (*
        (fabs (cbrt (- (* b b) (* c (* a 4.0)))))
        (sqrt (cbrt (- (* b b) (* c (* a 4.0))))))
       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 <= -3.281222392987421e+142) || !(b <= 8.332598834170677e+99)) {
		double tmp_1;
		if (b >= 0.0) {
			tmp_1 = -0.5 * ((2.0 * (b - ((c / b) * a))) / a);
		} else {
			tmp_1 = c / (((a / (cbrt(b) * cbrt(b))) * (c / cbrt(b))) - b);
		}
		tmp = tmp_1;
	} else if (b >= 0.0) {
		tmp = -0.5 * ((b + sqrt((b * b) - (c * (a * 4.0)))) / a);
	} else {
		tmp = (2.0 * c) / ((fabs(cbrt((b * b) - (c * (a * 4.0)))) * sqrt(cbrt((b * b) - (c * (a * 4.0))))) - 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 2 regimes
  2. if b < -3.28122239298742125e142 or 8.3325988341706774e99 < b

    1. Initial program 40.8

      \[\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. Simplified40.8

      \[\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 23.9

      \[\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. Simplified23.9

      \[\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 add-cube-cbrt_binary64_10923.9

      \[\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}{\left(\sqrt[3]{b} \cdot \sqrt[3]{b}\right) \cdot \sqrt[3]{b}} - b\right)}\\ \end{array}\]
    7. Applied times-frac_binary64_8321.2

      \[\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}{\sqrt[3]{b} \cdot \sqrt[3]{b}} \cdot \frac{c}{\sqrt[3]{b}} - b\right)}\\ \end{array}\]
    8. Using strategy rm
    9. Applied associate-/r*_binary64_2321.0

      \[\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{\frac{c \cdot 2}{2}}{\frac{a}{\sqrt[3]{b} \cdot \sqrt[3]{b}} \cdot \frac{c}{\sqrt[3]{b}} - b}\\ \end{array}\]
    10. Simplified21.0

      \[\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}{\frac{a}{\sqrt[3]{b} \cdot \sqrt[3]{b}} \cdot \frac{c}{\sqrt[3]{b}} - b}\\ \end{array}\]
    11. Taylor expanded around inf 5.6

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{\color{blue}{2 \cdot b - 2 \cdot \frac{a \cdot c}{b}}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{\frac{a}{\sqrt[3]{b} \cdot \sqrt[3]{b}} \cdot \frac{c}{\sqrt[3]{b}} - b}\\ \end{array}\]
    12. Simplified2.7

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

    if -3.28122239298742125e142 < b < 8.3325988341706774e99

    1. Initial program 8.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. Simplified8.3

      \[\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 add-cube-cbrt_binary64_1098.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{\color{blue}{c} \cdot 2}{\sqrt{\left(\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}} - b}\\ \end{array}\]
    5. Applied sqrt-prod_binary64_928.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{\color{blue}{c \cdot 2}}{\sqrt{\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}} - b}\\ \end{array}\]
    6. Simplified8.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{\color{blue}{c} \cdot 2}{\left|\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}\right| \cdot \sqrt{\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}} - b}\\ \end{array}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification6.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -3.281222392987421 \cdot 10^{+142} \lor \neg \left(b \leq 8.332598834170677 \cdot 10^{+99}\right):\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;-0.5 \cdot \frac{2 \cdot \left(b - \frac{c}{b} \cdot a\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{\frac{a}{\sqrt[3]{b} \cdot \sqrt[3]{b}} \cdot \frac{c}{\sqrt[3]{b}} - b}\\ \end{array}\\ \mathbf{elif}\;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}{\left|\sqrt[3]{b \cdot b - c \cdot \left(a \cdot 4\right)}\right| \cdot \sqrt{\sqrt[3]{b \cdot b - c \cdot \left(a \cdot 4\right)}} - b}\\ \end{array}\]

Reproduce

herbie shell --seed 2020303 
(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)))))))