5
$\begingroup$

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_]] :=...

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

2 Answers 2

6
$\begingroup$

One can use

f[x_,y_,z_]/;(Order[x,y]<0) := f[y,x,z];
$\endgroup$
1
  • 3
    $\begingroup$ Or f[x_, y_, z_] /; ! OrderedQ[{x, y}] := f[y, x, z] $\endgroup$
    – Roman
    Commented Sep 15, 2022 at 17:43
6
$\begingroup$

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}

$\endgroup$
2
  • 1
    $\begingroup$ @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]. $\endgroup$
    – march
    Commented Sep 15, 2022 at 16:56
  • $\begingroup$ @march Thanks for your kind explanation and elaboration. $\endgroup$
    – Syed
    Commented Sep 16, 2022 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.