Average Error: 33.9 → 9.0
Time: 7.7s
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 -5.937328566151444 \cdot 10^{+119}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} + \frac{b}{a} \cdot -0.6666666666666666\\ \mathbf{elif}\;b \leq 1.9911819164430855 \cdot 10^{-143}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3}\\ \mathbf{elif}\;b \leq 8.101478123646484 \cdot 10^{+82}:\\ \;\;\;\;\frac{a \cdot \left(c \cdot -3\right)}{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)}} \cdot \frac{0.3333333333333333}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{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 -5.937328566151444 \cdot 10^{+119}:\\
\;\;\;\;0.5 \cdot \frac{c}{b} + \frac{b}{a} \cdot -0.6666666666666666\\

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

\mathbf{elif}\;b \leq 8.101478123646484 \cdot 10^{+82}:\\
\;\;\;\;\frac{a \cdot \left(c \cdot -3\right)}{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)}} \cdot \frac{0.3333333333333333}{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{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 -5.937328566151444e+119)
   (+ (* 0.5 (/ c b)) (* (/ b a) -0.6666666666666666))
   (if (<= b 1.9911819164430855e-143)
     (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0))
     (if (<= b 8.101478123646484e+82)
       (*
        (/ (* a (* c -3.0)) (+ b (sqrt (- (* b b) (* c (* a 3.0))))))
        (/ 0.3333333333333333 a))
       (/ (* c -0.5) 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 <= -5.937328566151444e+119) {
		tmp = (0.5 * (c / b)) + ((b / a) * -0.6666666666666666);
	} else if (b <= 1.9911819164430855e-143) {
		tmp = (sqrt((b * b) - (c * (a * 3.0))) - b) / (a * 3.0);
	} else if (b <= 8.101478123646484e+82) {
		tmp = ((a * (c * -3.0)) / (b + sqrt((b * b) - (c * (a * 3.0))))) * (0.3333333333333333 / a);
	} else {
		tmp = (c * -0.5) / 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 4 regimes
  2. if b < -5.9373285661514437e119

    1. Initial program 52.5

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

      \[\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.6

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

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

    if -5.9373285661514437e119 < b < 1.9911819164430855e-143

    1. Initial program 11.1

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

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

    if 1.9911819164430855e-143 < b < 8.1014781236464845e82

    1. Initial program 39.4

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

      \[\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_binary64_246239.4

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

      \[\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 flip--_binary64_244039.5

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

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

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

    if 8.1014781236464845e82 < b

    1. Initial program 58.6

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

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b}}\]
    4. Using strategy rm
    5. Applied associate-*r/_binary64_24073.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -5.937328566151444 \cdot 10^{+119}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} + \frac{b}{a} \cdot -0.6666666666666666\\ \mathbf{elif}\;b \leq 1.9911819164430855 \cdot 10^{-143}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3}\\ \mathbf{elif}\;b \leq 8.101478123646484 \cdot 10^{+82}:\\ \;\;\;\;\frac{a \cdot \left(c \cdot -3\right)}{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)}} \cdot \frac{0.3333333333333333}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array}\]

Reproduce

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