Suppose we want to compute
$$\sum_{k=0}^1 \sum_{j=0}^{2k}{ 2 \choose 2k-j}{2 \choose j}=7$$
with Maple (I picked this trivial example only as an illustration).I always thought that the order of double summation in Maple is the natural one, where limit(s) of the inner sum can depend on the index of the outer sum. But when I enter this in Maple I get
sum(sum(binomial(2,2*k-j)*binomial(2,j),j=0..2*k),k=0..1); 0
sum(sum(binomial(2,2*k-j)*binomial(2,j),k=0..1),j=0..2*k); 7
Why the first computation returns $0$ and the second gives the correct answer?
Edit: On the other hand,
sum(sum(m,m=1..k),k=0..10); 100
as expected and
sum(sum(m,k=0..10),m=1..k); $11(k+1)^2/2-11k/2-11/2$
also as expected (it runs the k-summation from 1 to k 11 times).
If your goal is to add up a finite number of terms then you could use
addinstead ofsum.Note that
addhas 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 toadd.In contrast,
sumis evaluated using Maple's regular evaluation rules, and its first argument is evaluated up front. In your first example, before indexkattains a specific value (from the second argument, the range), the first argument of the outer call tosumis evaluated. That is to say, the inner call tosumis evaluated up front.and then the outer call to
sumis computed,For this particular example you could delay the evaluation of the inner call to
sum, untilkgets its particular numeric values.Or you could delay the evaluation of the first argument of the inner call to
sum, to the extent that the result of the outersumcall requires anevalto complete the computation.Note that some of these workarounds/kludges are quite problem specific.
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:
Or,
Nesting the other way, you get a rather "fortuitous" result.
And now something interesting. In version Maple 11.02 the following obtains, and seems somewhat useful,
while in Maple 12.02 through Maple 2015.1 one gets,
which is interesting in light of,
Your other examples' results can also be seem to be a consequence of the usual evaluation rules of Maple which
sumfollows.