(* ::Package:: *)

(* ::Input:: *)
(*BeginPackage["Perm`"];*)
(*Perm::usage="Perm[5,2,3,1,4] means the permutation that maps 1\[RightArrow]5, 2\[RightArrow]2, 3\[RightArrow]3, 4\[RightArrow]1, 5\[RightArrow]4. Perm[c] may also be used to convert a permutation c from cycles into standard form";*)
(*ComposePerm::usage="ComposePerm[\[Sigma],\[Tau]] where \[Sigma] and \[Tau] are permutations returns the permutation obtained by composing \[Sigma] and \[Tau] where both \[Sigma] and \[Tau] may be in cycle form or standard form. Alternatively ComposePerm[\[Sigma],A] will return the expression obtained by applying permutation \[Sigma] to expression A. The alternate notation is \[Sigma]\[SmallCircle]\[Tau]";*)
(*PermPower::usage="PermPower[\[Tau],n] returns the permutaiton obtained by taking \[Tau] to n-th power. Alternate notation is \!\(\*SuperscriptBox[\(\[Tau]\), \(n\)]\)";*)
(*PermutationQ::usage="PermutationQ[\[Tau]] Returns True if \[Tau] is a permutation and false otherwise";*)
(*IdentityPerm::usage="IdenityPerm[n] returns the identity permution of length n";*)
(*FindPerm::usage="FindPerm[a,b] returns the permutation that takes expression a to expression b";*)
(*RandomPerm::usage="RandomPerm[n] returns a random permutation of length n";*)
(*PermList::usage="PermList[n] creates a list of all permutations of length n";*)
(*PermOrder::usage="PermOrder[\[Tau]] returns the order of a permutation";*)
(**)
(**)
(*Begin["`private`"];*)
(**)
(*PermutationQ[\[Sigma]_Perm]:=Sort[List@@\[Sigma]]===Range[Length[\[Sigma]]];*)
(*Perm/:\[Sigma]_Perm\[SmallCircle]\[Tau]_Perm/;Length[\[Sigma]]==Length[\[Tau]]:=\[Sigma][[List@@\[Tau]]];*)
(*Perm/:(\[Sigma]_Perm)^0/;PermutationQ[\[Sigma]]:=IdentityPerm[Length[\[Sigma]]];*)
(*Perm/:(\[Sigma]_Perm)^n_Integer/;PermutationQ[\[Sigma]]\[And] n>=1:=\[Sigma]\[SmallCircle]\[Sigma]^(n-1);*)
(**)
(*Perm/:(\[Sigma]_Perm)^-1/;PermutationQ[\[Sigma]]:=\:f000 \[Tau]=\[Sigma];*)
(*Do[\[Tau][[\[Sigma][[i]]]]=i,{i,Length[\[Sigma]]}];*)
(*\[Tau]*)
(*\:f006;*)
(**)
(*IdentityPerm[n_Integer]:=Perm@@Range[n]*)
(**)
(*Perm/:(\[Sigma]_Perm)^n_Integer/;PermutationQ[\[Sigma]]\[And] n<= -1:=(\[Sigma]^-n)^-1;*)
(**)
(*Perm[c_Cycles]:=(\[Tau]1=Range[Max[List@@c]];*)
(*For[i=1,i<=Length[c[[1]]],i++,*)
(*For[j=1,j<= Length[c[[1]][[i]]],j++,*)
(*\[Tau]1=ReplacePart[\[Tau]1,c[[1]][[i]][[j]]->c[[1]][[i]][[If[j==Length[c[[1]][[i]]],1,j+1]]]];*)
(*]*)
(*];*)
(*Perm@@\[Tau]1*)
(*)*)
(**)
(*\[Sigma]_Perm\[SmallCircle]\[Tau]_Cycles/;Length[\[Sigma]]==Length[Perm[\[Tau]]]:=\[Sigma]\[SmallCircle]Perm[\[Tau]];*)
(*\[Tau]_Cycles\[SmallCircle]\[Sigma]_Perm/;Length[\[Sigma]]==Length[Perm[\[Tau]]]:=Perm[\[Tau]]\[SmallCircle]\[Sigma];*)
(**)
(*\[Tau]_Perm\[SmallCircle]\[Sigma]_/;Length[\[Sigma]]==Length[\[Tau]]:=\[Sigma][[List@@\[Tau]]];*)
(**)
(*ComposePerm[\[Sigma]_,\[Tau]_]:=\[Sigma]\[SmallCircle]\[Tau]*)
(*PermPower[\[Tau]_Perm,n_Integer]:=\[Tau]^n*)
(**)
(*FindPerm[a_,b_]/;Sort[a]==Sort[b]And Length[Union[a]]==Length[a]And Length[Union[b]]==Length[b] :=Perm@@Table[Position[a,n][[1]][[1]],{n,b}]*)
(**)
(*RandomPerm[n_Integer]:=Module[{list=Range[n],a,\[Tau]2={}},*)
(*For[i=1,i<=n,i++,*)
(*a=RandomChoice[list];*)
(*\[Tau]2=Append[\[Tau]2,a];*)
(*list=DeleteCases[list,a]*)
(*];*)
(*Perm@@\[Tau]2*)
(*];*)
(**)
(*PermOrder[p_Perm]:=(\[Tau]3=p;For[n=1,List@@\[Tau]3!=Range[Length[p]],n++,\[Tau]3=\[Tau]3\[SmallCircle]p];*)
(*n*)
(*)*)
(**)
(*PermList[1]:={Perm[1]}*)
(*PermList[n_Integer]:=Flatten@Table[Insert[i,n,j],{i,PermList[n-1]},{j,Range[n]}]*)
(**)
(**)
(*End[];EndPackage[];*)
