(* ::Package:: *)

(************************************************************************)
(* This file was generated automatically by the Mathematica front end.  *)
(* It contains Initialization cells from a Notebook file, which         *)
(* typically will have the same name as this file except ending in      *)
(* ".nb" instead of ".m".                                               *)
(*                                                                      *)
(* This file is intended to be loaded into the Mathematica kernel using *)
(* the package loading commands Get or Needs.  Doing so is equivalent   *)
(* to using the Evaluate Initialization Cells menu command in the front *)
(* end.                                                                 *)
(*                                                                      *)
(* DO NOT EDIT THIS FILE.  This entire file is regenerated              *)
(* automatically each time the parent Notebook file is saved in the     *)
(* Mathematica front end.  Any changes you make to this file will be    *)
(* overwritten.                                                         *)
(************************************************************************)



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];


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[]



