Question: How to get cylic sum and symmetric sum

Hi all, how to write function to get cylic sum and symmetric sum

Example.

getSum(a, [a,b,c]) then return a + b + c,
getSum(a^2, [a,b,c]) then return a^2 + b^2 + c^2,
getSum(a^2b, [a,b,c]) then return a^2b + b^2c + c^2a,
getSum(a, [a,b,c,d]) then return a + b + c + d,
getSum(a^2b, [a,b,c,d]) then return a^2b + b^2c + c^2d + d^2a
getSum(ab, [a,b,c,d]) then return ab + ac + ad + bc + bd + cd.

Thank you very much.

Please Wait...