Average Error: 33.9 → 10.6
Time: 23.3s
Precision: binary64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
\[\begin{array}{l} t_0 := \frac{c}{b} \cdot -0.5\\ \mathbf{if}\;b \leq -7.129467328473503 \cdot 10^{+79}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} - 0.6666666666666666 \cdot \frac{b}{a}\\ \mathbf{elif}\;b \leq 2.3252761482698304 \cdot 10^{-132}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(c, a \cdot -3, b \cdot b\right)} - b}{a \cdot 3}\\ \mathbf{elif}\;b \leq 4.629430298105775 \cdot 10^{-102}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq 1.1474036072114028 \cdot 10^{-45}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{a \cdot 3} - \frac{b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\begin{array}{l}
t_0 := \frac{c}{b} \cdot -0.5\\
\mathbf{if}\;b \leq -7.129467328473503 \cdot 10^{+79}:\\
\;\;\;\;0.5 \cdot \frac{c}{b} - 0.6666666666666666 \cdot \frac{b}{a}\\

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

\mathbf{elif}\;b \leq 4.629430298105775 \cdot 10^{-102}:\\
\;\;\;\;t_0\\

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

\mathbf{else}:\\
\;\;\;\;t_0\\


\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
 (let* ((t_0 (* (/ c b) -0.5)))
   (if (<= b -7.129467328473503e+79)
     (- (* 0.5 (/ c b)) (* 0.6666666666666666 (/ b a)))
     (if (<= b 2.3252761482698304e-132)
       (/ (- (sqrt (fma c (* a -3.0) (* b b))) b) (* a 3.0))
       (if (<= b 4.629430298105775e-102)
         t_0
         (if (<= b 1.1474036072114028e-45)
           (- (/ (sqrt (fma a (* c -3.0) (* b b))) (* a 3.0)) (/ b (* a 3.0)))
           t_0))))))
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 t_0 = (c / b) * -0.5;
	double tmp;
	if (b <= -7.129467328473503e+79) {
		tmp = (0.5 * (c / b)) - (0.6666666666666666 * (b / a));
	} else if (b <= 2.3252761482698304e-132) {
		tmp = (sqrt(fma(c, (a * -3.0), (b * b))) - b) / (a * 3.0);
	} else if (b <= 4.629430298105775e-102) {
		tmp = t_0;
	} else if (b <= 1.1474036072114028e-45) {
		tmp = (sqrt(fma(a, (c * -3.0), (b * b))) / (a * 3.0)) - (b / (a * 3.0));
	} else {
		tmp = t_0;
	}
	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.1294673284735029e79

    1. Initial program 43.8

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

      \[\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 b around -inf 5.6

      \[\leadsto \color{blue}{0.5 \cdot \frac{c}{b} - 0.6666666666666666 \cdot \frac{b}{a}} \]

    if -7.1294673284735029e79 < b < 2.3252761482698304e-132

    1. Initial program 11.4

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

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

    if 2.3252761482698304e-132 < b < 4.62943029810577516e-102 or 1.14740360721140278e-45 < b

    1. Initial program 52.3

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

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b}} \]

    if 4.62943029810577516e-102 < b < 1.14740360721140278e-45

    1. Initial program 36.2

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Simplified36.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 egg-rr36.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 egg-rr36.2

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{a \cdot 3} - \frac{b}{a \cdot 3}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification10.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -7.129467328473503 \cdot 10^{+79}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} - 0.6666666666666666 \cdot \frac{b}{a}\\ \mathbf{elif}\;b \leq 2.3252761482698304 \cdot 10^{-132}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(c, a \cdot -3, b \cdot b\right)} - b}{a \cdot 3}\\ \mathbf{elif}\;b \leq 4.629430298105775 \cdot 10^{-102}:\\ \;\;\;\;\frac{c}{b} \cdot -0.5\\ \mathbf{elif}\;b \leq 1.1474036072114028 \cdot 10^{-45}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{a \cdot 3} - \frac{b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -0.5\\ \end{array} \]

Reproduce

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