Average Error: 28.6 → 5.1
Time: 6.8s
Precision: binary64
\[\left(\left(1.0536712127723509 \cdot 10^{-8} < a \land a < 94906265.62425156\right) \land \left(1.0536712127723509 \cdot 10^{-8} < b \land b < 94906265.62425156\right)\right) \land \left(1.0536712127723509 \cdot 10^{-8} < c \land c < 94906265.62425156\right)\]
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
\[\begin{array}{l} t_0 := \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\\ \mathbf{if}\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a} \leq -7.2325206455704425:\\ \;\;\;\;\left(\left(t_0 - b \cdot b\right) \cdot \frac{1}{b + \sqrt{t_0}}\right) \cdot \frac{0.3333333333333333}{a}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\left(a \cdot a\right) \cdot {c}^{3}}{{b}^{5}}, -0.5625, \mathsf{fma}\left(\frac{{a}^{3} \cdot {c}^{4}}{{b}^{7}}, -1.0546875, \mathsf{fma}\left(\frac{c \cdot \left(a \cdot c\right)}{{b}^{3}}, -0.375, -0.5 \cdot \frac{c}{b}\right)\right)\right)\\ \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 := \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\\
\mathbf{if}\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a} \leq -7.2325206455704425:\\
\;\;\;\;\left(\left(t_0 - b \cdot b\right) \cdot \frac{1}{b + \sqrt{t_0}}\right) \cdot \frac{0.3333333333333333}{a}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\left(a \cdot a\right) \cdot {c}^{3}}{{b}^{5}}, -0.5625, \mathsf{fma}\left(\frac{{a}^{3} \cdot {c}^{4}}{{b}^{7}}, -1.0546875, \mathsf{fma}\left(\frac{c \cdot \left(a \cdot c\right)}{{b}^{3}}, -0.375, -0.5 \cdot \frac{c}{b}\right)\right)\right)\\


\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 (fma a (* c -3.0) (* b b))))
   (if (<=
        (/ (- (sqrt (- (* b b) (* (* 3.0 a) c))) b) (* 3.0 a))
        -7.2325206455704425)
     (* (* (- t_0 (* b b)) (/ 1.0 (+ b (sqrt t_0)))) (/ 0.3333333333333333 a))
     (fma
      (/ (* (* a a) (pow c 3.0)) (pow b 5.0))
      -0.5625
      (fma
       (/ (* (pow a 3.0) (pow c 4.0)) (pow b 7.0))
       -1.0546875
       (fma (/ (* c (* a c)) (pow b 3.0)) -0.375 (* -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 t_0 = fma(a, (c * -3.0), (b * b));
	double tmp;
	if (((sqrt(((b * b) - ((3.0 * a) * c))) - b) / (3.0 * a)) <= -7.2325206455704425) {
		tmp = ((t_0 - (b * b)) * (1.0 / (b + sqrt(t_0)))) * (0.3333333333333333 / a);
	} else {
		tmp = fma((((a * a) * pow(c, 3.0)) / pow(b, 5.0)), -0.5625, fma(((pow(a, 3.0) * pow(c, 4.0)) / pow(b, 7.0)), -1.0546875, fma(((c * (a * c)) / pow(b, 3.0)), -0.375, (-0.5 * (c / b)))));
	}
	return tmp;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 2 regimes
  2. if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) < -7.2325206455704425

    1. Initial program 9.8

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

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

    if -7.2325206455704425 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a))

    1. Initial program 30.8

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

      \[\leadsto \color{blue}{-\left(0.5625 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}} + \left(1.0546875 \cdot \frac{{c}^{4} \cdot {a}^{3}}{{b}^{7}} + \left(0.375 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}} + 0.5 \cdot \frac{c}{b}\right)\right)\right)} \]
    4. Simplified4.7

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\left(a \cdot a\right) \cdot {c}^{3}}{{b}^{5}}, -0.5625, \mathsf{fma}\left(\frac{{a}^{3} \cdot {c}^{4}}{{b}^{7}}, -1.0546875, \mathsf{fma}\left(\frac{c \cdot \left(c \cdot a\right)}{{b}^{3}}, -0.375, -0.5 \cdot \frac{c}{b}\right)\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification5.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a} \leq -7.2325206455704425:\\ \;\;\;\;\left(\left(\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right) - b \cdot b\right) \cdot \frac{1}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}\right) \cdot \frac{0.3333333333333333}{a}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\left(a \cdot a\right) \cdot {c}^{3}}{{b}^{5}}, -0.5625, \mathsf{fma}\left(\frac{{a}^{3} \cdot {c}^{4}}{{b}^{7}}, -1.0546875, \mathsf{fma}\left(\frac{c \cdot \left(a \cdot c\right)}{{b}^{3}}, -0.375, -0.5 \cdot \frac{c}{b}\right)\right)\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022130 
(FPCore (a b c)
  :name "Cubic critical, narrow range"
  :precision binary64
  :pre (and (and (and (< 1.0536712127723509e-8 a) (< a 94906265.62425156)) (and (< 1.0536712127723509e-8 b) (< b 94906265.62425156))) (and (< 1.0536712127723509e-8 c) (< c 94906265.62425156)))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))