Average Error: 33.9 → 10.4
Time: 8.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 -1.3691570764324218 \cdot 10^{+95}:\\ \;\;\;\;\frac{\frac{\left(-b\right) - b}{3}}{a}\\ \mathbf{elif}\;b \leq 2.1387839641340222 \cdot 10^{-29}:\\ \;\;\;\;\left(\sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)} - b\right) \cdot \frac{0.3333333333333333}{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 -1.3691570764324218 \cdot 10^{+95}:\\
\;\;\;\;\frac{\frac{\left(-b\right) - b}{3}}{a}\\

\mathbf{elif}\;b \leq 2.1387839641340222 \cdot 10^{-29}:\\
\;\;\;\;\left(\sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)} - b\right) \cdot \frac{0.3333333333333333}{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 -1.3691570764324218e+95)
   (/ (/ (- (- b) b) 3.0) a)
   (if (<= b 2.1387839641340222e-29)
     (* (- (sqrt (+ (* b b) (* a (* c -3.0)))) b) (/ 0.3333333333333333 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 <= -1.3691570764324218e+95) {
		tmp = ((-b - b) / 3.0) / a;
	} else if (b <= 2.1387839641340222e-29) {
		tmp = (sqrt((b * b) + (a * (c * -3.0))) - b) * (0.3333333333333333 / 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 < -1.3691570764324218e95

    1. Initial program 45.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Simplified45.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 associate-/r*_binary6445.7

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

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

      \[\leadsto \frac{\frac{\color{blue}{-1 \cdot b} - b}{3}}{a}\]
    7. Simplified4.0

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

    if -1.3691570764324218e95 < b < 2.1387839641340222e-29

    1. Initial program 14.6

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

      \[\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 div-inv_binary6414.7

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

      \[\leadsto \left(\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b\right) \cdot \color{blue}{\frac{0.3333333333333333}{a}}\]
    6. Using strategy rm
    7. Applied sub-neg_binary6414.7

      \[\leadsto \left(\sqrt{\color{blue}{b \cdot b + \left(-\left(3 \cdot a\right) \cdot c\right)}} - b\right) \cdot \frac{0.3333333333333333}{a}\]
    8. Simplified14.7

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

    if 2.1387839641340222e-29 < b

    1. Initial program 54.9

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.3691570764324218 \cdot 10^{+95}:\\ \;\;\;\;\frac{\frac{\left(-b\right) - b}{3}}{a}\\ \mathbf{elif}\;b \leq 2.1387839641340222 \cdot 10^{-29}:\\ \;\;\;\;\left(\sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)} - b\right) \cdot \frac{0.3333333333333333}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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