?

Average Error: 52.3 → 0.4
Time: 7.1s
Precision: binary64
Cost: 14916

?

\[\left(\left(4.930380657631324 \cdot 10^{-32} < a \land a < 2.028240960365167 \cdot 10^{+31}\right) \land \left(4.930380657631324 \cdot 10^{-32} < b \land b < 2.028240960365167 \cdot 10^{+31}\right)\right) \land \left(4.930380657631324 \cdot 10^{-32} < c \land c < 2.028240960365167 \cdot 10^{+31}\right)\]
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
\[\begin{array}{l} t_0 := \sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)}\\ \frac{\begin{array}{l} \mathbf{if}\;b + t_0 \ne 0:\\ \;\;\;\;\frac{c \cdot \left(-3 \cdot a\right)}{b + \sqrt{b \cdot b + -3 \cdot \left(c \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;t_0 - b\\ \end{array}}{3 \cdot a} \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 (sqrt (+ (* b b) (* c (* a -3.0))))))
   (/
    (if (!= (+ b t_0) 0.0)
      (/ (* c (* -3.0 a)) (+ b (sqrt (+ (* b b) (* -3.0 (* c a))))))
      (- t_0 b))
    (* 3.0 a))))
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 = sqrt(((b * b) + (c * (a * -3.0))));
	double tmp;
	if ((b + t_0) != 0.0) {
		tmp = (c * (-3.0 * a)) / (b + sqrt(((b * b) + (-3.0 * (c * a)))));
	} else {
		tmp = t_0 - b;
	}
	return tmp / (3.0 * a);
}
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    code = (-b + sqrt(((b * b) - ((3.0d0 * a) * c)))) / (3.0d0 * a)
end function
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8) :: t_0
    real(8) :: tmp
    t_0 = sqrt(((b * b) + (c * (a * (-3.0d0)))))
    if ((b + t_0) /= 0.0d0) then
        tmp = (c * ((-3.0d0) * a)) / (b + sqrt(((b * b) + ((-3.0d0) * (c * a)))))
    else
        tmp = t_0 - b
    end if
    code = tmp / (3.0d0 * a)
