Average Error: 33.9 → 6.5
Time: 12.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 -3.6719904792053715 \cdot 10^{+126}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} + \frac{b}{a} \cdot -0.6666666666666666\\ \mathbf{elif}\;b \leq -1.0659637489022944 \cdot 10^{-294}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - 3 \cdot \left(c \cdot a\right)} - b}{3}}{a}\\ \mathbf{elif}\;b \leq 2.710249643306574 \cdot 10^{+91}:\\ \;\;\;\;\frac{-c}{b + \sqrt{b \cdot b - 3 \cdot \left(c \cdot a\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 -3.6719904792053715 \cdot 10^{+126}:\\
\;\;\;\;0.5 \cdot \frac{c}{b} + \frac{b}{a} \cdot -0.6666666666666666\\

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

\mathbf{elif}\;b \leq 2.710249643306574 \cdot 10^{+91}:\\
\;\;\;\;\frac{-c}{b + \sqrt{b \cdot b - 3 \cdot \left(c \cdot a\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 -3.6719904792053715e+126)
   (+ (* 0.5 (/ c b)) (* (/ b a) -0.6666666666666666))
   (if (<= b -1.0659637489022944e-294)
     (/ (/ (- (sqrt (- (* b b) (* 3.0 (* c a)))) b) 3.0) a)
     (if (<= b 2.710249643306574e+91)
       (/ (- c) (+ b (sqrt (- (* b b) (* 3.0 (* c a))))))
       (* (/ 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 <= -3.6719904792053715e+126) {
		tmp = (0.5 * (c / b)) + ((b / a) * -0.6666666666666666);
	} else if (b <= -1.0659637489022944e-294) {
		tmp = ((sqrt((b * b) - (3.0 * (c * a))) - b) / 3.0) / a;
	} else if (b <= 2.710249643306574e+91) {
		tmp = -c / (b + sqrt((b * b) - (3.0 * (c * a))));
	} 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 < -3.6719904792053715e126

    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 3.8

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

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

    if -3.6719904792053715e126 < b < -1.06596374890229441e-294

    1. Initial program 8.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Simplified8.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 associate-/r*_binary64_27508.7

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

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

    if -1.06596374890229441e-294 < b < 2.710249643306574e91

    1. Initial program 31.5

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(a \cdot \frac{c \cdot -3}{b + \sqrt{b \cdot b - 3 \cdot \left(a \cdot c\right)}}\right) \cdot \color{blue}{\frac{0.3333333333333333}{a}}\]
    16. Using strategy rm
    17. Applied associate-*r/_binary64_274817.0

      \[\leadsto \color{blue}{\frac{a \cdot \left(c \cdot -3\right)}{b + \sqrt{b \cdot b - 3 \cdot \left(a \cdot c\right)}}} \cdot \frac{0.3333333333333333}{a}\]
    18. Applied associate-*l/_binary64_274916.3

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

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

    if 2.710249643306574e91 < b

    1. Initial program 59.0

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -3.6719904792053715 \cdot 10^{+126}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} + \frac{b}{a} \cdot -0.6666666666666666\\ \mathbf{elif}\;b \leq -1.0659637489022944 \cdot 10^{-294}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - 3 \cdot \left(c \cdot a\right)} - b}{3}}{a}\\ \mathbf{elif}\;b \leq 2.710249643306574 \cdot 10^{+91}:\\ \;\;\;\;\frac{-c}{b + \sqrt{b \cdot b - 3 \cdot \left(c \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -0.5\\ \end{array}\]

Reproduce

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