Average Error: 29.9 → 7.8
Time: 9.7s
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 -8.182845608862169 \cdot 10^{+150}:\\ \;\;\;\;\frac{\left(b \cdot -2\right) \cdot 0.3333333333333333}{a}\\ \mathbf{elif}\;b \leq 1.1498395275009536 \cdot 10^{-168}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)} - b}{a \cdot 3}\\ \mathbf{elif}\;b \leq 5.17555123963869 \cdot 10^{+45}:\\ \;\;\;\;\frac{\frac{0.3333333333333333 \cdot \mathsf{fma}\left(a, c \cdot -3, 0\right)}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}{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 -8.182845608862169 \cdot 10^{+150}:\\
\;\;\;\;\frac{\left(b \cdot -2\right) \cdot 0.3333333333333333}{a}\\

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

\mathbf{elif}\;b \leq 5.17555123963869 \cdot 10^{+45}:\\
\;\;\;\;\frac{\frac{0.3333333333333333 \cdot \mathsf{fma}\left(a, c \cdot -3, 0\right)}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}{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 -8.182845608862169e+150)
   (/ (* (* b -2.0) 0.3333333333333333) a)
   (if (<= b 1.1498395275009536e-168)
     (/ (- (sqrt (fma b b (* c (* a -3.0)))) b) (* a 3.0))
     (if (<= b 5.17555123963869e+45)
       (/
        (/
         (* 0.3333333333333333 (fma a (* c -3.0) 0.0))
         (+ b (sqrt (fma a (* c -3.0) (* b b)))))
        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 <= -8.182845608862169e+150) {
		tmp = ((b * -2.0) * 0.3333333333333333) / a;
	} else if (b <= 1.1498395275009536e-168) {
		tmp = (sqrt(fma(b, b, (c * (a * -3.0)))) - b) / (a * 3.0);
	} else if (b <= 5.17555123963869e+45) {
		tmp = ((0.3333333333333333 * fma(a, (c * -3.0), 0.0)) / (b + sqrt(fma(a, (c * -3.0), (b * b))))) / a;
	} 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 < -8.1828456088621686e150

    1. Initial program 36.6

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

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

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

    if -8.1828456088621686e150 < b < 1.14983952750095361e-168

    1. Initial program 9.1

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

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

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

    if 1.14983952750095361e-168 < b < 5.1755512396386903e45

    1. Initial program 35.1

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

      \[\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 associate-*r/_binary6435.2

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

      \[\leadsto \frac{\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 0.3333333333333333}{a} \]
    5. Applied associate-*l/_binary6435.5

      \[\leadsto \frac{\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 0.3333333333333333}{\sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)} + b}}}{a} \]
    6. Simplified17.1

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

    if 5.1755512396386903e45 < b

    1. Initial program 55.8

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -8.182845608862169 \cdot 10^{+150}:\\ \;\;\;\;\frac{\left(b \cdot -2\right) \cdot 0.3333333333333333}{a}\\ \mathbf{elif}\;b \leq 1.1498395275009536 \cdot 10^{-168}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)} - b}{a \cdot 3}\\ \mathbf{elif}\;b \leq 5.17555123963869 \cdot 10^{+45}:\\ \;\;\;\;\frac{\frac{0.3333333333333333 \cdot \mathsf{fma}\left(a, c \cdot -3, 0\right)}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]

Reproduce

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