Average Error: 34.3 → 7.3
Time: 7.0s
Precision: binary64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \leq -5.212113506128886 \cdot 10^{+52}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} - 0.6666666666666666 \cdot \frac{b}{a}\\ \mathbf{elif}\;b \leq -1.566285583643343 \cdot 10^{-266}:\\ \;\;\;\;\frac{1}{\frac{3}{\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a}}}\\ \mathbf{elif}\;b \leq 7.178750185064038 \cdot 10^{+92}:\\ \;\;\;\;\frac{c}{\left(-b\right) - \sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -0.5\\ \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 \leq -5.212113506128886 \cdot 10^{+52}:\\
\;\;\;\;0.5 \cdot \frac{c}{b} - 0.6666666666666666 \cdot \frac{b}{a}\\

\mathbf{elif}\;b \leq -1.566285583643343 \cdot 10^{-266}:\\
\;\;\;\;\frac{1}{\frac{3}{\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a}}}\\

\mathbf{elif}\;b \leq 7.178750185064038 \cdot 10^{+92}:\\
\;\;\;\;\frac{c}{\left(-b\right) - \sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)}}\\

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

\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 (<= b -5.212113506128886e+52)
   (- (* 0.5 (/ c b)) (* 0.6666666666666666 (/ b a)))
   (if (<= b -1.566285583643343e-266)
     (/ 1.0 (/ 3.0 (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) a)))
     (if (<= b 7.178750185064038e+92)
       (/ c (- (- b) (sqrt (+ (* b b) (* a (* c -3.0))))))
       (* (/ c b) -0.5)))))
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 (b <= -5.212113506128886e+52) {
		tmp = (0.5 * (c / b)) - (0.6666666666666666 * (b / a));
	} else if (b <= -1.566285583643343e-266) {
		tmp = 1.0 / (3.0 / ((sqrt((b * b) - (c * (a * 3.0))) - b) / a));
	} else if (b <= 7.178750185064038e+92) {
		tmp = c / (-b - sqrt((b * b) + (a * (c * -3.0))));
	} else {
		tmp = (c / b) * -0.5;
	}
	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 4 regimes
  2. if b < -5.21211350612888562e52

    1. Initial program 38.4

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

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

    if -5.21211350612888562e52 < b < -1.5662855836433431e-266

    1. Initial program 9.6

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

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

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

    if -1.5662855836433431e-266 < b < 7.178750185064038e92

    1. Initial program 30.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-+_binary64_177330.6

      \[\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. Simplified16.3

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

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

      \[\leadsto \frac{1}{\color{blue}{1 \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{c}}}\]
    8. Using strategy rm
    9. Applied add-sqr-sqrt_binary64_18219.4

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

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

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

      \[\leadsto 1 \cdot \color{blue}{\frac{c}{\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}\]
    13. Using strategy rm
    14. Applied sub-neg_binary64_17929.0

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

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

    if 7.178750185064038e92 < b

    1. Initial program 59.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -5.212113506128886 \cdot 10^{+52}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} - 0.6666666666666666 \cdot \frac{b}{a}\\ \mathbf{elif}\;b \leq -1.566285583643343 \cdot 10^{-266}:\\ \;\;\;\;\frac{1}{\frac{3}{\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a}}}\\ \mathbf{elif}\;b \leq 7.178750185064038 \cdot 10^{+92}:\\ \;\;\;\;\frac{c}{\left(-b\right) - \sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -0.5\\ \end{array}\]

Reproduce

herbie shell --seed 2020289 
(FPCore (a b c)
  :name "Cubic critical"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))