# Groupings: orderless version?

Consider the following groupings code:

Groupings[IntegerPartitions, {A -> 2, B -> 2}]


This generates:

 {A[2, 1], B[2, 1], A[A[1, 1], 1], A[1, A[1, 1]], A[B[1, 1], 1],
A[1, B[1, 1]], B[A[1, 1], 1], B[1, A[1, 1]], B[B[1, 1], 1],
B[1, B[1, 1]]}


In other words, the expressions with heads A and heads B over the arguments given by integer partition are generated.

These expressions correspond to expression trees of which Orderless versions can be obtained (Orderless" in the sense of Mathematica, for trees, i.e. essentially trees identified up to permutations of children of a node).

Is there an Orderless version for Groupings?

I tried something like:

    Groupings[IntegerPartitions, {A -> 2, B -> 2}, Orderless]


Or:

    Groupings[IntegerPartitions, {A -> 2, B -> 2, Orderless}]


both of which produce errors.

I would like to obtain an efficient way to only keep Orderless versions of the expressions'' (as determined by the orderless versions of their expression trees).

Note that a distinction of heads matters, i.e. A and B are not interchangeable).

• what is the desired output for your example?
– kglr
Jun 19, 2019 at 20:26
• does SetAttributes[{A,B}, Orderless] work?
– kglr
Jun 19, 2019 at 20:28
• ... or Groupings[IntegerPartitions, {foo -> 2, bar -> 2}, Sort]?
– kglr
Jun 19, 2019 at 20:36
• Sort won't do it as it keeps copies of identical trees (generated by Sort). I found the answer though, copied below Jun 19, 2019 at 20:49

Groupings[IntegerPartitions, {A -> {2, Orderless}, B -> {2, Orderless}}]

 {A[2, 1], B[2, 1], A[A[1, 1], 1], A[B[1, 1], 1], B[A[1, 1], 1],