Average Error: 28.3 → 5.2
Time: 1.4min
Precision: binary64
\[1.0536712127723509 \cdot 10^{-8} < a \land a < 94906265.62425156 \land 1.0536712127723509 \cdot 10^{-8} < b \land b < 94906265.62425156 \land 1.0536712127723509 \cdot 10^{-8} < c \land c < 94906265.62425156\]
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a} \leq -1.2336704304669632:\\ \;\;\;\;\frac{\frac{\left(b \cdot b - 3 \cdot \left(a \cdot c\right)\right) - b \cdot b}{b + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;0.5625 \cdot \frac{{a}^{2} \cdot \left(-{c}^{3}\right)}{{b}^{5}} - \left(1.0546875 \cdot \frac{{c}^{4} \cdot {a}^{3}}{{b}^{7}} + \left(0.375 \cdot \frac{a \cdot {c}^{2}}{{b}^{3}} + 0.5 \cdot \frac{c}{b}\right)\right)\\ \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}\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a} \leq -1.2336704304669632:\\
\;\;\;\;\frac{\frac{\left(b \cdot b - 3 \cdot \left(a \cdot c\right)\right) - b \cdot b}{b + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}{3 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;0.5625 \cdot \frac{{a}^{2} \cdot \left(-{c}^{3}\right)}{{b}^{5}} - \left(1.0546875 \cdot \frac{{c}^{4} \cdot {a}^{3}}{{b}^{7}} + \left(0.375 \cdot \frac{a \cdot {c}^{2}}{{b}^{3}} + 0.5 \cdot \frac{c}{b}\right)\right)\\


\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 (<=
      (/ (- (sqrt (- (* b b) (* (* 3.0 a) c))) b) (* 3.0 a))
      -1.2336704304669632)
   (/
    (/
     (- (- (* b b) (* 3.0 (* a c))) (* b b))
     (+ b (sqrt (- (* b b) (* (* 3.0 a) c)))))
    (* 3.0 a))
   (-
    (* 0.5625 (/ (* (pow a 2.0) (- (pow c 3.0))) (pow b 5.0)))
    (+
     (* 1.0546875 (/ (* (pow c 4.0) (pow a 3.0)) (pow b 7.0)))
     (+ (* 0.375 (/ (* a (pow c 2.0)) (pow b 3.0))) (* 0.5 (/ c b)))))))
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 (((sqrt((b * b) - ((3.0 * a) * c)) - b) / (3.0 * a)) <= -1.2336704304669632) {
		tmp = ((((b * b) - (3.0 * (a * c))) - (b * b)) / (b + sqrt((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
	} else {
		tmp = (0.5625 * ((pow(a, 2.0) * -pow(c, 3.0)) / pow(b, 5.0))) - ((1.0546875 * ((pow(c, 4.0) * pow(a, 3.0)) / pow(b, 7.0))) + ((0.375 * ((a * pow(c, 2.0)) / pow(b, 3.0))) + (0.5 * (c / b))));
	}
	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 2 regimes
  2. if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) < -1.23367043046696323

    1. Initial program 10.9

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

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

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

    if -1.23367043046696323 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a))

    1. Initial program 31.0

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

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

      \[\leadsto \color{blue}{-\left(0.5625 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}} + \left(1.0546875 \cdot \frac{{c}^{4} \cdot {a}^{3}}{{b}^{7}} + \left(0.375 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}} + 0.5 \cdot \frac{c}{b}\right)\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification5.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a} \leq -1.2336704304669632:\\ \;\;\;\;\frac{\frac{\left(b \cdot b - 3 \cdot \left(a \cdot c\right)\right) - b \cdot b}{b + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;0.5625 \cdot \frac{{a}^{2} \cdot \left(-{c}^{3}\right)}{{b}^{5}} - \left(1.0546875 \cdot \frac{{c}^{4} \cdot {a}^{3}}{{b}^{7}} + \left(0.375 \cdot \frac{a \cdot {c}^{2}}{{b}^{3}} + 0.5 \cdot \frac{c}{b}\right)\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2021210 
(FPCore (a b c)
  :name "Cubic critical, narrow range"
  :precision binary64
  :pre (and (< 1.0536712127723509e-8 a 94906265.62425156) (< 1.0536712127723509e-8 b 94906265.62425156) (< 1.0536712127723509e-8 c 94906265.62425156))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))