Average Error: 34.4 → 10.8
Time: 29.8s
Precision: binary64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \leq -4.973293101750323 \cdot 10^{+32}:\\ \;\;\;\;\frac{1}{\frac{3}{b \cdot -2} \cdot a}\\ \mathbf{elif}\;b \leq 2.2206845534742922 \cdot 10^{-06}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array}\]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \leq -4.973293101750323 \cdot 10^{+32}:\\
\;\;\;\;\frac{1}{\frac{3}{b \cdot -2} \cdot a}\\

\mathbf{elif}\;b \leq 2.2206845534742922 \cdot 10^{-06}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b}\\

\end{array}
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
(FPCore (a b c)
 :precision binary64
 (if (<= b -4.973293101750323e+32)
   (/ 1.0 (* (/ 3.0 (* b -2.0)) a))
   (if (<= b 2.2206845534742922e-06)
     (/ (- (sqrt (- (* b b) (* (* 3.0 a) c))) b) (* 3.0 a))
     (* -0.5 (/ c b)))))
double code(double a, double b, double c) {
	return (-b + sqrt((b * b) - ((3.0 * a) * c))) / (3.0 * a);
}
double code(double a, double b, double c) {
	double tmp;
	if (b <= -4.973293101750323e+32) {
		tmp = 1.0 / ((3.0 / (b * -2.0)) * a);
	} else if (b <= 2.2206845534742922e-06) {
		tmp = (sqrt((b * b) - ((3.0 * a) * c)) - b) / (3.0 * a);
	} else {
		tmp = -0.5 * (c / 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 < -4.9732931017503234e32

    1. Initial program 36.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Simplified36.7

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}}\]
    3. Using strategy rm
    4. Applied clear-num_binary64_144136.7

      \[\leadsto \color{blue}{\frac{1}{\frac{3 \cdot a}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}}}\]
    5. Simplified36.7

      \[\leadsto \frac{1}{\color{blue}{\frac{3}{\sqrt{b \cdot b - a \cdot \left(c \cdot 3\right)} - b} \cdot a}}\]
    6. Taylor expanded around -inf 6.6

      \[\leadsto \frac{1}{\frac{3}{\color{blue}{-2 \cdot b}} \cdot a}\]
    7. Simplified6.6

      \[\leadsto \frac{1}{\frac{3}{\color{blue}{b \cdot -2}} \cdot a}\]

    if -4.9732931017503234e32 < b < 2.22068455347429224e-6

    1. Initial program 16.8

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Simplified16.8

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

    if 2.22068455347429224e-6 < b

    1. Initial program 56.2

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Simplified56.2

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - 3 \cdot \left(a \cdot c\right)} - b}{3 \cdot a}}\]
    3. Taylor expanded around inf 5.6

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification10.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -4.973293101750323 \cdot 10^{+32}:\\ \;\;\;\;\frac{1}{\frac{3}{b \cdot -2} \cdot a}\\ \mathbf{elif}\;b \leq 2.2206845534742922 \cdot 10^{-06}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2021176 
(FPCore (a b c)
  :name "Cubic critical"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))