end function
public static double code(double a, double b, double c) {
	return (-b + Math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
public static double code(double a, double b, double c) {
	double t_0 = Math.sqrt(((b * b) + (c * (a * -3.0))));
	double tmp;
	if ((b + t_0) != 0.0) {
		tmp = (c * (-3.0 * a)) / (b + Math.sqrt(((b * b) + (-3.0 * (c * a)))));
	} else {
		tmp = t_0 - b;
	}
	return tmp / (3.0 * a);
}
def code(a, b, c):
	return (-b + math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a)
def code(a, b, c):
	t_0 = math.sqrt(((b * b) + (c * (a * -3.0))))
	tmp = 0
	if (b + t_0) != 0.0:
		tmp = (c * (-3.0 * a)) / (b + math.sqrt(((b * b) + (-3.0 * (c * a)))))
	else:
		tmp = t_0 - b
	return tmp / (3.0 * a)
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 = sqrt(Float64(Float64(b * b) + Float64(c * Float64(a * -3.0))))
	tmp = 0.0
	if (Float64(b + t_0) != 0.0)
		tmp = Float64(Float64(c * Float64(-3.0 * a)) / Float64(b + sqrt(Float64(Float64(b * b) + Float64(-3.0 * Float64(c * a))))));
	else
		tmp = Float64(t_0 - b);
	end
	return Float64(tmp / Float64(3.0 * a))
end
function tmp = code(a, b, c)
	tmp = (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
end
function tmp_2 = code(a, b, c)
	t_0 = sqrt(((b * b) + (c * (a * -3.0))));
	tmp = 0.0;
	if ((b + t_0) ~= 0.0)
		tmp = (c * (-3.0 * a)) / (b + sqrt(((b * b) + (-3.0 * (c * a)))));
	else
		tmp = t_0 - b;
	end
	tmp_2 = tmp / (3.0 * a);
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[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(c * N[(a * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, N[(If[Unequal[N[(b + t$95$0), $MachinePrecision], 0.0], N[(N[(c * N[(-3.0 * a), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(-3.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 - b), $MachinePrecision]] / N[(3.0 * a), $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 := \sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)}\\
\frac{\begin{array}{l}
\mathbf{if}\;b + t_0 \ne 0:\\
\;\;\;\;\frac{c \cdot \left(-3 \cdot a\right)}{b + \sqrt{b \cdot b + -3 \cdot \left(c \cdot a\right)}}\\

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


\end{array}}{3 \cdot a}
\end{array}

Error?

Derivation?

  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}{\frac{\sqrt{b \cdot b - 3 \cdot \left(c \cdot a\right)} - b}{3 \cdot a}} \]
    Proof

    [Start]52.3

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

    rational_best-simplify-62 [=>]52.3

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

    rational_best-simplify-51 [=>]52.3

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

    rational_best-simplify-3 [=>]52.3

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

    rational_best-simplify-113 [=>]52.3

    \[ \frac{\sqrt{b \cdot b - \color{blue}{3 \cdot \left(c \cdot a\right)}} - b}{3 \cdot a} \]
  3. Applied egg-rr52.0

    \[\leadsto \frac{\color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;b + \sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} \ne 0:\\ \;\;\;\;\frac{\sqrt{\left(b \cdot b + c \cdot \left(a \cdot -3\right)\right) \cdot \left(b \cdot b + c \cdot \left(a \cdot -3\right)\right)} - b \cdot b}{b + \sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b\\ } \end{array}}}{3 \cdot a} \]
  4. Taylor expanded in b around 0 0.5

    \[\leadsto \frac{\begin{array}{l} \mathbf{if}\;b + \sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} \ne 0:\\ \;\;\;\;\frac{\color{blue}{-3 \cdot \left(c \cdot a\right)}}{b + \sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b\\ \end{array}}{3 \cdot a} \]
  5. Simplified0.4

    \[\leadsto \frac{\begin{array}{l} \mathbf{if}\;b + \sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} \ne 0:\\ \;\;\;\;\frac{\color{blue}{c \cdot \left(-3 \cdot a\right)}}{b + \sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b\\ \end{array}}{3 \cdot a} \]
    Proof

    [Start]0.5

    \[ \frac{\begin{array}{l} \mathbf{if}\;b + \sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} \ne 0:\\ \;\;\;\;\frac{-3 \cdot \left(c \cdot a\right)}{b + \sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b\\ \end{array}}{3 \cdot a} \]

    rational_best-simplify-113 [=>]0.4

    \[ \frac{\begin{array}{l} \mathbf{if}\;b + \sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} \ne 0:\\ \;\;\;\;\frac{\color{blue}{c \cdot \left(-3 \cdot a\right)}}{b + \sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b\\ \end{array}}{3 \cdot a} \]
  6. Taylor expanded in c around 0 0.4

    \[\leadsto \frac{\begin{array}{l} \mathbf{if}\;b + \sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} \ne 0:\\ \;\;\;\;\frac{c \cdot \left(-3 \cdot a\right)}{b + \sqrt{b \cdot b + \color{blue}{-3 \cdot \left(c \cdot a\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b\\ \end{array}}{3 \cdot a} \]
  7. Final simplification0.4

    \[\leadsto \frac{\begin{array}{l} \mathbf{if}\;b + \sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} \ne 0:\\ \;\;\;\;\frac{c \cdot \left(-3 \cdot a\right)}{b + \sqrt{b \cdot b + -3 \cdot \left(c \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b\\ \end{array}}{3 \cdot a} \]

Alternatives

Alternative 1
Error0.5
Cost14916
\[\begin{array}{l} t_0 := \sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)}\\ t_1 := b + t_0\\ \frac{\begin{array}{l} \mathbf{if}\;t_1 \ne 0:\\ \;\;\;\;\frac{-3 \cdot \left(c \cdot a\right)}{t_1}\\ \mathbf{else}:\\ \;\;\;\;t_0 - b\\ \end{array}}{3 \cdot a} \end{array} \]
Alternative 2
Error6.0
Cost14852
\[\begin{array}{l} \mathbf{if}\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \leq -5 \cdot 10^{-17}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 3 \cdot \left(c \cdot a\right)} - b}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 3
Error3.1
Cost13760
\[-0.5 \cdot \frac{c}{b} + -0.375 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}} \]
Alternative 4
Error6.4
Cost320
\[-0.5 \cdot \frac{c}{b} \]

Error

Reproduce?

herbie shell --seed 2023104 
(FPCore (a b c)
  :name "Cubic critical, wide range"
  :precision binary64
  :pre (and (and (and (< 4.930380657631324e-32 a) (< a 2.028240960365167e+31)) (and (< 4.930380657631324e-32 b) (< b 2.028240960365167e+31))) (and (< 4.930380657631324e-32 c) (< c 2.028240960365167e+31)))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))