Average Error: 34.1 → 9.0
Time: 7.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 -6.350987509722503 \cdot 10^{+107}:\\ \;\;\;\;\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}} \cdot \left(\frac{\frac{b}{a}}{\sqrt[3]{3}} \cdot -2\right)\\ \mathbf{elif}\;b \leq 4.2393047293392074 \cdot 10^{-139}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}\\ \mathbf{elif}\;b \leq 1.1308364602898941 \cdot 10^{+67}:\\ \;\;\;\;\frac{\frac{a \cdot \left(c \cdot -3\right)}{b + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}{3 \cdot 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 -6.350987509722503 \cdot 10^{+107}:\\
\;\;\;\;\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}} \cdot \left(\frac{\frac{b}{a}}{\sqrt[3]{3}} \cdot -2\right)\\

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

\mathbf{elif}\;b \leq 1.1308364602898941 \cdot 10^{+67}:\\
\;\;\;\;\frac{\frac{a \cdot \left(c \cdot -3\right)}{b + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}{3 \cdot 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 -6.350987509722503e+107)
   (* (/ 1.0 (* (cbrt 3.0) (cbrt 3.0))) (* (/ (/ b a) (cbrt 3.0)) -2.0))
   (if (<= b 4.2393047293392074e-139)
     (/ (- (sqrt (- (* b b) (* (* 3.0 a) c))) b) (* 3.0 a))
     (if (<= b 1.1308364602898941e+67)
       (/
        (/ (* a (* c -3.0)) (+ b (sqrt (- (* b b) (* (* 3.0 a) c)))))
        (* 3.0 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 <= -6.350987509722503e+107) {
		tmp = (1.0 / (cbrt(3.0) * cbrt(3.0))) * (((b / a) / cbrt(3.0)) * -2.0);
	} else if (b <= 4.2393047293392074e-139) {
		tmp = (sqrt((b * b) - ((3.0 * a) * c)) - b) / (3.0 * a);
	} else if (b <= 1.1308364602898941e+67) {
		tmp = ((a * (c * -3.0)) / (b + sqrt((b * b) - ((3.0 * a) * c)))) / (3.0 * 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 < -6.3509875097225029e107

    1. Initial program 50.5

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

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

      \[\leadsto \frac{1}{\color{blue}{\frac{3}{\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{a}}}}\]
    6. Using strategy rm
    7. Applied *-un-lft-identity_binary6450.6

      \[\leadsto \frac{1}{\frac{3}{\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{\color{blue}{1 \cdot a}}}}\]
    8. Applied *-un-lft-identity_binary6450.6

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

      \[\leadsto \frac{1}{\frac{3}{\color{blue}{\frac{1}{1} \cdot \frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{a}}}}\]
    10. Applied add-cube-cbrt_binary6450.6

      \[\leadsto \frac{1}{\frac{\color{blue}{\left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right) \cdot \sqrt[3]{3}}}{\frac{1}{1} \cdot \frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{a}}}\]
    11. Applied times-frac_binary6450.6

      \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt[3]{3} \cdot \sqrt[3]{3}}{\frac{1}{1}} \cdot \frac{\sqrt[3]{3}}{\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{a}}}}\]
    12. Applied add-sqr-sqrt_binary6450.6

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

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

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

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

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

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

    if -6.3509875097225029e107 < b < 4.2393047293392074e-139

    1. Initial program 11.4

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

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

    if 4.2393047293392074e-139 < b < 1.13083646028989413e67

    1. Initial program 37.8

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

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

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

      \[\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}\]

    if 1.13083646028989413e67 < b

    1. Initial program 57.8

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -6.350987509722503 \cdot 10^{+107}:\\ \;\;\;\;\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}} \cdot \left(\frac{\frac{b}{a}}{\sqrt[3]{3}} \cdot -2\right)\\ \mathbf{elif}\;b \leq 4.2393047293392074 \cdot 10^{-139}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}\\ \mathbf{elif}\;b \leq 1.1308364602898941 \cdot 10^{+67}:\\ \;\;\;\;\frac{\frac{a \cdot \left(c \cdot -3\right)}{b + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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