Pretty simple question: how do I sum over multiple indices that can only take specific values all together?
To clarify: let's say I have the following sum:
$\sum p_{a,b,c} f(a,b,c)$
where $f$ is a function and $p$ is a coefficient (number) still in symbolic form, both dependent on indices $a,b,c$. Here {$a$, $b$, $c$} can take values specified by a list of three numbers, like {1,2,3}, {3,6,7} and so on. My idea is that I have a list of triplets, and I would like the sum to run on these triplets by assigning $a$ to the first number, $b$ to the second and $c$ to the third. So let's say that for a list of triplets
list={{1,2,3},{3,6,7},{2,6,9}}
The outcome should be
$p_{1,2,3}f[1,2,3]+p_{2,6,9}f[2,6,9]+p_{3,6,7}f[3,6,7]$
I was able to do it with Apply
if there was only a function, but the coefficients $p$ need to carry the indices so it becomes tricky.
p_{1,2,3}
as that translates to{p_,2 p_, 3 p_}
. But ifp_
is really a function that takes a list as an argument, then you might want to trySum[p[list[[i]]] f[list[[i, 1]], list[[i, 2]], list[[i, 3]]], {i, Length[list]}]
which gets youf[1, 2, 3] p[{1, 2, 3}] + f[2, 6, 9] p[{2, 6, 9}] + f[3, 6, 7] p[{3, 6, 7}]
. $\endgroup$Sum[Subscript[p, list[[i, 1]], list[[i, 2]], list[[i, 3]]] f[list[[i, 1]], list[[i, 2]], list[[i, 3]]], {i, Length[list]}]
with outputf[1, 2, 3] Subscript[p, 1, 2, 3] + f[2, 6, 9] Subscript[p, 2, 6, 9] + f[3, 6, 7] Subscript[p, 3, 6, 7]
. $\endgroup$