Average Error: 33.9 → 6.5
Time: 5.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.097183452461109 \cdot 10^{+149}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} - 0.6666666666666666 \cdot \frac{b}{a}\\ \mathbf{elif}\;b \leq -4.704826106702257 \cdot 10^{-221}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{3}}{a}\\ \mathbf{elif}\;b \leq 2.217223282760919 \cdot 10^{+108}:\\ \;\;\;\;\frac{1}{\left(b + \sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)}\right) \cdot \frac{-1}{c}}\\ \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.097183452461109 \cdot 10^{+149}:\\
\;\;\;\;0.5 \cdot \frac{c}{b} - 0.6666666666666666 \cdot \frac{b}{a}\\

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

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

\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.097183452461109e+149)
   (- (* 0.5 (/ c b)) (* 0.6666666666666666 (/ b a)))
   (if (<= b -4.704826106702257e-221)
     (/ (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) 3.0) a)
     (if (<= b 2.217223282760919e+108)
       (/ 1.0 (* (+ b (sqrt (- (* b b) (* c (* a 3.0))))) (/ -1.0 c)))
       (* (/ 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.097183452461109e+149) {
		tmp = (0.5 * (c / b)) - (0.6666666666666666 * (b / a));
	} else if (b <= -4.704826106702257e-221) {
		tmp = ((sqrt((b * b) - (c * (a * 3.0))) - b) / 3.0) / a;
	} else if (b <= 2.217223282760919e+108) {
		tmp = 1.0 / ((b + sqrt((b * b) - (c * (a * 3.0)))) * (-1.0 / c));
	} 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.0971834524611091e149

    1. Initial program 62.2

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

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

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

    if -2.0971834524611091e149 < b < -4.7048261067022572e-221

    1. Initial program 7.2

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

      \[\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*_binary647.2

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

    if -4.7048261067022572e-221 < b < 2.21722328276091895e108

    1. Initial program 30.8

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

      \[\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 flip--_binary6430.9

      \[\leadsto \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 \cdot a}\]
    5. Simplified16.4

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

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

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

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

    if 2.21722328276091895e108 < b

    1. Initial program 59.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2.097183452461109 \cdot 10^{+149}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} - 0.6666666666666666 \cdot \frac{b}{a}\\ \mathbf{elif}\;b \leq -4.704826106702257 \cdot 10^{-221}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{3}}{a}\\ \mathbf{elif}\;b \leq 2.217223282760919 \cdot 10^{+108}:\\ \;\;\;\;\frac{1}{\left(b + \sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)}\right) \cdot \frac{-1}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -0.5\\ \end{array}\]

Reproduce

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