If your goal is to add up a finite number of terms then you could use add
instead of sum
.
restart;
add(add(binomial(2,2*k-j)*binomial(2,j), j=0..2*k), k=0..1);
7
Note that add
has special evaluation rules in Maple, and its first argument is not evaluated until the index attains a numeric value. In this case that applies to both the outer and inner calls to add
.
In contrast, sum
is evaluated using Maple's regular evaluation rules, and its first argument is evaluated up front. In your first example, before index k
attains a specific value (from the second argument, the range), the first argument of the outer call to sum
is evaluated. That is to say, the inner call to sum
is evaluated up front.
sum(binomial(2,2*k-j)*binomial(2,j), j=0..2*k);
0
and then the outer call to sum
is computed,
sum(%, k=0..1);
0
For this particular example you could delay the evaluation of the inner call to sum
, until k
gets its particular numeric values.
sum('sum(binomial(2,2*k-j)*binomial(2,j),j=0..2*k)',k=0..1);
7
sum('sum'(binomial(2,2*k-j)*binomial(2,j),j=0..2*k),k=0..1);
7
Or you could delay the evaluation of the first argument of the inner call to sum
, to the extent that the result of the outer sum
call requires an eval
to complete the computation.
sum(sum(''binomial(2,2*k-j)*binomial(2,j)'',j=0..2*k),k=0..1);
3 '1' + '4'
eval(%);
7
Note that some of these workarounds/kludges are quite problem specific.
Z := sum(binomial(2,2*k-j)*binomial(2,j), j=A..B):
ZZ := limit( limit(Z, B=2*k), A=0):
sum(ZZ, k=0..1);
7
These results are from version Maple 2015.1. Using version Maple 11.02 that last command returns an error about the summand being singular in the interval of summation. But in both versions the following obtains:
eval(ZZ,k=0);
Error, (in GAMMA) numeric exception: division by zero
eval(ZZ,k=1);
Error, (in GAMMA) numeric exception: division by zero
limit(ZZ,k=0) + limit(ZZ,k=1);
7
limit( limit(Z, A=0), B=2*k):
sum(%, k=0..1);
7
Or,
Q := sum(binomial(2,2*k-j)*binomial(2,j), j=0..M):
eval(Q, M=2*k);
Error, numeric exception: division by zero
limit(Q, M=2*k);
6 binomial(2, 2 k)
------------------
2
2 k - 7 k + 6
sum(%, k=0..1);
7
Nesting the other way, you get a rather "fortuitous" result.
P := sum(binomial(2,2*k-j)*binomial(2,j), k=0..1);
P := binomial(2, -j) binomial(2, j) + binomial(2, 2 - j) binomial(2, j)
sum(P, j=0..2*k);
7
And now something interesting. In version Maple 11.02 the following obtains, and seems somewhat useful,
sum(P, j=0..M); # M is unassigned
7-binomial(2,M+1)*(binomial(2,-M-1)+binomial(2,1-M))
*hypergeom([1, M-1, M-1, 2-I*2^(1/2)+M, 2+I*2^(1/2)+M],
[2+M, 4+M, 1-I*2^(1/2)+M, 1+I*2^(1/2)+M],1)
while in Maple 12.02 through Maple 2015.1 one gets,
sum(P, j=0..M); # M is unassigned
7
which is interesting in light of,
sum(P, j=0..1);
6
add(P, j=0..1);
6
Your other examples' results can also be seem to be a consequence of the usual evaluation rules of Maple which sum
follows.
sum(m, m=1..k);
1 2 1 1
- (k + 1) - - k - -
2 2 2
sum(%, k=0..10);
220
sum(m, k=0..10);
11 m
sum(%, m=1..k);
11 2 11 11
-- (k + 1) - -- k - --
2 2 2