Average Error: 34.2 → 13.7
Time: 14.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 -2.412892212611534 \cdot 10^{+148}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{elif}\;b \leq 1.4510006837108914 \cdot 10^{-139}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}\\ \mathbf{elif}\;b \leq 7.672052807609023 \cdot 10^{+49}:\\ \;\;\;\;\frac{\frac{3 \cdot \left(a \cdot c\right)}{\left(-b\right) - \mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -3\right)}, b\right)}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1.5 \cdot \frac{a \cdot c}{b}}{3 \cdot a}\\ \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 -2.412892212611534 \cdot 10^{+148}:\\
\;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\

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

\mathbf{elif}\;b \leq 7.672052807609023 \cdot 10^{+49}:\\
\;\;\;\;\frac{\frac{3 \cdot \left(a \cdot c\right)}{\left(-b\right) - \mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -3\right)}, b\right)}}{3 \cdot a}\\

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


\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 -2.412892212611534e+148)
   (/ (* b -2.0) (* 3.0 a))
   (if (<= b 1.4510006837108914e-139)
     (/ (- (sqrt (- (* b b) (* (* 3.0 a) c))) b) (* 3.0 a))
     (if (<= b 7.672052807609023e+49)
       (/
        (/ (* 3.0 (* a c)) (- (- b) (hypot (sqrt (* c (* a -3.0))) b)))
        (* 3.0 a))
       (/ (* -1.5 (/ (* a c) b)) (* 3.0 a))))))
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 <= -2.412892212611534e+148) {
		tmp = (b * -2.0) / (3.0 * a);
	} else if (b <= 1.4510006837108914e-139) {
		tmp = (sqrt((b * b) - ((3.0 * a) * c)) - b) / (3.0 * a);
	} else if (b <= 7.672052807609023e+49) {
		tmp = ((3.0 * (a * c)) / (-b - hypot(sqrt(c * (a * -3.0)), b))) / (3.0 * a);
	} else {
		tmp = (-1.5 * ((a * c) / b)) / (3.0 * a);
	}
	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 < -2.4128922126115341e148

    1. Initial program 62.1

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

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

    if -2.4128922126115341e148 < b < 1.4510006837108914e-139

    1. Initial program 10.7

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

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

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

    if 1.4510006837108914e-139 < b < 7.67205280760902282e49

    1. Initial program 37.9

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

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

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

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

    if 7.67205280760902282e49 < b

    1. Initial program 57.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2.412892212611534 \cdot 10^{+148}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{elif}\;b \leq 1.4510006837108914 \cdot 10^{-139}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}\\ \mathbf{elif}\;b \leq 7.672052807609023 \cdot 10^{+49}:\\ \;\;\;\;\frac{\frac{3 \cdot \left(a \cdot c\right)}{\left(-b\right) - \mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -3\right)}, b\right)}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1.5 \cdot \frac{a \cdot c}{b}}{3 \cdot a}\\ \end{array} \]

Reproduce

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