Average Error: 33.7 → 14.2
Time: 6.1s
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 -3.877652638047906 \cdot 10^{+139}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} - \frac{b}{a} \cdot 0.6666666666666666\\ \mathbf{elif}\;b \leq 4.889920063260302 \cdot 10^{-55}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -0.5 + \frac{a \cdot \left(c \cdot c\right)}{{b}^{3}} \cdot -0.375\\ \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 -3.877652638047906 \cdot 10^{+139}:\\
\;\;\;\;0.5 \cdot \frac{c}{b} - \frac{b}{a} \cdot 0.6666666666666666\\

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

\mathbf{else}:\\
\;\;\;\;\frac{c}{b} \cdot -0.5 + \frac{a \cdot \left(c \cdot c\right)}{{b}^{3}} \cdot -0.375\\

\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 -3.877652638047906e+139)
   (- (* 0.5 (/ c b)) (* (/ b a) 0.6666666666666666))
   (if (<= b 4.889920063260302e-55)
     (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0))
     (+ (* (/ c b) -0.5) (* (/ (* a (* c c)) (pow b 3.0)) -0.375)))))
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 <= -3.877652638047906e+139) {
		tmp = (0.5 * (c / b)) - ((b / a) * 0.6666666666666666);
	} else if (b <= 4.889920063260302e-55) {
		tmp = (sqrt((b * b) - (c * (a * 3.0))) - b) / (a * 3.0);
	} else {
		tmp = ((c / b) * -0.5) + (((a * (c * c)) / pow(b, 3.0)) * -0.375);
	}
	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 < -3.877652638047906e139

    1. Initial program 59.1

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

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{c}{b} - 0.6666666666666666 \cdot \frac{b}{a}}\]
    4. Simplified2.8

      \[\leadsto \color{blue}{0.5 \cdot \frac{c}{b} - \frac{b}{a} \cdot 0.6666666666666666}\]

    if -3.877652638047906e139 < b < 4.8899200632603017e-55

    1. Initial program 12.7

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

    if 4.8899200632603017e-55 < b

    1. Initial program 53.7

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

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

      \[\leadsto \color{blue}{-\left(0.5 \cdot \frac{c}{b} + 0.375 \cdot \frac{a \cdot {c}^{2}}{{b}^{3}}\right)}\]
    4. Simplified19.8

      \[\leadsto \color{blue}{\frac{c}{b} \cdot -0.5 + \frac{a \cdot \left(c \cdot c\right)}{{b}^{3}} \cdot -0.375}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification14.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -3.877652638047906 \cdot 10^{+139}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} - \frac{b}{a} \cdot 0.6666666666666666\\ \mathbf{elif}\;b \leq 4.889920063260302 \cdot 10^{-55}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -0.5 + \frac{a \cdot \left(c \cdot c\right)}{{b}^{3}} \cdot -0.375\\ \end{array}\]

Reproduce

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