Pensieve header: A (failed) permutations package for March 28, 2016.

BeginPackage["Permutations`"]

Permutation::usage = "Permutation[i1,i2,...] represents a permutation mapping 1->i1,2->i2,...";

Begin["`Private`"]

Permutation /: PermutationProduct[a_Permutation] := a;
Permutation /: PermutationProduc[a_Permutation, b_Permutation] := b[[List@@a]];
(*Permutation /: PermutationProduct[a_Permutation, rest__Permutation] := PermutationProduct[a,PermutationProduct@rest];*)

PermutationProduct[Permutation[1,3,2]]

PermutationProduct[Permutation[1,3,2],Permutation[2,3,1]] // Trace // Take[#,40]& // FullForm

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

1+1

?PermutationList

?PermutationCycles

?Permutation

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