Average Error: 34.2 → 8.7
Time: 6.7s
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 -1.8784026798326835 \cdot 10^{+149}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} - 0.6666666666666666 \cdot \frac{b}{a}\\ \mathbf{elif}\;b \leq 3.768751181218888 \cdot 10^{-301}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{3}}{a}\\ \mathbf{elif}\;b \leq 8.627093492358085 \cdot 10^{-16}:\\ \;\;\;\;\frac{a \cdot \frac{c \cdot -3}{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)}}}{a \cdot 3}\\ \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 -1.8784026798326835 \cdot 10^{+149}:\\
\;\;\;\;0.5 \cdot \frac{c}{b} - 0.6666666666666666 \cdot \frac{b}{a}\\

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

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

\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 -1.8784026798326835e+149)
   (- (* 0.5 (/ c b)) (* 0.6666666666666666 (/ b a)))
   (if (<= b 3.768751181218888e-301)
     (/ (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) 3.0) a)
     (if (<= b 8.627093492358085e-16)
       (/
        (* a (/ (* c -3.0) (+ b (sqrt (- (* b b) (* c (* a 3.0)))))))
        (* a 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 <= -1.8784026798326835e+149) {
		tmp = (0.5 * (c / b)) - (0.6666666666666666 * (b / a));
	} else if (b <= 3.768751181218888e-301) {
		tmp = ((sqrt((b * b) - (c * (a * 3.0))) - b) / 3.0) / a;
	} else if (b <= 8.627093492358085e-16) {
		tmp = (a * ((c * -3.0) / (b + sqrt((b * b) - (c * (a * 3.0)))))) / (a * 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 < -1.8784026798326835e149

    1. Initial program 62.2

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

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

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

    if -1.8784026798326835e149 < b < 3.7687511812188879e-301

    1. Initial program 8.5

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

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

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

    if 3.7687511812188879e-301 < b < 8.62709349235808539e-16

    1. Initial program 26.7

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

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

      \[\leadsto \frac{\frac{a \cdot \left(-3 \cdot c\right)}{\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_binary64_176219.4

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

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

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

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

    if 8.62709349235808539e-16 < b

    1. Initial program 54.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.8784026798326835 \cdot 10^{+149}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} - 0.6666666666666666 \cdot \frac{b}{a}\\ \mathbf{elif}\;b \leq 3.768751181218888 \cdot 10^{-301}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{3}}{a}\\ \mathbf{elif}\;b \leq 8.627093492358085 \cdot 10^{-16}:\\ \;\;\;\;\frac{a \cdot \frac{c \cdot -3}{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)}}}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -0.5\\ \end{array}\]

Reproduce

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