I have an expression like this,
input = x[1] x[2]^3 x[5]^2;
Fist step, we can get a list from the input expression,
list0={x[1],x[2],x[2],x[2],x[5],x[5]};
list1 = {1, 2, 2, 2, 5, 5};
Second step, I want to get all possible pairs in a new list2. Namely, we divide Length[list1]/2 parts in list1 and combine the possible sublist in a new list. Of course, Length[list1]===Even.
list2 = {{{1, 2}, {2, 2}, {5, 5}}, {{1, 2}, {2, 5}, {2, 5}} , {{1, 5}, {2, 2}, {2, 5}}};
Last step, we get the output expression,
output = f[1, 2] f[2, 2] f[5, 5] + f[1, 2] f[2, 5]^2 + f[1, 5] f[2, 2] f[2, 5];
How can I transform the input expression into the output result? Can you show me a simple method that will work for the general problem as well as my example?
In addition, we take another example,
list1 = {1, 1, 2, 4};
the list2 should be
list2 = {{1, 1}, {2, 4}}, {{1, 2}, {1, 4}};

list2into three sublists? – s0rce Mar 11 at 14:05list1andlist2is not obvious to me. Could you give some further explanation? – m_goldberg Mar 11 at 14:09list2is derived the bothers me. – m_goldberg Mar 11 at 14:17Tuples[list1, 2] // Union, yielding{{1, 1}, {1, 2}, {1, 5}, {2, 1}, {2, 2}, {2, 5}, {5, 1}, {5, 2}, {5, 5}}– David Carraher Mar 11 at 14:28