Average Error: 33.8 → 9.1
Time: 11.5s
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 -7.56759573380979 \cdot 10^{+118}:\\ \;\;\;\;\frac{\left(-b\right) - b}{3 \cdot a}\\ \mathbf{elif}\;b \leq 5.2420715003536045 \cdot 10^{-73}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + \left(a \cdot -3\right) \cdot c} - b}{3 \cdot a}\\ \mathbf{elif}\;b \leq 3.4777572249671126 \cdot 10^{+79}:\\ \;\;\;\;\frac{\left(a \cdot \left(c \cdot -3\right)\right) \cdot \frac{0.3333333333333333}{a}}{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 -7.56759573380979 \cdot 10^{+118}:\\
\;\;\;\;\frac{\left(-b\right) - b}{3 \cdot a}\\

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

\mathbf{elif}\;b \leq 3.4777572249671126 \cdot 10^{+79}:\\
\;\;\;\;\frac{\left(a \cdot \left(c \cdot -3\right)\right) \cdot \frac{0.3333333333333333}{a}}{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 -7.56759573380979e+118)
   (/ (- (- b) b) (* 3.0 a))
   (if (<= b 5.2420715003536045e-73)
     (/ (- (sqrt (+ (* b b) (* (* a -3.0) c))) b) (* 3.0 a))
     (if (<= b 3.4777572249671126e+79)
       (/
        (* (* a (* c -3.0)) (/ 0.3333333333333333 a))
        (+ 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 <= -7.56759573380979e+118) {
		tmp = (-b - b) / (3.0 * a);
	} else if (b <= 5.2420715003536045e-73) {
		tmp = (sqrt((b * b) + ((a * -3.0) * c)) - b) / (3.0 * a);
	} else if (b <= 3.4777572249671126e+79) {
		tmp = ((a * (c * -3.0)) * (0.3333333333333333 / a)) / (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 < -7.56759573380979045e118

    1. Initial program 51.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.1

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

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

    if -7.56759573380979045e118 < b < 5.2420715003536045e-73

    1. Initial program 12.6

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Applied cancel-sign-sub-inv_binary6412.6

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

    if 5.2420715003536045e-73 < b < 3.47775722496711261e79

    1. Initial program 42.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Simplified42.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. Applied flip--_binary6442.8

      \[\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/_binary6442.8

      \[\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. Simplified14.9

      \[\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} \]

    if 3.47775722496711261e79 < b

    1. Initial program 58.7

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -7.56759573380979 \cdot 10^{+118}:\\ \;\;\;\;\frac{\left(-b\right) - b}{3 \cdot a}\\ \mathbf{elif}\;b \leq 5.2420715003536045 \cdot 10^{-73}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + \left(a \cdot -3\right) \cdot c} - b}{3 \cdot a}\\ \mathbf{elif}\;b \leq 3.4777572249671126 \cdot 10^{+79}:\\ \;\;\;\;\frac{\left(a \cdot \left(c \cdot -3\right)\right) \cdot \frac{0.3333333333333333}{a}}{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 2022005 
(FPCore (a b c)
  :name "Cubic critical"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))