Average Error: 34.8 → 8.2
Time: 5.8s
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 -2.29357534225476664 \cdot 10^{102}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} - 0.66666666666666663 \cdot \frac{b}{a}\\ \mathbf{elif}\;b \le -1.1994977793869009 \cdot 10^{-240}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \frac{1}{3 \cdot a}\\ \mathbf{elif}\;b \le 8.3790388975916793 \cdot 10^{-6}:\\ \;\;\;\;\frac{a \cdot \frac{c}{\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}{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 \le -2.29357534225476664 \cdot 10^{102}:\\
\;\;\;\;0.5 \cdot \frac{c}{b} - 0.66666666666666663 \cdot \frac{b}{a}\\

\mathbf{elif}\;b \le -1.1994977793869009 \cdot 10^{-240}:\\
\;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \frac{1}{3 \cdot a}\\

\mathbf{elif}\;b \le 8.3790388975916793 \cdot 10^{-6}:\\
\;\;\;\;\frac{a \cdot \frac{c}{\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}{a}\\

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

\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 <= -2.2935753422547666e+102)) {
		VAR = ((0.5 * (c / b)) - (0.6666666666666666 * (b / a)));
	} else {
		double VAR_1;
		if ((b <= -1.1994977793869009e-240)) {
			VAR_1 = ((-b + sqrt(((b * b) - ((3.0 * a) * c)))) * (1.0 / (3.0 * a)));
		} else {
			double VAR_2;
			if ((b <= 8.37903889759168e-06)) {
				VAR_2 = ((a * (c / (-b - sqrt(((b * b) - ((3.0 * a) * c)))))) / a);
			} else {
				VAR_2 = (-0.5 * (c / b));
			}
			VAR_1 = VAR_2;
		}
		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 4 regimes
  2. if b < -2.2935753422547666e+102

    1. Initial program 49.0

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

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

    if -2.2935753422547666e+102 < b < -1.1994977793869009e-240

    1. Initial program 8.5

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Using strategy rm
    3. Applied div-inv8.5

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

    if -1.1994977793869009e-240 < b < 8.37903889759168e-06

    1. Initial program 23.9

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

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

      \[\leadsto \frac{\frac{\color{blue}{0 + 3 \cdot \left(a \cdot c\right)}}{\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}{3 \cdot a}\]
    5. Using strategy rm
    6. Applied associate-/r*17.1

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

      \[\leadsto \frac{\color{blue}{\frac{3 \cdot \left(a \cdot c\right)}{3 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}}{a}\]
    8. Using strategy rm
    9. Applied *-un-lft-identity17.1

      \[\leadsto \frac{\frac{3 \cdot \left(a \cdot c\right)}{3 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{\color{blue}{1 \cdot a}}\]
    10. Applied associate-/r*17.1

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

      \[\leadsto \frac{\color{blue}{\frac{a \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}}{a}\]
    12. Using strategy rm
    13. Applied *-un-lft-identity17.0

      \[\leadsto \frac{\frac{a \cdot c}{\color{blue}{1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}}{a}\]
    14. Applied times-frac14.2

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

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

    if 8.37903889759168e-06 < b

    1. Initial program 56.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.29357534225476664 \cdot 10^{102}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} - 0.66666666666666663 \cdot \frac{b}{a}\\ \mathbf{elif}\;b \le -1.1994977793869009 \cdot 10^{-240}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \frac{1}{3 \cdot a}\\ \mathbf{elif}\;b \le 8.3790388975916793 \cdot 10^{-6}:\\ \;\;\;\;\frac{a \cdot \frac{c}{\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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