Average Error: 34.8 → 16.0
Time: 5.0s
Precision: 64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -4.11134778664368488 \cdot 10^{95}:\\ \;\;\;\;\frac{1.5 \cdot \frac{a \cdot c}{b} - 2 \cdot b}{3 \cdot a}\\ \mathbf{elif}\;b \le 8.9463181710813709 \cdot 10^{-95}:\\ \;\;\;\;\frac{\mathsf{fma}\left(-\sqrt[3]{b} \cdot \sqrt[3]{b}, \sqrt[3]{b}, \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1.5 \cdot \frac{a \cdot c}{b}}{3 \cdot a}\\ \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 \le -4.11134778664368488 \cdot 10^{95}:\\
\;\;\;\;\frac{1.5 \cdot \frac{a \cdot c}{b} - 2 \cdot b}{3 \cdot a}\\

\mathbf{elif}\;b \le 8.9463181710813709 \cdot 10^{-95}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-\sqrt[3]{b} \cdot \sqrt[3]{b}, \sqrt[3]{b}, \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}{3 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;\frac{-1.5 \cdot \frac{a \cdot c}{b}}{3 \cdot a}\\

\end{array}
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 VAR;
	if ((b <= -4.111347786643685e+95)) {
		VAR = (((1.5 * ((a * c) / b)) - (2.0 * b)) / (3.0 * a));
	} else {
		double VAR_1;
		if ((b <= 8.946318171081371e-95)) {
			VAR_1 = (fma(-(cbrt(b) * cbrt(b)), cbrt(b), sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a));
		} else {
			VAR_1 = ((-1.5 * ((a * c) / b)) / (3.0 * a));
		}
		VAR = VAR_1;
	}
	return VAR;
}

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 < -4.111347786643685e+95

    1. Initial program 45.4

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Taylor expanded around -inf 9.9

      \[\leadsto \frac{\color{blue}{1.5 \cdot \frac{a \cdot c}{b} - 2 \cdot b}}{3 \cdot a}\]

    if -4.111347786643685e+95 < b < 8.946318171081371e-95

    1. Initial program 12.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Using strategy rm
    3. Applied add-cube-cbrt12.8

      \[\leadsto \frac{\left(-\color{blue}{\left(\sqrt[3]{b} \cdot \sqrt[3]{b}\right) \cdot \sqrt[3]{b}}\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    4. Applied distribute-lft-neg-in12.8

      \[\leadsto \frac{\color{blue}{\left(-\sqrt[3]{b} \cdot \sqrt[3]{b}\right) \cdot \sqrt[3]{b}} + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    5. Applied fma-def12.8

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

    if 8.946318171081371e-95 < b

    1. Initial program 52.6

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Taylor expanded around inf 21.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.11134778664368488 \cdot 10^{95}:\\ \;\;\;\;\frac{1.5 \cdot \frac{a \cdot c}{b} - 2 \cdot b}{3 \cdot a}\\ \mathbf{elif}\;b \le 8.9463181710813709 \cdot 10^{-95}:\\ \;\;\;\;\frac{\mathsf{fma}\left(-\sqrt[3]{b} \cdot \sqrt[3]{b}, \sqrt[3]{b}, \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1.5 \cdot \frac{a \cdot c}{b}}{3 \cdot a}\\ \end{array}\]

Reproduce

herbie shell --seed 2020102 +o rules:numerics
(FPCore (a b c)
  :name "Cubic critical"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 3 a) c)))) (* 3 a)))