Average Error: 34.1 → 18.5
Time: 10.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 -1.346889012582839 \cdot 10^{+154}:\\ \;\;\;\;\frac{\frac{\sqrt{0} - b}{3}}{a}\\ \mathbf{elif}\;b \leq -2.7798465605045782 \cdot 10^{-285}:\\ \;\;\;\;\frac{1}{\frac{3}{\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{a}}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}\\ \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.346889012582839 \cdot 10^{+154}:\\
\;\;\;\;\frac{\frac{\sqrt{0} - b}{3}}{a}\\

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

\mathbf{else}:\\
\;\;\;\;-\frac{c}{b + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}\\

\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.346889012582839e+154)
   (/ (/ (- (sqrt 0.0) b) 3.0) a)
   (if (<= b -2.7798465605045782e-285)
     (/ 1.0 (/ 3.0 (/ (- (sqrt (- (* b b) (* (* 3.0 a) c))) b) a)))
     (- (/ c (+ b (sqrt (- (* b b) (* (* 3.0 a) c)))))))))
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.346889012582839e+154) {
		tmp = ((sqrt(0.0) - b) / 3.0) / a;
	} else if (b <= -2.7798465605045782e-285) {
		tmp = 1.0 / (3.0 / ((sqrt((b * b) - ((3.0 * a) * c)) - b) / a));
	} else {
		tmp = -(c / (b + sqrt((b * b) - ((3.0 * a) * c))));
	}
	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 3 regimes
  2. if b < -1.34688901258283899e154

    1. Initial program 64.0

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

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

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

      \[\leadsto \frac{\frac{\color{blue}{\sqrt{0}} - b}{3}}{a}\]

    if -1.34688901258283899e154 < b < -2.77984656050457822e-285

    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 clear-num_binary648.6

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

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

    if -2.77984656050457822e-285 < b

    1. Initial program 43.5

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

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

      \[\leadsto \frac{\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}}{a}\]
    7. Simplified23.3

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

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

      \[\leadsto \frac{\frac{\frac{a \cdot \left(c \cdot -3\right)}{b + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}{3}}{\color{blue}{1 \cdot a}}\]
    11. Applied associate-/r*_binary6423.3

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

      \[\leadsto \frac{\color{blue}{\left(-\frac{c}{b + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}\right) \cdot a}}{a}\]
    13. Using strategy rm
    14. Applied distribute-lft-neg-out_binary6421.8

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

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

      \[\leadsto -\color{blue}{\frac{c}{b + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification18.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.346889012582839 \cdot 10^{+154}:\\ \;\;\;\;\frac{\frac{\sqrt{0} - b}{3}}{a}\\ \mathbf{elif}\;b \leq -2.7798465605045782 \cdot 10^{-285}:\\ \;\;\;\;\frac{1}{\frac{3}{\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{a}}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}\\ \end{array}\]

Reproduce

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