Average Error: 34.2 → 6.8
Time: 5.6s
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 -6.649876856688698 \cdot 10^{+87}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} - 0.6666666666666666 \cdot \frac{b}{a}\\ \mathbf{elif}\;b \leq -1.0972294854103117 \cdot 10^{-255}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{3}}{a}\\ \mathbf{elif}\;b \leq 1.1429453515296668 \cdot 10^{+130}:\\ \;\;\;\;\frac{-c}{b + \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 -6.649876856688698 \cdot 10^{+87}:\\
\;\;\;\;0.5 \cdot \frac{c}{b} - 0.6666666666666666 \cdot \frac{b}{a}\\

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

\mathbf{elif}\;b \leq 1.1429453515296668 \cdot 10^{+130}:\\
\;\;\;\;\frac{-c}{b + \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 -6.649876856688698e+87)
   (- (* 0.5 (/ c b)) (* 0.6666666666666666 (/ b a)))
   (if (<= b -1.0972294854103117e-255)
     (/ (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) 3.0) a)
     (if (<= b 1.1429453515296668e+130)
       (/ (- 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 <= -6.649876856688698e+87) {
		tmp = (0.5 * (c / b)) - (0.6666666666666666 * (b / a));
	} else if (b <= -1.0972294854103117e-255) {
		tmp = ((sqrt((b * b) - (c * (a * 3.0))) - b) / 3.0) / a;
	} else if (b <= 1.1429453515296668e+130) {
		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 < -6.64987685668869819e87

    1. Initial program 43.6

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

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

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

    if -6.64987685668869819e87 < b < -1.09722948541031171e-255

    1. Initial program 9.0

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

      \[\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 associate-/r*_binary649.0

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

    if -1.09722948541031171e-255 < b < 1.1429453515296668e130

    1. Initial program 32.8

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

      \[\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--_binary6432.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. Simplified15.7

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

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

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

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

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

      \[\leadsto 0.3333333333333333 \cdot \color{blue}{\left(1 \cdot \frac{c \cdot -3}{b + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}\right)}\]
    12. Using strategy rm
    13. Applied associate-*r/_binary649.1

      \[\leadsto 0.3333333333333333 \cdot \color{blue}{\frac{1 \cdot \left(c \cdot -3\right)}{b + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}\]
    14. Applied associate-*r/_binary649.0

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

      \[\leadsto \frac{\color{blue}{-c}}{b + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}\]
    16. Using strategy rm
    17. Applied sub-neg_binary648.8

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

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

    if 1.1429453515296668e130 < b

    1. Initial program 61.9

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -6.649876856688698 \cdot 10^{+87}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} - 0.6666666666666666 \cdot \frac{b}{a}\\ \mathbf{elif}\;b \leq -1.0972294854103117 \cdot 10^{-255}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{3}}{a}\\ \mathbf{elif}\;b \leq 1.1429453515296668 \cdot 10^{+130}:\\ \;\;\;\;\frac{-c}{b + \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 2020253 
(FPCore (a b c)
  :name "Cubic critical"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))