Output function control and manipulation for efficient computation [closed]

I have taken note of a similar post related to modifying function parameters. I tried to adapt Kuba's solution to this post but I can't get it to work. I will illustrate my problem using a similar notation used in the other post.

I have a function, $f$, that has an arbitrary, but even number of arguments; i.e. $f(A,B,C,D,E,F)$. The parameters $A,B,C,D,E,F$ actually represent variables which I integrate over. Now two different variables may be switched, but the evaluation of the integration of such a function will not change since all we have done is switch the 'dummy' variable.

So I have a function that generates a lot of these such functions and I want Mathematica to use this to simplify the output. For example, if I have as the output of my function:

expr1 = f[2, 2, 1, 3, 3, 1] + f[2, 2, 3, 1, 1, 3] +
f[3, 3, 1, 2, 2, 1] + f[1, 1, 2, 3, 3, 2];

I want mathematica to generate the output:

4f(1,1,2,3,3,2)

Since the integration of all of these functions will be the same. Of course, more than 1 switch of variables can be made. The number of arguments can increase to an arbitrary even number. Additionally, any pair of arguments can be switched EXCEPT the last pair. i.e.

expr2 = f[1, 3, 2, 2, 3, 1] + f[2, 2, 1, 3, 3, 1] + f[2, 2, 3, 1, 1, 3]

should give:

2f(2,2,1,3,3,1) + f(2,2,3,1,1,3)

Since the first two functions are the same but the third is not - since the last pair in the third function has been switched by the second pair (compared to the second pair). So any pair can be switched BUT not the last pair of arguments.

Writing a function that acknowledges that these functions are the same enables a reduced number of integration evaluation - important when each integration takes long to evaluate.

Thanks very much for your help.

closed as unclear what you're asking by Michael E2, Sjoerd C. de Vries, Dr. belisarius, rcollyer, m_goldbergApr 28 '15 at 17:24

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• SetAttributes[f, Orderless];f[2, 2, 1, 3, 3, 1] + f[2, 2, 3, 1, 1, 3] + f[3, 3, 1, 2, 2, 1] + f[1, 1, 2, 3, 3, 2] solves the first part – Dr. belisarius Feb 18 '15 at 20:22
• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – user9660 Feb 18 '15 at 20:26
• At the end I don't know if my answer was of any help so I removed it. – Kuba Feb 19 '15 at 16:03
• Your first example and the additional requirement for your second example are inconsistent. Please clarify. – Michael E2 Apr 28 '15 at 14:23

Here is a way.

For example you can define :

f1[x__, p1_, p2_] := f2[x][p1, p2]
SetAttributes[f2, Orderless];

f3[x__][p1_, p2_] := f[x, p1, p2]

Test

Your initial output can be generated this way :

myargs = {{2, 2, 1, 3, 3, 1}, {1, 3, 2, 2, 3, 1}, {2, 2, 3, 1, 1, 3}};
mysum = Plus @@ f @@@ myargs

f[1, 3, 2, 2, 3, 1] + f[2, 2, 1, 3, 3, 1] + f[2, 2, 3, 1, 1, 3]

Then

mysum /. f -> f1

f2[1, 2, 2, 3][1, 3] + 2 f2[1, 2, 2, 3][3, 1]

mysum /. f -> f1 /. f2 -> f3

f[1, 2, 2, 3, 1, 3] + 2 f[1, 2, 2, 3, 3, 1]