Pensieve header: A draft permutations package for March 28, 2016.

BeginPackage["Permutations`"]

PP::usage = "PP[a,b,..] gives the product of the permutations a,b,...";
IP::usage = "IP[a] gives the inverse permutation of a.";
PS::usage = "PS[a] gives the support of the permutation a (its domain, minus the set of its fixed points).";
PR::usage = "PR[expr, a] applies the permutation a to all integers appearing in expr.";

Begin["`Private`"]

PP[a_List] := a;
PP[a_List, b_List] := b[[a]];
PP[a_List, rest__List] := PP[a,PP@rest];

Exercise: Can you reduce the above to just two lines?

IP[a_List] := (t=0a; Do[t[[a[[i]]]]=i, {i,Length@a}]; t)

PS[a_] := Select[a, #≠a[[#]]&]

PR[expr_,a_List] := expr /. Table[i->a[[i]], {i,a}]

PR[expr_,a_List] := expr /.Thread[a -> a[[a]]]

End[]; EndPackage[]

To do

?PermutationList

?PermutationCycles

?Permutation

Use the head “Permutation” to represent permutations!
Use old operation names “PermutationProduct”, “InversePermutation”, “PermutationSupport”, “PermutationReplace”!
Allow mixing old and new notations!