Here's a streamlined version of it: With[{m = 5, k = 3}, indices = Flatten[Permutations /@ IntegerPartitions[5, {3}], 1] ]; Dot[##, v] & @@@ Map[s, indices, {2}] // Total (* s[1].s[1].s[3].v + s[1].s[2].s[2].v + s[1].s[3].s[1].v + s[2].s[1].s[2].v + s[2].s[2].s[1].v + s[3].s[1].s[1].v *)