# Declare a function with symmetric arguments

I have a package that contains a function f[a_,b_,c_] which is explicitly symmetric but only in its first two arguments. How do I make Mathematica simplify things such that

(f[x,y,z] + f[y,x,z])//FullSimplify = 2f[x,y,z]

Even better would be a general function to declare which arguments are symmetric and antisymmetric...

Note: the function is not defined to do anything with those arguments, i.e. in the package I've only defined it via a Format[f[a_,b_,c_]] :=...

• SetAttributes[f, Orderless] and f[x, y, z] + f[y, x, z] ??
– Syed
Commented Sep 15, 2022 at 14:16
• I am not sure if I understood but this might be a duplicate of this question Commented Sep 15, 2022 at 15:30

One can use

f[x_,y_,z_]/;(Order[x,y]<0) := f[y,x,z];

• Or f[x_, y_, z_] /; ! OrderedQ[{x, y}] := f[y, x, z] Commented Sep 15, 2022 at 17:43

Try this:

f[OrderlessPatternSequence[x_, y_], z_] := {x, y, z}

f[x, y, z] + f[y, x, z]


{2 x, 2 y, 2 z}

f[x, y, z] + f[y, z, x]


{x + y, y + z, x + z}

• @Akoben. Try the various results of f[OrderlessPatternSequence[x_, y_], z_] := ff[x, y, z] (with ff undefined). You will see that f[x, y, z] + f[x, z, y] becomes ff[x, y, z] + ff[x, z, y] but f[x, y, z] + f[y, x, z] becomes 2*ff[x, y, z]. Commented Sep 15, 2022 at 16:56
• @march Thanks for your kind explanation and elaboration.
– Syed
Commented Sep 16, 2022 at 7:19