12

Mathematica refuses to evaluate this summation.

Sum[2^(k + 1)^3 - 2^(k - 1)^3, {k, 0, n}]

It just returns the form unevaluated.

$\sum _{k=0}^n \left(2^{(k+1)^3}-\ 2^{(k-1)^3}\right)$

Is there some special command for this case? I think it should evaluate because it is telescopic.

EDIT :Hi, This summation can be evaluated by hand, but Mathematica refuses to evaluate it, how should I write the command so that it gives me a result? my mathemativa is version 10.410

zeros
  • 2,263
  • 1
  • 14
  • 18

4 Answers4

8

The problem with telescoping sums is recognizing how many terms are needed before the cancellation is going to start happening. The built-in method only tries to see if cancellation occurs in adjacent terms. If the gap before cancellation is two terms or greater, then the built-in method fails and the sum is not evaluated. It's easy enough to extend the method, but apparently the user has to do this for themselves.

Here's a way to extend the built-in method to longer gaps (based on the code for sumFiniteTelescoping):

clearSumCache[] := DownValues@Sum`SumParserDump`sumParserEvaluate = 
   DownValues[Sum`SumParserDump`sumParserEvaluate][[-2 ;;]];

clearSumCache[];  (* sum results are cached, so either Quit[] or clear the cache *)

