Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

In a multiple Sum I need to put an automatically generated summation region. But when I generate the summation region automatically I get a list whose elements are lists. Then the summation does not work.

For example:

Sum[1,{i,1,2},{j,1,2}]

works;

Sum[1,{{i,1,2},{j,1,2}}]

or

A = Table[{i[j],j+1},{j,2}];
Sum[1,A]

doesn't work.

share|improve this question
2  
You could use something like Sum[1,Evaluate[Sequence@@{{i,1,2},{j,1,2}}]] –  sebhofer Jul 21 '13 at 21:50

2 Answers 2

As always there are several possibilities. For example

Sum[1,Evaluate[Sequence@@{{i,1,2},{j,1,2}}]]

or

Sum[1, ##] & @@ {{i, 1, 2}, {j, 1, 2}}

both work.

share|improve this answer

The syntax for Sum is wrong. For multiple sums, you list each summation index as a separate argument, not enclosed in a list. For example, instead of

Sum[1,{{i,1,2},{j,1,2}}]

you need to write

Sum[1, {i, 1, 2}, {j, 1, 2}]

(* ==> 4 *)

To modify your last example,

Sum[1,A]

you should do this:

A = Table[{i, j}, {i, 1, 2}, {j, 1, 2}];
Sum[1, {tuple, Flatten[A, 1]}]

(* ==> 4 *)

This assumes that your goal was to have A be a list of tuples i, j.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.