0
$\begingroup$

Suppose I want to sum a function, $f(\{m_a\})$, of several variables, $m_a$, $a=1,..,n$, which run over ranges, $1,...,k[[a]]$, however, I do not know $n$ in advance. I thought I could do this using ``Apply,'' namely:

Apply[Sum,Join[{f[Table[Subscript[m,a],{a,1,n}]]},Table[{Subscript[m,a],1,k[[a]]},{a,1,n}]]]

However, I'm running into the following problem. The function $f$ is getting called only once, at the argument ``$\{m_a\}$'', ie, before assigning them the numerical values being summed over. If the function requires numerical inputs, this won't run properly. However, if I write the corresponding Sum by hand (ie, in cases where I know in advance what $n$ is), then $f$ is called for each term in the sum, and there is no problem. How can I make this sum behave as I'd like for arbitrary $n$?

New contributor
bibbitt is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$
0
$\begingroup$

I was able to find a solution, which is instead to use:

Sum[f[Table[Subscript[m,a],{a,1,n}]],Evaluate[Sequence@@Table[{Subscript[m,a],1,k[[a]]},{a,1,n}]]]

Although I'm still curious why the previous method doesn't work.

New contributor
bibbitt is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$

Your Answer

bibbitt is a new contributor. Be nice, and check out our Code of Conduct.

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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