Average Error: 34.5 → 7.1
Time: 12.3s
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 -4.632381428632677 \cdot 10^{+153}:\\ \;\;\;\;\frac{\left(-b\right) - b}{3 \cdot a}\\ \mathbf{elif}\;b \leq -2.2723855696978872 \cdot 10^{-219}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}\\ \mathbf{elif}\;b \leq 7.524306741962282 \cdot 10^{+62}:\\ \;\;\;\;\frac{-1}{\frac{b + \sqrt{b \cdot b - 3 \cdot \left(a \cdot c\right)}}{c}}\\ \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 \leq -4.632381428632677 \cdot 10^{+153}:\\
\;\;\;\;\frac{\left(-b\right) - b}{3 \cdot a}\\

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

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

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

\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 -4.632381428632677e+153)
   (/ (- (- b) b) (* 3.0 a))
   (if (<= b -2.2723855696978872e-219)
     (/ (- (sqrt (- (* b b) (* (* 3.0 a) c))) b) (* 3.0 a))
     (if (<= b 7.524306741962282e+62)
       (/ -1.0 (/ (+ b (sqrt (- (* b b) (* 3.0 (* a c))))) c))
       (* -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 (b <= -4.632381428632677e+153) {
		tmp = (-b - b) / (3.0 * a);
	} else if (b <= -2.2723855696978872e-219) {
		tmp = (sqrt((b * b) - ((3.0 * a) * c)) - b) / (3.0 * a);
	} else if (b <= 7.524306741962282e+62) {
		tmp = -1.0 / ((b + sqrt((b * b) - (3.0 * (a * c)))) / c);
	} else {
		tmp = -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 4 regimes
  2. if b < -4.632381428632677e153

    1. Initial program 63.9

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Simplified63.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 2.7

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

    if -4.632381428632677e153 < b < -2.2723855696978872e-219

    1. Initial program 7.8

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

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

    if -2.2723855696978872e-219 < b < 7.5243067419622818e62

    1. Initial program 27.9

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Simplified27.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_244028.0

      \[\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. Simplified17.6

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\left(b + \sqrt{b \cdot b - 3 \cdot \left(a \cdot c\right)}\right) \cdot \frac{-1}{c}}}\]
    10. Using strategy rm
    11. Applied frac-2neg_binary64_247611.2

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

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

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

    if 7.5243067419622818e62 < b

    1. Initial program 57.7

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

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

      \[\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. Simplified28.8

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -4.632381428632677 \cdot 10^{+153}:\\ \;\;\;\;\frac{\left(-b\right) - b}{3 \cdot a}\\ \mathbf{elif}\;b \leq -2.2723855696978872 \cdot 10^{-219}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}\\ \mathbf{elif}\;b \leq 7.524306741962282 \cdot 10^{+62}:\\ \;\;\;\;\frac{-1}{\frac{b + \sqrt{b \cdot b - 3 \cdot \left(a \cdot c\right)}}{c}}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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