?

Average Error: 33.9 → 9.8
Time: 1.4min
Precision: binary64
Cost: 7880

?

\[\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 -5.2 \cdot 10^{+87}:\\ \;\;\;\;-0.6666666666666666 \cdot \frac{b}{a} + 0.5 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \leq 4 \cdot 10^{-36}:\\ \;\;\;\;\sqrt{b \cdot b + \frac{a \cdot c}{-0.3333333333333333}} \cdot \frac{0.3333333333333333}{a} - b \cdot \frac{0.3333333333333333}{a}\\ \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 -5.2e+87)
   (+ (* -0.6666666666666666 (/ b a)) (* 0.5 (/ c b)))
   (if (<= b 4e-36)
     (-
      (*
       (sqrt (+ (* b b) (/ (* a c) -0.3333333333333333)))
       (/ 0.3333333333333333 a))
      (* b (/ 0.3333333333333333 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 tmp;
	if (b <= -5.2e+87) {
		tmp = (-0.6666666666666666 * (b / a)) + (0.5 * (c / b));
	} else if (b <= 4e-36) {
		tmp = (sqrt(((b * b) + ((a * c) / -0.3333333333333333))) * (0.3333333333333333 / a)) - (b * (0.3333333333333333 / a));
	} else {
		tmp = -0.5 * (c / b);
	}
	return tmp;
}
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) :: tmp
    if (b <= (-5.2d+87)) then
        tmp = ((-0.6666666666666666d0) * (b / a)) + (0.5d0 * (c / b))
    else if (b <= 4d-36) then
        tmp = (sqrt(((b * b) + ((a * c) / (-0.3333333333333333d0)))) * (0.3333333333333333d0 / a)) - (b * (0.3333333333333333d0 / a))
    else
        tmp = (-0.5d0) * (c / b)
    end if
    code = tmp
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 tmp;
	if (b <= -5.2e+87) {
		tmp = (-0.6666666666666666 * (b / a)) + (0.5 * (c / b));
	} else if (b <= 4e-36) {
		tmp = (Math.sqrt(((b * b) + ((a * c) / -0.3333333333333333))) * (0.3333333333333333 / a)) - (b * (0.3333333333333333 / a));
	} else {
		tmp = -0.5 * (c / b);
	}
	return tmp;
}
def code(a, b, c):
	return (-b + math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a)
def code(a, b, c):
	tmp = 0
	if b <= -5.2e+87:
		tmp = (-0.6666666666666666 * (b / a)) + (0.5 * (c / b))
	elif b <= 4e-36:
		tmp = (math.sqrt(((b * b) + ((a * c) / -0.3333333333333333))) * (0.3333333333333333 / a)) - (b * (0.3333333333333333 / a))
	else:
		tmp = -0.5 * (c / b)
	return tmp
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)
	tmp = 0.0
	if (b <= -5.2e+87)
		tmp = Float64(Float64(-0.6666666666666666 * Float64(b / a)) + Float64(0.5 * Float64(c / b)));
	elseif (b <= 4e-36)
		tmp = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(Float64(a * c) / -0.3333333333333333))) * Float64(0.3333333333333333 / a)) - Float64(b * Float64(0.3333333333333333 / a)));
	else
		tmp = Float64(-0.5 * Float64(c / b));
	end
	return tmp
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)
	tmp = 0.0;
	if (b <= -5.2e+87)
		tmp = (-0.6666666666666666 * (b / a)) + (0.5 * (c / b));
	elseif (b <= 4e-36)
		tmp = (sqrt(((b * b) + ((a * c) / -0.3333333333333333))) * (0.3333333333333333 / a)) - (b * (0.3333333333333333 / a));
	else
		tmp = -0.5 * (c / b);
	end
	tmp_2 = tmp;
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_] := If[LessEqual[b, -5.2e+87], N[(N[(-0.6666666666666666 * N[(b / a), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4e-36], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(N[(a * c), $MachinePrecision] / -0.3333333333333333), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(0.3333333333333333 / a), $MachinePrecision]), $MachinePrecision] - N[(b * N[(0.3333333333333333 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\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 -5.2 \cdot 10^{+87}:\\
\;\;\;\;-0.6666666666666666 \cdot \frac{b}{a} + 0.5 \cdot \frac{c}{b}\\

\mathbf{elif}\;b \leq 4 \cdot 10^{-36}:\\
\;\;\;\;\sqrt{b \cdot b + \frac{a \cdot c}{-0.3333333333333333}} \cdot \frac{0.3333333333333333}{a} - b \cdot \frac{0.3333333333333333}{a}\\

\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Split input into 3 regimes
  2. if b < -5.19999999999999997e87

    1. Initial program 44.2

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

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

      [Start]44.2

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

      rational_best-simplify-3 [=>]44.2

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

      rational_best-simplify-9 [<=]44.2

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

      rational_best-simplify-56 [=>]44.2

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

      rational_best-simplify-6 [=>]44.2

      \[ \frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - \color{blue}{b}}{3 \cdot a} \]
    3. Taylor expanded in b around -inf 4.5

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

    if -5.19999999999999997e87 < b < 3.9999999999999998e-36

    1. Initial program 14.2

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

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

      [Start]14.2

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

      rational_best-simplify-3 [=>]14.2

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

      rational_best-simplify-9 [<=]14.2

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

      rational_best-simplify-56 [=>]14.2

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

      rational_best-simplify-6 [=>]14.2

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

      \[\leadsto \color{blue}{\sqrt{b \cdot b + \frac{a \cdot c}{-0.3333333333333333}} \cdot \frac{0.3333333333333333}{a} - b \cdot \frac{0.3333333333333333}{a}} \]

    if 3.9999999999999998e-36 < b

    1. Initial program 55.1

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

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

      [Start]55.1

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

      rational_best-simplify-3 [=>]55.1

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

      rational_best-simplify-9 [<=]55.1

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

      rational_best-simplify-56 [=>]55.1

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

      rational_best-simplify-6 [=>]55.1

      \[ \frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - \color{blue}{b}}{3 \cdot a} \]
    3. Taylor expanded in b around inf 6.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -5.2 \cdot 10^{+87}:\\ \;\;\;\;-0.6666666666666666 \cdot \frac{b}{a} + 0.5 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \leq 4 \cdot 10^{-36}:\\ \;\;\;\;\sqrt{b \cdot b + \frac{a \cdot c}{-0.3333333333333333}} \cdot \frac{0.3333333333333333}{a} - b \cdot \frac{0.3333333333333333}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]

Alternatives

Alternative 1
Error9.7
Cost7624
\[\begin{array}{l} \mathbf{if}\;b \leq -9.5 \cdot 10^{+87}:\\ \;\;\;\;-0.6666666666666666 \cdot \frac{b}{a} + 0.5 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \leq 1.05 \cdot 10^{-35}:\\ \;\;\;\;\frac{0.3333333333333333}{a} \cdot \left(\sqrt{b \cdot b + \frac{a \cdot c}{-0.3333333333333333}} - b\right)\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 2
Error9.6
Cost7624
\[\begin{array}{l} \mathbf{if}\;b \leq -1.25 \cdot 10^{+134}:\\ \;\;\;\;-0.6666666666666666 \cdot \frac{b}{a} + 0.5 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \leq 5.8 \cdot 10^{-36}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 3
Error13.0
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -2.05 \cdot 10^{-73}:\\ \;\;\;\;-0.6666666666666666 \cdot \frac{b}{a} + 0.5 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \leq 1.85 \cdot 10^{-35}:\\ \;\;\;\;\left(b - \sqrt{a \cdot \left(c \cdot -3\right)}\right) \cdot \frac{-0.3333333333333333}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 4
Error13.0
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -2.05 \cdot 10^{-73}:\\ \;\;\;\;-0.6666666666666666 \cdot \frac{b}{a} + 0.5 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \leq 1.2 \cdot 10^{-34}:\\ \;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -3\right)} - b}{a} \cdot 0.3333333333333333\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 5
Error13.0
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -2.05 \cdot 10^{-73}:\\ \;\;\;\;-0.6666666666666666 \cdot \frac{b}{a} + 0.5 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \leq 3 \cdot 10^{-35}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -3\right)} - b}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 6
Error13.2
Cost7240
\[\begin{array}{l} \mathbf{if}\;b \leq -1.55 \cdot 10^{-76}:\\ \;\;\;\;-0.6666666666666666 \cdot \frac{b}{a} + 0.5 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \leq 3.6 \cdot 10^{-34}:\\ \;\;\;\;\frac{\sqrt{-3 \cdot \left(a \cdot c\right)}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 7
Error19.7
Cost7112
\[\begin{array}{l} \mathbf{if}\;b \leq -2.9 \cdot 10^{-115}:\\ \;\;\;\;-0.6666666666666666 \cdot \frac{b}{a} + 0.5 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \leq 1.25 \cdot 10^{-100}:\\ \;\;\;\;0.3333333333333333 \cdot \sqrt{\frac{c}{a} \cdot -3}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 8
Error19.6
Cost7112
\[\begin{array}{l} \mathbf{if}\;b \leq -4.5 \cdot 10^{-115}:\\ \;\;\;\;-0.6666666666666666 \cdot \frac{b}{a} + 0.5 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \leq 5 \cdot 10^{-106}:\\ \;\;\;\;\sqrt{c \cdot \frac{-3}{a}} \cdot 0.3333333333333333\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 9
Error22.5
Cost836
\[\begin{array}{l} \mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\ \;\;\;\;-0.6666666666666666 \cdot \frac{b}{a} + 0.5 \cdot \frac{c}{b}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 10
Error22.5
Cost580
\[\begin{array}{l} \mathbf{if}\;b \leq 2.4 \cdot 10^{-271}:\\ \;\;\;\;\frac{0.3333333333333333 \cdot \left(b \cdot -2\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 11
Error22.5
Cost580
\[\begin{array}{l} \mathbf{if}\;b \leq 2.2 \cdot 10^{-271}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 12
Error36.7
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 2.2 \cdot 10^{-271}:\\ \;\;\;\;-0.3333333333333333 \cdot \frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 13
Error22.5
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 2.4 \cdot 10^{-271}:\\ \;\;\;\;b \cdot \frac{-0.6666666666666666}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 14
Error22.5
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 2.4 \cdot 10^{-271}:\\ \;\;\;\;\frac{b}{a} \cdot -0.6666666666666666\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 15
Error40.0
Cost320
\[-0.5 \cdot \frac{c}{b} \]

Error

Reproduce?

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