Average Error: 34.0 → 6.5
Time: 8.0s
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.6639797539343423 \cdot 10^{+153}:\\ \;\;\;\;\frac{\frac{b \cdot -2}{3}}{a}\\ \mathbf{elif}\;b \leq -9.85258107206253 \cdot 10^{-259}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}\\ \mathbf{elif}\;b \leq 8.68809347721397 \cdot 10^{+54}:\\ \;\;\;\;\frac{-c}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}\\ \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 -1.6639797539343423 \cdot 10^{+153}:\\
\;\;\;\;\frac{\frac{b \cdot -2}{3}}{a}\\

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

\mathbf{elif}\;b \leq 8.68809347721397 \cdot 10^{+54}:\\
\;\;\;\;\frac{-c}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}\\

\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 -1.6639797539343423e+153)
   (/ (/ (* b -2.0) 3.0) a)
   (if (<= b -9.85258107206253e-259)
     (/ (- (sqrt (- (* b b) (* (* 3.0 a) c))) b) (* 3.0 a))
     (if (<= b 8.68809347721397e+54)
       (/ (- c) (+ b (sqrt (fma a (* c -3.0) (* b b)))))
       (* -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 <= -1.6639797539343423e+153) {
		tmp = ((b * -2.0) / 3.0) / a;
	} else if (b <= -9.85258107206253e-259) {
		tmp = (sqrt((b * b) - ((3.0 * a) * c)) - b) / (3.0 * a);
	} else if (b <= 8.68809347721397e+54) {
		tmp = -c / (b + sqrt(fma(a, (c * -3.0), (b * b))));
	} else {
		tmp = -0.5 * (c / b);
	}
	return tmp;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 4 regimes
  2. if b < -1.66397975393434225e153

    1. Initial program 63.6

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Applied associate-/r*_binary6463.6

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

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

    if -1.66397975393434225e153 < b < -9.85258107206253017e-259

    1. Initial program 7.9

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

    if -9.85258107206253017e-259 < b < 8.688093477213969e54

    1. Initial program 28.4

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

      \[\leadsto \color{blue}{\left(\sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)} - b\right) \cdot \frac{0.3333333333333333}{a}} \]
    3. Applied flip--_binary6428.6

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)} \cdot \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)} - b \cdot b}{\sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)} + b}} \cdot \frac{0.3333333333333333}{a} \]
    4. Applied associate-*l/_binary6428.6

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

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

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

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

    if 8.688093477213969e54 < b

    1. Initial program 57.2

      \[\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 3.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.6639797539343423 \cdot 10^{+153}:\\ \;\;\;\;\frac{\frac{b \cdot -2}{3}}{a}\\ \mathbf{elif}\;b \leq -9.85258107206253 \cdot 10^{-259}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}\\ \mathbf{elif}\;b \leq 8.68809347721397 \cdot 10^{+54}:\\ \;\;\;\;\frac{-c}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]

Reproduce

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