Average Error: 33.5 → 6.7
Time: 7.0s
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 -2.452019057043114 \cdot 10^{+129}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} - 0.6666666666666666 \cdot \frac{b}{a}\\ \mathbf{elif}\;b \leq 1.03289464838539 \cdot 10^{-299}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)}}{a \cdot 3} - \frac{b}{a \cdot 3}\\ \mathbf{elif}\;b \leq 1.1209799556123897 \cdot 10^{+93}:\\ \;\;\;\;\frac{1}{3 \cdot \frac{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)}}{c \cdot -3}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -0.5\\ \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 -2.452019057043114 \cdot 10^{+129}:\\
\;\;\;\;0.5 \cdot \frac{c}{b} - 0.6666666666666666 \cdot \frac{b}{a}\\

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

\mathbf{elif}\;b \leq 1.1209799556123897 \cdot 10^{+93}:\\
\;\;\;\;\frac{1}{3 \cdot \frac{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)}}{c \cdot -3}}\\

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

\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 -2.452019057043114e+129)
   (- (* 0.5 (/ c b)) (* 0.6666666666666666 (/ b a)))
   (if (<= b 1.03289464838539e-299)
     (- (/ (sqrt (- (* b b) (* c (* a 3.0)))) (* a 3.0)) (/ b (* a 3.0)))
     (if (<= b 1.1209799556123897e+93)
       (/ 1.0 (* 3.0 (/ (+ b (sqrt (- (* b b) (* c (* a 3.0))))) (* c -3.0))))
       (* (/ c b) -0.5)))))
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 <= -2.452019057043114e+129) {
		tmp = (0.5 * (c / b)) - (0.6666666666666666 * (b / a));
	} else if (b <= 1.03289464838539e-299) {
		tmp = (sqrt((b * b) - (c * (a * 3.0))) / (a * 3.0)) - (b / (a * 3.0));
	} else if (b <= 1.1209799556123897e+93) {
		tmp = 1.0 / (3.0 * ((b + sqrt((b * b) - (c * (a * 3.0)))) / (c * -3.0)));
	} else {
		tmp = (c / b) * -0.5;
	}
	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 < -2.45201905704311411e129

    1. Initial program 54.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Simplified54.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 3.2

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

    if -2.45201905704311411e129 < b < 1.03289464838539e-299

    1. Initial program 9.1

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

      \[\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-sub_binary64_14479.1

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

    if 1.03289464838539e-299 < b < 1.12097995561238967e93

    1. Initial program 31.5

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

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

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3}}{a}}\]
    5. Using strategy rm
    6. Applied flip--_binary64_141731.6

      \[\leadsto \frac{\frac{\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}}}{3}}{a}\]
    7. Simplified16.1

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

      \[\leadsto \frac{\frac{\frac{a \cdot \left(c \cdot -3\right)}{\color{blue}{b + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}}{3}}{a}\]
    9. Using strategy rm
    10. Applied clear-num_binary64_144116.3

      \[\leadsto \color{blue}{\frac{1}{\frac{a}{\frac{\frac{a \cdot \left(c \cdot -3\right)}{b + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}{3}}}}\]
    11. Simplified8.8

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

    if 1.12097995561238967e93 < b

    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.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2.452019057043114 \cdot 10^{+129}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} - 0.6666666666666666 \cdot \frac{b}{a}\\ \mathbf{elif}\;b \leq 1.03289464838539 \cdot 10^{-299}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)}}{a \cdot 3} - \frac{b}{a \cdot 3}\\ \mathbf{elif}\;b \leq 1.1209799556123897 \cdot 10^{+93}:\\ \;\;\;\;\frac{1}{3 \cdot \frac{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)}}{c \cdot -3}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -0.5\\ \end{array}\]

Reproduce

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