Average Error: 34.1 → 14.6
Time: 7.8s
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.68191977281259 \cdot 10^{+58}:\\ \;\;\;\;\frac{\frac{\left|b \cdot -2\right|}{3}}{a}\\ \mathbf{elif}\;b \leq 7.630379190543333 \cdot 10^{-98}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1.5 \cdot \frac{a \cdot c}{b}}{3 \cdot a}\\ \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.68191977281259 \cdot 10^{+58}:\\
\;\;\;\;\frac{\frac{\left|b \cdot -2\right|}{3}}{a}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{-1.5 \cdot \frac{a \cdot c}{b}}{3 \cdot a}\\


\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.68191977281259e+58)
   (/ (/ (fabs (* b -2.0)) 3.0) a)
   (if (<= b 7.630379190543333e-98)
     (/ (- (sqrt (- (* b b) (* (* 3.0 a) c))) b) (* 3.0 a))
     (/ (* -1.5 (/ (* a c) b)) (* 3.0 a)))))
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.68191977281259e+58) {
		tmp = (fabs(b * -2.0) / 3.0) / a;
	} else if (b <= 7.630379190543333e-98) {
		tmp = (sqrt((b * b) - ((3.0 * a) * c)) - b) / (3.0 * a);
	} else {
		tmp = (-1.5 * ((a * c) / b)) / (3.0 * a);
	}
	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.68191977281259011e58

    1. Initial program 40.1

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Applied add-sqr-sqrt_binary6440.2

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

      \[\leadsto \frac{\color{blue}{\sqrt{\mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -3\right)}, b\right) - b}} \cdot \sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}{3 \cdot a} \]
    4. Simplified36.5

      \[\leadsto \frac{\sqrt{\mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -3\right)}, b\right) - b} \cdot \color{blue}{\sqrt{\mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -3\right)}, b\right) - b}}}{3 \cdot a} \]
    5. Applied add-sqr-sqrt_binary6436.5

      \[\leadsto \frac{\sqrt{\mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -3\right)}, b\right) - b} \cdot \sqrt{\color{blue}{\sqrt{\mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -3\right)}, b\right) - b} \cdot \sqrt{\mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -3\right)}, b\right) - b}}}}{3 \cdot a} \]
    6. Applied rem-sqrt-square_binary6436.5

      \[\leadsto \frac{\sqrt{\mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -3\right)}, b\right) - b} \cdot \color{blue}{\left|\sqrt{\mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -3\right)}, b\right) - b}\right|}}{3 \cdot a} \]
    7. Applied add-sqr-sqrt_binary6436.5

      \[\leadsto \frac{\sqrt{\color{blue}{\sqrt{\mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -3\right)}, b\right) - b} \cdot \sqrt{\mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -3\right)}, b\right) - b}}} \cdot \left|\sqrt{\mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -3\right)}, b\right) - b}\right|}{3 \cdot a} \]
    8. Applied rem-sqrt-square_binary6436.5

      \[\leadsto \frac{\color{blue}{\left|\sqrt{\mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -3\right)}, b\right) - b}\right|} \cdot \left|\sqrt{\mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -3\right)}, b\right) - b}\right|}{3 \cdot a} \]
    9. Applied mul-fabs_binary6436.5

      \[\leadsto \frac{\color{blue}{\left|\sqrt{\mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -3\right)}, b\right) - b} \cdot \sqrt{\mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -3\right)}, b\right) - b}\right|}}{3 \cdot a} \]
    10. Simplified36.3

      \[\leadsto \frac{\left|\color{blue}{\mathsf{hypot}\left(\sqrt{-3 \cdot \left(c \cdot a\right)}, b\right) - b}\right|}{3 \cdot a} \]
    11. Applied associate-/r*_binary6436.3

      \[\leadsto \color{blue}{\frac{\frac{\left|\mathsf{hypot}\left(\sqrt{-3 \cdot \left(c \cdot a\right)}, b\right) - b\right|}{3}}{a}} \]
    12. Taylor expanded in b around -inf 5.5

      \[\leadsto \frac{\frac{\left|\color{blue}{-2 \cdot b}\right|}{3}}{a} \]
    13. Simplified5.5

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

    if -1.68191977281259011e58 < b < 7.6303791905433328e-98

    1. Initial program 12.4

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Applied *-un-lft-identity_binary6412.4

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

    if 7.6303791905433328e-98 < b

    1. Initial program 51.8

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Taylor expanded in b around inf 20.8

      \[\leadsto \frac{\color{blue}{-1.5 \cdot \frac{c \cdot a}{b}}}{3 \cdot a} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification14.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.68191977281259 \cdot 10^{+58}:\\ \;\;\;\;\frac{\frac{\left|b \cdot -2\right|}{3}}{a}\\ \mathbf{elif}\;b \leq 7.630379190543333 \cdot 10^{-98}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1.5 \cdot \frac{a \cdot c}{b}}{3 \cdot a}\\ \end{array} \]

Reproduce

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