Average Error: 33.8 → 6.7
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 -2.730148424505267 \cdot 10^{+150}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} + \frac{b}{a} \cdot -0.6666666666666666\\ \mathbf{elif}\;b \leq -3.352581098106061 \cdot 10^{-289}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3}\\ \mathbf{elif}\;b \leq 7.484148894778323 \cdot 10^{+146}:\\ \;\;\;\;\frac{\frac{c}{b + \sqrt{b \cdot b - 3 \cdot \left(c \cdot a\right)}}}{-1}\\ \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 -2.730148424505267 \cdot 10^{+150}:\\
\;\;\;\;0.5 \cdot \frac{c}{b} + \frac{b}{a} \cdot -0.6666666666666666\\

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

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

\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 -2.730148424505267e+150)
   (+ (* 0.5 (/ c b)) (* (/ b a) -0.6666666666666666))
   (if (<= b -3.352581098106061e-289)
     (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0))
     (if (<= b 7.484148894778323e+146)
       (/ (/ c (+ b (sqrt (- (* b b) (* 3.0 (* c a)))))) -1.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 <= -2.730148424505267e+150) {
		tmp = (0.5 * (c / b)) + ((b / a) * -0.6666666666666666);
	} else if (b <= -3.352581098106061e-289) {
		tmp = (sqrt((b * b) - (c * (a * 3.0))) - b) / (a * 3.0);
	} else if (b <= 7.484148894778323e+146) {
		tmp = (c / (b + sqrt((b * b) - (3.0 * (c * a))))) / -1.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 < -2.73014842450526683e150

    1. Initial program 62.1

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

      \[\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} - 0.6666666666666666 \cdot \frac{b}{a}}\]
    4. Simplified2.6

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

    if -2.73014842450526683e150 < b < -3.3525810981060608e-289

    1. Initial program 8.8

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Simplified8.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 *-un-lft-identity_binary648.8

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

    if -3.3525810981060608e-289 < b < 7.48414889477832338e146

    1. Initial program 33.1

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

      \[\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*_binary6433.1

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

      \[\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--_binary6433.1

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

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

      \[\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 clear-num_binary6416.0

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

      \[\leadsto \frac{1}{\color{blue}{3 \cdot \left(1 \cdot \frac{b + \sqrt{b \cdot b - 3 \cdot \left(a \cdot c\right)}}{c \cdot -3}\right)}}\]
    13. Using strategy rm
    14. Applied div-inv_binary649.1

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

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

    if 7.48414889477832338e146 < b

    1. Initial program 63.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2.730148424505267 \cdot 10^{+150}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} + \frac{b}{a} \cdot -0.6666666666666666\\ \mathbf{elif}\;b \leq -3.352581098106061 \cdot 10^{-289}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3}\\ \mathbf{elif}\;b \leq 7.484148894778323 \cdot 10^{+146}:\\ \;\;\;\;\frac{\frac{c}{b + \sqrt{b \cdot b - 3 \cdot \left(c \cdot a\right)}}}{-1}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -0.5\\ \end{array}\]

Reproduce

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