Average Error: 34.1 → 8.3
Time: 4.2s
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 -1.3324370156406744 \cdot 10^{154}:\\ \;\;\;\;\frac{\left(-b\right) + \left(1.5 \cdot \frac{a \cdot c}{b} - b\right)}{3 \cdot a}\\ \mathbf{elif}\;b \le -1.81326726409651757 \cdot 10^{-188}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\\ \mathbf{elif}\;b \le 3.9699026479641371 \cdot 10^{110}:\\ \;\;\;\;\frac{1}{1 \cdot \frac{\left(-b\right) - \sqrt{b \cdot b + \left(-\left(a \cdot c\right) \cdot 3\right)}}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{-\frac{2 \cdot b - 1.5 \cdot \frac{a \cdot c}{b}}{1}}\\ \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 -1.3324370156406744 \cdot 10^{154}:\\
\;\;\;\;\frac{\left(-b\right) + \left(1.5 \cdot \frac{a \cdot c}{b} - b\right)}{3 \cdot a}\\

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

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

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

\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 <= -1.3324370156406744e+154)) {
		VAR = ((-b + ((1.5 * ((a * c) / b)) - b)) / (3.0 * a));
	} else {
		double VAR_1;
		if ((b <= -1.8132672640965176e-188)) {
			VAR_1 = ((-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a));
		} else {
			double VAR_2;
			if ((b <= 3.969902647964137e+110)) {
				VAR_2 = (1.0 / (1.0 * ((-b - sqrt(((b * b) + -((a * c) * 3.0)))) / c)));
			} else {
				VAR_2 = (c / -(((2.0 * b) - (1.5 * ((a * c) / b))) / 1.0));
			}
			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 < -1.3324370156406744e+154

    1. Initial program 64.0

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

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

    if -1.3324370156406744e+154 < b < -1.8132672640965176e-188

    1. Initial program 7.2

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

    if -1.8132672640965176e-188 < b < 3.969902647964137e+110

    1. Initial program 29.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 sub-neg29.3

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

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

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

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

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

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

    if 3.969902647964137e+110 < b

    1. Initial program 60.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 sub-neg60.5

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

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

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

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

      \[\leadsto \frac{\frac{\color{blue}{\left(c \cdot a\right)} \cdot 3}{\left(-b\right) - \sqrt{b \cdot b + \left(-\left(a \cdot c\right) \cdot 3\right)}}}{3 \cdot a}\]
    10. Applied associate-*l*32.5

      \[\leadsto \frac{\frac{\color{blue}{c \cdot \left(a \cdot 3\right)}}{\left(-b\right) - \sqrt{b \cdot b + \left(-\left(a \cdot c\right) \cdot 3\right)}}}{3 \cdot a}\]
    11. Applied associate-/l*33.8

      \[\leadsto \frac{\color{blue}{\frac{c}{\frac{\left(-b\right) - \sqrt{b \cdot b + \left(-\left(a \cdot c\right) \cdot 3\right)}}{a \cdot 3}}}}{3 \cdot a}\]
    12. Applied associate-/l/33.3

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.3324370156406744 \cdot 10^{154}:\\ \;\;\;\;\frac{\left(-b\right) + \left(1.5 \cdot \frac{a \cdot c}{b} - b\right)}{3 \cdot a}\\ \mathbf{elif}\;b \le -1.81326726409651757 \cdot 10^{-188}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\\ \mathbf{elif}\;b \le 3.9699026479641371 \cdot 10^{110}:\\ \;\;\;\;\frac{1}{1 \cdot \frac{\left(-b\right) - \sqrt{b \cdot b + \left(-\left(a \cdot c\right) \cdot 3\right)}}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{-\frac{2 \cdot b - 1.5 \cdot \frac{a \cdot c}{b}}{1}}\\ \end{array}\]

Reproduce

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