Average Error: 28.9 → 5.0
Time: 50.5s
Precision: binary64
Cost: 62468
\[\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 := {\left(-1.5 \cdot \left(c \cdot a\right)\right)}^{2}\\ t_1 := \sqrt{\mathsf{fma}\left(b, b, \left(-3 \cdot c\right) \cdot a\right)}\\ t_2 := \left(-b\right) - t_1\\ \mathbf{if}\;b \leq 0.0202:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;t_2 \ne 0:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, b, -{t_1}^{2}\right)}{t_2}\\ \mathbf{else}:\\ \;\;\;\;t_1 - b\\ \end{array} \cdot \frac{0.3333333333333333}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.16666666666666666 \cdot \frac{{\left(\frac{1}{b}\right)}^{7} \cdot \left(2.25 \cdot \left(t_0 \cdot \left({a}^{2} \cdot {c}^{2}\right)\right) + {\left(-0.5 \cdot t_0\right)}^{2}\right)}{a} + \left(-0.25 \cdot \left(c \cdot \left(t_0 \cdot {\left(\frac{1}{b}\right)}^{5}\right)\right) + \left(-0.16666666666666666 \cdot \frac{t_0 \cdot \frac{\frac{\frac{1}{b}}{b}}{b}}{a} + -0.5 \cdot \frac{c}{b}\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 (pow (* -1.5 (* c a)) 2.0))
        (t_1 (sqrt (fma b b (* (* -3.0 c) a))))
        (t_2 (- (- b) t_1)))
   (if (<= b 0.0202)
     (*
      (if (!= t_2 0.0) (/ (fma b b (- (pow t_1 2.0))) t_2) (- t_1 b))
      (/ 0.3333333333333333 a))
     (+
      (*
       -0.16666666666666666
       (/
        (*
         (pow (/ 1.0 b) 7.0)
         (+
          (* 2.25 (* t_0 (* (pow a 2.0) (pow c 2.0))))
          (pow (* -0.5 t_0) 2.0)))
        a))
      (+
       (* -0.25 (* c (* t_0 (pow (/ 1.0 b) 5.0))))
       (+
        (* -0.16666666666666666 (/ (* t_0 (/ (/ (/ 1.0 b) 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 t_0 = pow((-1.5 * (c * a)), 2.0);
	double t_1 = sqrt(fma(b, b, ((-3.0 * c) * a)));
	double t_2 = -b - t_1;
	double tmp_1;
	if (b <= 0.0202) {
		double tmp_2;
		if (t_2 != 0.0) {
			tmp_2 = fma(b, b, -pow(t_1, 2.0)) / t_2;
		} else {
			tmp_2 = t_1 - b;
		}
		tmp_1 = tmp_2 * (0.3333333333333333 / a);
	} else {
		tmp_1 = (-0.16666666666666666 * ((pow((1.0 / b), 7.0) * ((2.25 * (t_0 * (pow(a, 2.0) * pow(c, 2.0)))) + pow((-0.5 * t_0), 2.0))) / a)) + ((-0.25 * (c * (t_0 * pow((1.0 / b), 5.0)))) + ((-0.16666666666666666 * ((t_0 * (((1.0 / b) / b) / b)) / a)) + (-0.5 * (c / b))));
	}
	return tmp_1;
}
function code(a, b, c)
	return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c)))) / Float64(3.0 * a))
end
function code(a, b, c)
	t_0 = Float64(-1.5 * Float64(c * a)) ^ 2.0
	t_1 = sqrt(fma(b, b, Float64(Float64(-3.0 * c) * a)))
	t_2 = Float64(Float64(-b) - t_1)
	tmp_1 = 0.0
	if (b <= 0.0202)
		tmp_2 = 0.0
		if (t_2 != 0.0)
			tmp_2 = Float64(fma(b, b, Float64(-(t_1 ^ 2.0))) / t_2);
		else
			tmp_2 = Float64(t_1 - b);
		end
		tmp_1 = Float64(tmp_2 * Float64(0.3333333333333333 / a));
	else
		tmp_1 = Float64(Float64(-0.16666666666666666 * Float64(Float64((Float64(1.0 / b) ^ 7.0) * Float64(Float64(2.25 * Float64(t_0 * Float64((a ^ 2.0) * (c ^ 2.0)))) + (Float64(-0.5 * t_0) ^ 2.0))) / a)) + Float64(Float64(-0.25 * Float64(c * Float64(t_0 * (Float64(1.0 / b) ^ 5.0)))) + Float64(Float64(-0.16666666666666666 * Float64(Float64(t_0 * Float64(Float64(Float64(1.0 / b) / b) / b)) / a)) + Float64(-0.5 * Float64(c / b)))));
	end
	return tmp_1
end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(3.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := Block[{t$95$0 = N[Power[N[(-1.5 * N[(c * a), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(b * b + N[(N[(-3.0 * c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[((-b) - t$95$1), $MachinePrecision]}, If[LessEqual[b, 0.0202], N[(If[Unequal[t$95$2, 0.0], N[(N[(b * b + (-N[Power[t$95$1, 2.0], $MachinePrecision])), $MachinePrecision] / t$95$2), $MachinePrecision], N[(t$95$1 - b), $MachinePrecision]] * N[(0.3333333333333333 / a), $MachinePrecision]), $MachinePrecision], N[(N[(-0.16666666666666666 * N[(N[(N[Power[N[(1.0 / b), $MachinePrecision], 7.0], $MachinePrecision] * N[(N[(2.25 * N[(t$95$0 * N[(N[Power[a, 2.0], $MachinePrecision] * N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Power[N[(-0.5 * t$95$0), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] + N[(N[(-0.25 * N[(c * N[(t$95$0 * N[Power[N[(1.0 / b), $MachinePrecision], 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(-0.16666666666666666 * N[(N[(t$95$0 * N[(N[(N[(1.0 / b), $MachinePrecision] / b), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] + N[(-0.5 * N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\begin{array}{l}
t_0 := {\left(-1.5 \cdot \left(c \cdot a\right)\right)}^{2}\\
t_1 := \sqrt{\mathsf{fma}\left(b, b, \left(-3 \cdot c\right) \cdot a\right)}\\
t_2 := \left(-b\right) - t_1\\
\mathbf{if}\;b \leq 0.0202:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;t_2 \ne 0:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, b, -{t_1}^{2}\right)}{t_2}\\

\mathbf{else}:\\
\;\;\;\;t_1 - b\\


\end{array} \cdot \frac{0.3333333333333333}{a}\\

\mathbf{else}:\\
\;\;\;\;-0.16666666666666666 \cdot \frac{{\left(\frac{1}{b}\right)}^{7} \cdot \left(2.25 \cdot \left(t_0 \cdot \left({a}^{2} \cdot {c}^{2}\right)\right) + {\left(-0.5 \cdot t_0\right)}^{2}\right)}{a} + \left(-0.25 \cdot \left(c \cdot \left(t_0 \cdot {\left(\frac{1}{b}\right)}^{5}\right)\right) + \left(-0.16666666666666666 \cdot \frac{t_0 \cdot \frac{\frac{\frac{1}{b}}{b}}{b}}{a} + -0.5 \cdot \frac{c}{b}\right)\right)\\


\end{array}

Error

Derivation

  1. Split input into 2 regimes
  2. if b < 0.0201999999999999992

    1. Initial program 9.3

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

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

      \[\leadsto \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, \left(-3 \cdot c\right) \cdot a\right)} \ne 0:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, b, -{\left(\sqrt{\mathsf{fma}\left(b, b, \left(-3 \cdot c\right) \cdot a\right)}\right)}^{2}\right)}{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, \left(-3 \cdot c\right) \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(b, b, \left(-3 \cdot c\right) \cdot a\right)} - b\\ } \end{array}} \cdot \frac{0.3333333333333333}{a} \]

    if 0.0201999999999999992 < b

    1. Initial program 30.5

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

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

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot \frac{{\left(\frac{1}{b}\right)}^{7} \cdot \left(2.25 \cdot \left({\left(-1.5 \cdot \left(c \cdot a\right)\right)}^{2} \cdot \left({a}^{2} \cdot {c}^{2}\right)\right) + {\left(-0.5 \cdot {\left(-1.5 \cdot \left(c \cdot a\right)\right)}^{2}\right)}^{2}\right)}{a} + \left(-0.25 \cdot \left(c \cdot \left({\left(-1.5 \cdot \left(c \cdot a\right)\right)}^{2} \cdot {\left(\frac{1}{b}\right)}^{5}\right)\right) + \left(-0.16666666666666666 \cdot \frac{{\left(-1.5 \cdot \left(c \cdot a\right)\right)}^{2} \cdot {\left(\frac{1}{b}\right)}^{3}}{a} + -0.5 \cdot \frac{c}{b}\right)\right)} \]
    4. Applied egg-rr4.7

      \[\leadsto -0.16666666666666666 \cdot \frac{{\left(\frac{1}{b}\right)}^{7} \cdot \left(2.25 \cdot \left({\left(-1.5 \cdot \left(c \cdot a\right)\right)}^{2} \cdot \left({a}^{2} \cdot {c}^{2}\right)\right) + {\left(-0.5 \cdot {\left(-1.5 \cdot \left(c \cdot a\right)\right)}^{2}\right)}^{2}\right)}{a} + \left(-0.25 \cdot \left(c \cdot \left({\left(-1.5 \cdot \left(c \cdot a\right)\right)}^{2} \cdot {\left(\frac{1}{b}\right)}^{5}\right)\right) + \left(-0.16666666666666666 \cdot \frac{{\left(-1.5 \cdot \left(c \cdot a\right)\right)}^{2} \cdot \color{blue}{\frac{\frac{\frac{1}{b}}{b}}{b}}}{a} + -0.5 \cdot \frac{c}{b}\right)\right) \]
  3. Recombined 2 regimes into one program.

Alternatives

Alternative 1
Error5.0
Cost53704
\[\begin{array}{l} t_0 := \left(\left(2.25 \cdot \left(c \cdot c\right)\right) \cdot a\right) \cdot a\\ t_1 := {\left(-1.5 \cdot \left(c \cdot a\right)\right)}^{2}\\ t_2 := \sqrt{\mathsf{fma}\left(b, b, \left(-3 \cdot c\right) \cdot a\right)}\\ t_3 := \left(-b\right) - t_2\\ \mathbf{if}\;b \leq 0.0202:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;t_3 \ne 0:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, b, -{t_2}^{2}\right)}{t_3}\\ \mathbf{else}:\\ \;\;\;\;t_2 - b\\ \end{array} \cdot \frac{0.3333333333333333}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.16666666666666666 \cdot \frac{{\left(\frac{1}{b}\right)}^{7} \cdot \left(2.25 \cdot \left(t_1 \cdot \left({a}^{2} \cdot {c}^{2}\right)\right) + {\left(-0.5 \cdot t_1\right)}^{2}\right)}{a} + \left(-0.25 \cdot \left(c \cdot \left(t_0 \cdot {\left(\frac{1}{b}\right)}^{5}\right)\right) + \left(-0.16666666666666666 \cdot \frac{t_0 \cdot \frac{\frac{\frac{1}{b}}{b}}{b}}{a} + -0.5 \cdot \frac{c}{b}\right)\right)\\ \end{array} \]
Alternative 2
Error5.0
Cost50052
\[\begin{array}{l} t_0 := {\left(-1.5 \cdot \left(c \cdot a\right)\right)}^{2}\\ t_1 := \left(\left(2.25 \cdot \left(c \cdot c\right)\right) \cdot a\right) \cdot a\\ \mathbf{if}\;b \leq 0.0202:\\ \;\;\;\;\frac{\frac{\frac{\sqrt{\mathsf{fma}\left(b, b, -3 \cdot \left(a \cdot c\right)\right)} - b}{a}}{\sqrt{3}}}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;-0.16666666666666666 \cdot \frac{{\left(\frac{1}{b}\right)}^{7} \cdot \left(2.25 \cdot \left(t_0 \cdot \left({a}^{2} \cdot {c}^{2}\right)\right) + {\left(-0.5 \cdot t_0\right)}^{2}\right)}{a} + \left(-0.25 \cdot \left(c \cdot \left(t_1 \cdot {\left(\frac{1}{b}\right)}^{5}\right)\right) + \left(-0.16666666666666666 \cdot \frac{t_1 \cdot \frac{\frac{\frac{1}{b}}{b}}{b}}{a} + -0.5 \cdot \frac{c}{b}\right)\right)\\ \end{array} \]
Alternative 3
Error6.6
Cost28100
\[\begin{array}{l} t_0 := {\left(-1.5 \cdot \left(c \cdot a\right)\right)}^{2}\\ \mathbf{if}\;b \leq 0.0202:\\ \;\;\;\;\frac{\frac{\frac{\sqrt{\mathsf{fma}\left(b, b, -3 \cdot \left(a \cdot c\right)\right)} - b}{a}}{\sqrt{3}}}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;-0.25 \cdot \left(c \cdot \left(t_0 \cdot {\left(\frac{1}{b}\right)}^{5}\right)\right) + \left(-0.16666666666666666 \cdot \frac{t_0 \cdot {\left(\frac{1}{b}\right)}^{3}}{a} + -0.5 \cdot \frac{c}{b}\right)\\ \end{array} \]
Alternative 4
Error9.3
Cost27780
\[\begin{array}{l} \mathbf{if}\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \leq -0.0044:\\ \;\;\;\;\left(\sqrt{\mathsf{fma}\left(b, b, -3 \cdot \left(a \cdot c\right)\right)} - b\right) \cdot \sqrt[3]{\frac{\frac{0.037037037037037035}{a \cdot a}}{a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b} + \left({\left(\frac{\left(-1.5 \cdot c\right) \cdot a}{b}\right)}^{2} \cdot \frac{-0.5}{b}\right) \cdot \frac{0.3333333333333333}{a}\\ \end{array} \]
Alternative 5
Error9.3
Cost21124
\[\begin{array}{l} \mathbf{if}\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \leq -0.0044:\\ \;\;\;\;\left(\sqrt{\mathsf{fma}\left(b, b, \left(-3 \cdot a\right) \cdot c\right)} - b\right) \cdot \frac{0.3333333333333333}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b} + \left({\left(\frac{\left(-1.5 \cdot c\right) \cdot a}{b}\right)}^{2} \cdot \frac{-0.5}{b}\right) \cdot \frac{0.3333333333333333}{a}\\ \end{array} \]
Alternative 6
Error9.3
Cost21124
\[\begin{array}{l} \mathbf{if}\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \leq -0.0044:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, -3 \cdot \left(a \cdot c\right)\right)} - b}{\frac{a}{0.3333333333333333}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b} + \left({\left(\frac{\left(-1.5 \cdot c\right) \cdot a}{b}\right)}^{2} \cdot \frac{-0.5}{b}\right) \cdot \frac{0.3333333333333333}{a}\\ \end{array} \]
Alternative 7
Error9.3
Cost21124
\[\begin{array}{l} \mathbf{if}\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \leq -0.0044:\\ \;\;\;\;\frac{\frac{\sqrt{\mathsf{fma}\left(b, b, \left(-3 \cdot c\right) \cdot a\right)} - b}{a}}{3}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b} + \left({\left(\frac{\left(-1.5 \cdot c\right) \cdot a}{b}\right)}^{2} \cdot \frac{-0.5}{b}\right) \cdot \frac{0.3333333333333333}{a}\\ \end{array} \]
Alternative 8
Error9.4
Cost15300
\[\begin{array}{l} \mathbf{if}\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \leq -0.0044:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(a \cdot c\right) \cdot 3}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b} + \left({\left(\frac{\left(-1.5 \cdot c\right) \cdot a}{b}\right)}^{2} \cdot \frac{-0.5}{b}\right) \cdot \frac{0.3333333333333333}{a}\\ \end{array} \]
Alternative 9
Error9.6
Cost14916
\[\begin{array}{l} t_0 := \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\\ t_1 := \frac{c \cdot a}{b}\\ \mathbf{if}\;t_0 \leq -0.0044:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-1.5 \cdot c\right) \cdot a}{b} \cdot \frac{0.3333333333333333}{a} + \left(\left(2.25 \cdot \left(t_1 \cdot t_1\right)\right) \cdot \frac{-0.5}{b}\right) \cdot \frac{0.3333333333333333}{a}\\ \end{array} \]
Alternative 10
Error9.6
Cost14916
\[\begin{array}{l} t_0 := \frac{c \cdot a}{b}\\ \mathbf{if}\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \leq -0.0044:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(a \cdot c\right) \cdot 3}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-1.5 \cdot c\right) \cdot a}{b} \cdot \frac{0.3333333333333333}{a} + \left(\left(2.25 \cdot \left(t_0 \cdot t_0\right)\right) \cdot \frac{-0.5}{b}\right) \cdot \frac{0.3333333333333333}{a}\\ \end{array} \]
Alternative 11
Error11.7
Cost2112
\[\begin{array}{l} t_0 := \frac{c \cdot a}{b}\\ \frac{\left(-1.5 \cdot c\right) \cdot a}{b} \cdot \frac{0.3333333333333333}{a} + \left(\left(2.25 \cdot \left(t_0 \cdot t_0\right)\right) \cdot \frac{-0.5}{b}\right) \cdot \frac{0.3333333333333333}{a} \end{array} \]
Alternative 12
Error11.7
Cost2112
\[\frac{\left(-1.5 \cdot c\right) \cdot a}{b} \cdot \frac{0.3333333333333333}{a} + \left(\left(2.25 \cdot \frac{\left(c \cdot c\right) \cdot \left(a \cdot a\right)}{b \cdot b}\right) \cdot \frac{-0.5}{b}\right) \cdot \frac{0.3333333333333333}{a} \]
Alternative 13
Error22.4
Cost320
\[\frac{-0.5 \cdot c}{b} \]

Error

Reproduce

herbie shell --seed 2023010 
(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)))