Average Error: 33.9 → 9.8
Time: 21.3s
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 -5.915145320276507 \cdot 10^{+152}:\\ \;\;\;\;\frac{\frac{b \cdot -2}{3}}{a}\\ \mathbf{elif}\;b \leq 5.55660938268195 \cdot 10^{-68}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{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 -5.915145320276507 \cdot 10^{+152}:\\
\;\;\;\;\frac{\frac{b \cdot -2}{3}}{a}\\

\mathbf{elif}\;b \leq 5.55660938268195 \cdot 10^{-68}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{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 -5.915145320276507e+152)
   (/ (/ (* b -2.0) 3.0) a)
   (if (<= b 5.55660938268195e-68)
     (/ (- (sqrt (- (* b b) (* (* 3.0 a) c))) b) (* 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 <= -5.915145320276507e+152) {
		tmp = ((b * -2.0) / 3.0) / a;
	} else if (b <= 5.55660938268195e-68) {
		tmp = (sqrt((b * b) - ((3.0 * a) * c)) - b) / (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 3 regimes
  2. if b < -5.91514532027650661e152

    1. Initial program 63.1

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

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

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

      \[\leadsto \frac{\left(-b\right) + \sqrt{\mathsf{fma}\left(c \cdot a, -3, b \cdot b\right) + \color{blue}{0}}}{3 \cdot a} \]
    5. Applied associate-/r*_binary6463.1

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

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

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

    if -5.91514532027650661e152 < b < 5.5566093826819504e-68

    1. Initial program 12.7

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

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

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

    if 5.5566093826819504e-68 < b

    1. Initial program 53.4

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

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

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

      \[\leadsto \frac{\left(-b\right) + \sqrt{\mathsf{fma}\left(c \cdot a, -3, b \cdot b\right) + \color{blue}{0}}}{3 \cdot a} \]
    5. Taylor expanded in b around inf 8.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -5.915145320276507 \cdot 10^{+152}:\\ \;\;\;\;\frac{\frac{b \cdot -2}{3}}{a}\\ \mathbf{elif}\;b \leq 5.55660938268195 \cdot 10^{-68}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]

Reproduce

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