3
$\begingroup$

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).

$\endgroup$
2

1 Answer 1

4
$\begingroup$

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 
$\endgroup$
1
  • 1
    $\begingroup$ This is very helpful. Thanks! $\endgroup$
    – Jeffrey
    Oct 14, 2015 at 20:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .