Function Repository Resource:

ParityPairings

Source Notebook

List all possible partitions of a list into disjoint pairs

Contributed by: Bradley Klee

ResourceFunction["ParityPairings"][items]

lists all partitionings of items into disjoint pairs matching each single item once to any other or to itself.

Details

If items has length n, each output partitioning has dimensions {k,2}, where n/2kn.
Each item from items appears exactly once as a member of a non-identical pair {l,m} or exactly twice as both members of an identical pair {m,m}.
When the items are chosen to be a range of numbers 1, 2, …, n, ResourceFunction["ParityPairings"] lists involutions of length n almost in Cycles notation, except that fixed indices are also listed as pairs {m,m}.

Examples

Basic Examples (2) 

The only pairing of one item is the Identity:

In[1]:=
ResourceFunction["ParityPairings"][{\[FormalA]}]
Out[1]=

Two items admit two distinct pairings:

In[2]:=
ResourceFunction["ParityPairings"][{\[FormalA], \[FormalB]}]
Out[2]=

Alternatively, items can also be entered as integers:

In[3]:=
ResourceFunction["ParityPairings"][{1, 2}]
Out[3]=

Properties and Relations (2) 

Compare with the result of the resource function Involutions:

In[4]:=
Function[{ind}, SameQ[ResourceFunction["ParityPairings"][Range[ind]],
   Map[Sort, ResourceFunction["Involutions"][ind, "Cycles"] /. {x_Integer} :> {x, x}, {0, 1}]
   ]] /@ Range[10]
Out[4]=

Plot the relative time savings:

In[5]:=
ListPlot[
 Function[{ind}, Divide[
      2 Apply[Subtract, #],
      Apply[Plus, #]
      ] &@{AbsoluteTiming[
       ResourceFunction["Involutions"][ind, "Cycles"]][[1]],
     AbsoluteTiming[
       ResourceFunction["ParityPairings"][Range[ind]]][[1]] }] /@ Range[10], PlotRange -> {0, 2}]
Out[5]=

Neat Examples (1) 

Count the number of distinct involutions on n letters (cf. OEIS A000085):

In[6]:=
Length[ResourceFunction["ParityPairings"][Range[#]]] & /@ Range[7]
Out[6]=

Publisher

Brad Klee

Version History

  • 1.0.0 – 27 September 2022

Related Resources

License Information