Author 
Comment/Response 
Brian

02/08/13 00:11am
I recently discovered the function "apply", which has really helped me deal with sums over unspecified numbers of variables, eg:
Apply[ Sum, Flatten[ { f[m] , Table[ {m[[j]],0,n} , {j,1,N}] , 1] ]
This gives a sum of the function f[m] over N variables m[[1]],...,m[[N]]].
The problem I'm having is very technical, but necessary for the application I have. Here's a simplified example that illustrates the problem:
Input:
z = {z1, z2};
Sum[ Product[ If[m > 0, z[[i]], 1] , {i, 1, 2}], {m, 0, 1}]
Apply[ Sum , {Product[ If[m > 0, z[[i]], 1], {i, 1, 2}], {m, 0, 1}}]
Output:
1 + z1 z2
1 + {z1, z2}[[i]]^2
Obviously I don't need to use apply for this simple example, but the problem I'm actually doing requires sums over arbitrarily many variables. I have only had this kind of problem with such a product containing an if statement. Can someone explain why the two lines are not identical, as I thought they should be?
URL: , 
