# Apply all possible permutations into a function [duplicate]

I need to create a function that returns all possible trebles of integers that sum up to a given number. For example, is n=2 then I need something like this: f[12,-5,5] or f[7,-4,-1] etc

For that reason I have written the following:

n = 2;

Sum[f[n - i - j, i, j], {i, -5, n}, {j, -5, n - i}]


which outputs:

f[0, -5, 7] + f[0, -4, 6] + f[0, -3, 5] + f[0, -2, 4] + f[0, -1, 3] +
f[0, 0, 2] + f[0, 1, 1] + f[0, 2, 0] + f[1, -5, 6] + f[1, -4, 5] +
f[1, -3, 4] + f[1, -2, 3] + f[1, -1, 2] + f[1, 0, 1] + f[1, 1, 0] +
f[1, 2, -1] + f[2, -5, 5] + f[2, -4, 4] + f[2, -3, 3] + f[2, -2, 2] +
f[2, -1, 1] + f[2, 0, 0] + f[2, 1, -1] + f[2, 2, -2] + f[3, -5, 4] +
f[3, -4, 3] + f[3, -3, 2] + f[3, -2, 1] + f[3, -1, 0] +
f[3, 0, -1] + f[3, 1, -2] + f[3, 2, -3] + f[4, -5, 3]


My problem is that for each part of this summation I also need the permutations

for example for f[0,-5,7] I need these:

f[0, -5, 7], f[0, 7, -5], f[-5, 0, 7], f[-5, 7, 0], f[7, 0, -5], f[7, -5,
0]


My problem is that I don't know how to map it:

Using

f /@ Permutations[{0, -5, 7}]


returns a form that I cannot use

{f[{0, -5, 7}], f[{0, 7, -5}], f[{-5, 0, 7}], f[{-5, 7, 0}],
f[{7, 0, -5}], f[{7, -5, 0}]}


f is a probability density function, and I need to sum the probabilities for given numbers, hence I need to be able to evaluate f.

• try f @@@ Permutations[{0, -5, 7}] – kglr Dec 28 '17 at 10:17
• I think it is a valid duplicate but let me know if you disagree with closing. – Kuba Dec 28 '17 at 10:30
• @Kuba kglr's proposal has helped me in order to create the map for each treble, so I just need to gather all of them into a single list. His solution is similar to the link you have provided, hence it is a possible duplicate indeed. Proceed according to regulations, thanks for your assistance. – Tom Zinger Dec 28 '17 at 10:36
• Here is another closely related one: 27856 – Kuba Dec 28 '17 at 10:56