mySum`sumFiniteTelescopingMaxGap = 3;
Internal`InheritedBlock[{Sum`FiniteSumDump`sumFiniteTelescoping},
 Sum`FiniteSumDump`sumFiniteTelescoping[expr_, {k_, min_ : 1, max_}] /;
    Head[expr] == Plus && Length[expr] == 2 := 
  Module[{test, lim1, lim2, tgap, idx},
   test = False; tgap = 0;
   While[! test && tgap < mySum`sumFiniteTelescopingMaxGap,
    tgap++;
    test =
     PossibleZeroQ[idx = 1; Together[(expr[[1]] /. {k -> k+tgap}) + expr[[2]]]] || 
      PossibleZeroQ[idx = 2; Together[(expr[[2]] /. {k -> k+tgap}) + expr[[1]]]];
    ];
   dbPrint[tgap];
   (lim1 = Quiet[expr[[idx]] /. Table[{k -> k0}, {k0, min, min+tgap-1}] // Total];
     (lim2 =
        Quiet[expr[[3-idx]] /. Table[{k -> k0}, {k0, max-tgap+1, max}] // Total];
       lim1 + lim2 /;
        FreeQ[lim2, Indeterminate | DirectedInfinity]) /;
      FreeQ[lim1, Indeterminate | DirectedInfinity]) /;
    test === True];

 Sum[2^(k + 1)^3 - 2^(k - 1)^3, {k, 0, n}]
 ]
(*  -(3/2) + 2^n^3 + 2^(1 + n)^3  *)

[Edit: Refactored the following.] Another approach is to use the above algorithm with plug-in Method option:

ClearAll[myFiniteTelescoping, getFiniteTelescopingSum];
$myFiniteTelescopingMaxGap = 3;

getFiniteTelescopingSum[e1_, e2_, k_, min_, max_, offset_] /;
   PossibleZeroQ[Together[(e1 /. {k -> k + offset}) + e2]] :=
  Module[{lim1, lim2},
   (lim1 = Quiet[e1 /. Table[{k -> k0}, {k0, min, min + offset - 1}] // Total];
    (lim2 = Quiet[e2 /. Table[{k -> k0}, {k0, max - offset + 1, max}] // Total];
      lim1 + lim2 /;
       FreeQ[lim2, Indeterminate | DirectedInfinity]) /;
     FreeQ[lim1, Indeterminate | DirectedInfinity])
   ];
getFiniteTelescopingSum[___] := $Failed;

myFiniteTelescoping[expr_, {k_, min_: 1, max_}] /; 
   Head[expr] == Plus && Length[expr] == 2 := 
  Module[{tgap, res},
   tgap = 1; res = $Failed;
   While[res === $Failed && tgap <= $myFiniteTelescopingMaxGap,
res = getFiniteTelescopingSum[expr[[1]], expr[[2]], k, min, max, tgap];
If[res === $Failed,
     res = getFiniteTelescopingSum[expr[[2]], expr[[1]], k, min, max, tgap]];
    tgap++
    ];
   res /; FreeQ[res, $Failed]];
myFiniteTelescoping[___] := $Failed;

Examples:

Sum[2^(k + 1)^3 - 2^(k - 1)^3, {k, 0, n}, Method -> myFiniteTelescoping]
(*  -(3/2) + 2^n^3 + 2^(1 + n)^3  *)

(* Fails because gap is too great *)
Sum[2^(k + 3)^3 - 2^(k - 1)^3, {k, 0, n}, Method -> myFiniteTelescoping]
(*  Sum[-2^(-1 + k)^3 + 2^(3 + k)^3, {k, 0, n}, Method -> myFiniteTelescoping]  *)

(* Succeeds if we raise the max gap checked *)
Block[{myFiniteTelescopingMaxGap = 5}, 
 Sum[2^(k + 3)^3 - 2^(k - 1)^3, {k, 0, n}, Method -> myFiniteTelescoping]]
(*  -(519/2) + 2^n^3 + 2^(1 + n)^3 + 2^(2 + n)^3 + 2^(3 + n)^3  *)
Michael E2
  • 235,386
  • 17
  • 334
  • 747
6
(sum1 = Sum[2^(k + 1)^3 - 2^(k - 1)^3, {k, 0, n}]) // TraditionalForm

enter image description here

Separate into two sums

(sum2 = sum1 /. Sum[f_, iter_] :> (Sum[#, iter] & /@ f)) // TraditionalForm

enter image description here

Translate indices

(sum3 = Sum[-2^(k - 1)^3 /. k -> k + 1, {k, -1, n - 1}] + 
    Sum[2^(k + 1)^3 /. k -> k - 1, {k, 1, n + 1}]) // TraditionalForm

enter image description here

Combine sums and cancel like terms with different signs

(sum = Sum[-2^(k^3), {k, -1, 0}] + 
    Sum[2^(k^3), {k, n, n + 1}]) // TraditionalForm

enter image description here

Numerically verifying,

And @@ Table[sum == sum1, {n, 0, 100}]

(* True *)
Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
  • Thank you very much, although I still have the doubt because Mathematica can not solve the sum directly – zeros Nov 10 '18 at 01:48
3

Getting the indices right and simplified depends on what values are known. If you are interested in sums of the form

$$\sum _{k=0}^n (f (k+\delta_1)-f (k+\delta_2))$$

where $\delta_1$ and $\delta_2$ are arbitrary integers and $n \geq 0$, then the following function will produce a (usually) simplified formula:

sum[δ1_, δ2_, n_] := Module[{δmin, δmax},
  {δmin, δmax} = MinMax[{δ1, δ2}];
  Sign[δ1 - δ2] (Sum[f[k], {k, n + δmin + 1, n + δmax}] - Sum[f[k], {k, δmin, δmax - 1}])]

For example, consider

sum[1, -1, n]
(* -f[-1] - f[0] + f[n] + f[1 + n] *)

If we define $f$ as in the question:

f[k_] := 2^k^3
sum[1, -1, n]

$$2^{n^3}+2^{(n+1)^3}-\frac{3}{2}$$

In general using

sum[δ1, δ2, n]

gets you

General formula

JimB
  • 41,653
  • 3
  • 48
  • 106
0

Adding additional parenthesis eliminates problems and becomes easy to evaluate.

Table[Sum[2^((k + 1)^3) - 2^((k - 1)^3), {k, 0, n}], {n, 0, 20}] 

works as expected. Evaluating the terms of the series and its proposed solution by use of

Table[Sum[2^((k + 1)^3) - 2^((k - 1)^3), {k, 0, n}] - (2^(n^3) + 2^((n + 1)^3) - 3/2), {n, 0, 20}] 

produces a string of zeros.

Leucippus
  • 365
  • 2
  • 4
  • 14