text: # Sum over multiple indices that take specific values
  
  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.
  
  • I'm not understanding what you mean by p_{1,2,3} as that translates to {p_,2 p_, 3 p_}. But if p_ is really a function that takes a list as an argument, then you might want to try Sum[p[list[[i]]] f[list[[i, 1]], list[[i, 2]], list[[i, 3]]], {i, Length[list]}] which gets you f[1, 2, 3] p[{1, 2, 3}] + f[2, 6, 9] p[{2, 6, 9}] + f[3, 6, 7] p[{3, 6, 7}].
  – JimB
  Jun 9, 2015 at 13:47
  • So $p$ is actually also a function of $a,b,c$? Jun 9, 2015 at 13:51
  • no, $p$ carries indices $a,b,c$ but they are just labels. i edited the question. Jun 9, 2015 at 13:55
  • So $p$ is symbolic and not numerical? Jun 9, 2015 at 14:00
  • If p is subscripted (and using subscripts can have definite but sometimes unexpected consequences), then the following might be what you want: 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 output f[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].
  – JimB
  Jun 9, 2015 at 14:10
  
  Here's one way:
  
  Total[Subscript[p, #] & /@ lst f @@@ lst]
  
  
  or
  
  Total[Subscript[p, #] & /@ lst f /@ lst]
  
  
  But you're probably making a mistake defining your p's this way, especially if you later need to do something with them. If you are willing to define p as a function, then
  
  Total[p @@@ lst f @@@ lst]
  
  
  would work.
  
  • (p @@@ lst).(f @@@ lst) will also work. Jun 9, 2015 at 22:41
metadata: {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}