Average Error: 34.1 → 8.8
Time: 14.4s
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.657670422663459 \cdot 10^{+37}:\\ \;\;\;\;\frac{\frac{b \cdot -2}{3}}{a}\\ \mathbf{elif}\;b \leq 2.053250763506355 \cdot 10^{-126}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} - \frac{b}{3 \cdot a}\\ \mathbf{elif}\;b \leq 5.632271499779473 \cdot 10^{+36}:\\ \;\;\;\;\frac{\frac{\frac{a}{\sqrt[3]{b + \sqrt{b \cdot b - 3 \cdot \left(a \cdot c\right)}} \cdot \sqrt[3]{b + \sqrt{b \cdot b - 3 \cdot \left(a \cdot c\right)}}}}{\sqrt[3]{3} \cdot \sqrt[3]{3}}}{\sqrt[3]{a} \cdot \sqrt[3]{a}} \cdot \frac{\frac{\frac{c \cdot -3}{\sqrt[3]{b + \sqrt{b \cdot b - 3 \cdot \left(a \cdot c\right)}}}}{\sqrt[3]{3}}}{\sqrt[3]{a}}\\ \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 -3.657670422663459 \cdot 10^{+37}:\\
\;\;\;\;\frac{\frac{b \cdot -2}{3}}{a}\\

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

\mathbf{elif}\;b \leq 5.632271499779473 \cdot 10^{+36}:\\
\;\;\;\;\frac{\frac{\frac{a}{\sqrt[3]{b + \sqrt{b \cdot b - 3 \cdot \left(a \cdot c\right)}} \cdot \sqrt[3]{b + \sqrt{b \cdot b - 3 \cdot \left(a \cdot c\right)}}}}{\sqrt[3]{3} \cdot \sqrt[3]{3}}}{\sqrt[3]{a} \cdot \sqrt[3]{a}} \cdot \frac{\frac{\frac{c \cdot -3}{\sqrt[3]{b + \sqrt{b \cdot b - 3 \cdot \left(a \cdot c\right)}}}}{\sqrt[3]{3}}}{\sqrt[3]{a}}\\

\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 -3.657670422663459e+37)
   (/ (/ (* b -2.0) 3.0) a)
   (if (<= b 2.053250763506355e-126)
     (- (/ (sqrt (- (* b b) (* (* 3.0 a) c))) (* 3.0 a)) (/ b (* 3.0 a)))
     (if (<= b 5.632271499779473e+36)
       (*
        (/
         (/
          (/
           a
           (*
            (cbrt (+ b (sqrt (- (* b b) (* 3.0 (* a c))))))
            (cbrt (+ b (sqrt (- (* b b) (* 3.0 (* a c))))))))
          (* (cbrt 3.0) (cbrt 3.0)))
         (* (cbrt a) (cbrt a)))
        (/
         (/
          (/ (* c -3.0) (cbrt (+ b (sqrt (- (* b b) (* 3.0 (* a c)))))))
          (cbrt 3.0))
         (cbrt a)))
       (* -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 <= -3.657670422663459e+37) {
		tmp = ((b * -2.0) / 3.0) / a;
	} else if (b <= 2.053250763506355e-126) {
		tmp = (sqrt((b * b) - ((3.0 * a) * c)) / (3.0 * a)) - (b / (3.0 * a));
	} else if (b <= 5.632271499779473e+36) {
		tmp = (((a / (cbrt(b + sqrt((b * b) - (3.0 * (a * c)))) * cbrt(b + sqrt((b * b) - (3.0 * (a * c)))))) / (cbrt(3.0) * cbrt(3.0))) / (cbrt(a) * cbrt(a))) * ((((c * -3.0) / cbrt(b + sqrt((b * b) - (3.0 * (a * c))))) / cbrt(3.0)) / cbrt(a));
	} 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 < -3.6576704226634589e37

    1. Initial program 35.9

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

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

      \[\leadsto \frac{\color{blue}{\frac{\sqrt{b \cdot b - 3 \cdot \left(a \cdot c\right)} - b}{3}}}{a}\]
    6. Taylor expanded around -inf 6.0

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

    if -3.6576704226634589e37 < b < 2.0532507635063549e-126

    1. Initial program 12.9

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

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

    if 2.0532507635063549e-126 < b < 5.63227149977947251e36

    1. Initial program 38.9

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

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

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

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

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

      \[\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 add-cube-cbrt_binary64_454618.7

      \[\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}{\left(\sqrt[3]{a} \cdot \sqrt[3]{a}\right) \cdot \sqrt[3]{a}}}\]
    12. Applied add-cube-cbrt_binary64_454618.7

      \[\leadsto \frac{\frac{\frac{a \cdot \left(c \cdot -3\right)}{b + \sqrt{b \cdot b - 3 \cdot \left(a \cdot c\right)}}}{\color{blue}{\left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right) \cdot \sqrt[3]{3}}}}{\left(\sqrt[3]{a} \cdot \sqrt[3]{a}\right) \cdot \sqrt[3]{a}}\]
    13. Applied add-cube-cbrt_binary64_454618.9

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

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

      \[\leadsto \frac{\color{blue}{\frac{\frac{a}{\sqrt[3]{b + \sqrt{b \cdot b - 3 \cdot \left(a \cdot c\right)}} \cdot \sqrt[3]{b + \sqrt{b \cdot b - 3 \cdot \left(a \cdot c\right)}}}}{\sqrt[3]{3} \cdot \sqrt[3]{3}} \cdot \frac{\frac{c \cdot -3}{\sqrt[3]{b + \sqrt{b \cdot b - 3 \cdot \left(a \cdot c\right)}}}}{\sqrt[3]{3}}}}{\left(\sqrt[3]{a} \cdot \sqrt[3]{a}\right) \cdot \sqrt[3]{a}}\]
    16. Applied times-frac_binary64_451711.2

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

    if 5.63227149977947251e36 < b

    1. Initial program 56.6

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -3.657670422663459 \cdot 10^{+37}:\\ \;\;\;\;\frac{\frac{b \cdot -2}{3}}{a}\\ \mathbf{elif}\;b \leq 2.053250763506355 \cdot 10^{-126}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} - \frac{b}{3 \cdot a}\\ \mathbf{elif}\;b \leq 5.632271499779473 \cdot 10^{+36}:\\ \;\;\;\;\frac{\frac{\frac{a}{\sqrt[3]{b + \sqrt{b \cdot b - 3 \cdot \left(a \cdot c\right)}} \cdot \sqrt[3]{b + \sqrt{b \cdot b - 3 \cdot \left(a \cdot c\right)}}}}{\sqrt[3]{3} \cdot \sqrt[3]{3}}}{\sqrt[3]{a} \cdot \sqrt[3]{a}} \cdot \frac{\frac{\frac{c \cdot -3}{\sqrt[3]{b + \sqrt{b \cdot b - 3 \cdot \left(a \cdot c\right)}}}}{\sqrt[3]{3}}}{\sqrt[3]{a}}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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