Average Error: 34.3 → 7.4
Time: 6.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 -8.0615263523114905 \cdot 10^{142}:\\ \;\;\;\;\frac{1}{\frac{3}{1.5 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}}}\\ \mathbf{elif}\;b \le -3.7607628574451261 \cdot 10^{-174}:\\ \;\;\;\;\frac{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3}}{a}\\ \mathbf{elif}\;b \le 1.44430318372460742:\\ \;\;\;\;\frac{1}{\frac{3}{\frac{1}{\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}} \cdot \left(c \cdot 3\right)}}\\ \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 -8.0615263523114905 \cdot 10^{142}:\\
\;\;\;\;\frac{1}{\frac{3}{1.5 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}}}\\

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

\mathbf{elif}\;b \le 1.44430318372460742:\\
\;\;\;\;\frac{1}{\frac{3}{\frac{1}{\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}} \cdot \left(c \cdot 3\right)}}\\

\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 <= -8.06152635231149e+142)) {
		VAR = (1.0 / (3.0 / ((1.5 * (c / b)) - (2.0 * (b / a)))));
	} else {
		double VAR_1;
		if ((b <= -3.760762857445126e-174)) {
			VAR_1 = (((-b + sqrt(((b * b) - ((3.0 * a) * c)))) / 3.0) / a);
		} else {
			double VAR_2;
			if ((b <= 1.4443031837246074)) {
				VAR_2 = (1.0 / (3.0 / ((1.0 / (-b - sqrt(((b * b) - ((3.0 * a) * c))))) * (c * 3.0))));
			} 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 < -8.06152635231149e+142

    1. Initial program 59.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 flip-+63.9

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

      \[\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 *-un-lft-identity62.7

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

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

      \[\leadsto \frac{\color{blue}{\frac{1}{1} \cdot \frac{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}\]
    9. Simplified62.7

      \[\leadsto \frac{\color{blue}{1} \cdot \frac{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}\]
    10. Simplified62.7

      \[\leadsto \frac{1 \cdot \color{blue}{\frac{3}{\frac{\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{a \cdot c}}}}{3 \cdot a}\]
    11. Using strategy rm
    12. Applied clear-num62.7

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

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

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

    if -8.06152635231149e+142 < b < -3.760762857445126e-174

    1. Initial program 6.3

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Using strategy rm
    3. Applied associate-/r*6.3

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

    if -3.760762857445126e-174 < b < 1.4443031837246074

    1. Initial program 23.1

      \[\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-+23.4

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

      \[\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 *-un-lft-identity17.0

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

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

      \[\leadsto \frac{\color{blue}{\frac{1}{1} \cdot \frac{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}\]
    9. Simplified17.0

      \[\leadsto \frac{\color{blue}{1} \cdot \frac{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}\]
    10. Simplified17.0

      \[\leadsto \frac{1 \cdot \color{blue}{\frac{3}{\frac{\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{a \cdot c}}}}{3 \cdot a}\]
    11. Using strategy rm
    12. Applied clear-num17.1

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

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

      \[\leadsto \frac{1}{\frac{3}{\frac{\frac{3}{\frac{\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{a \cdot c}}}{\color{blue}{1 \cdot a}}}}\]
    16. Applied div-inv17.6

      \[\leadsto \frac{1}{\frac{3}{\frac{\frac{3}{\color{blue}{\left(\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \frac{1}{a \cdot c}}}}{1 \cdot a}}}\]
    17. Applied *-un-lft-identity17.6

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

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

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

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

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

    if 1.4443031837246074 < b

    1. Initial program 56.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -8.0615263523114905 \cdot 10^{142}:\\ \;\;\;\;\frac{1}{\frac{3}{1.5 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}}}\\ \mathbf{elif}\;b \le -3.7607628574451261 \cdot 10^{-174}:\\ \;\;\;\;\frac{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3}}{a}\\ \mathbf{elif}\;b \le 1.44430318372460742:\\ \;\;\;\;\frac{1}{\frac{3}{\frac{1}{\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}} \cdot \left(c \cdot 3\right)}}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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