small additions to permutations

This commit is contained in:
Jiri Pittner 2024-01-24 13:41:39 +01:00
parent 13c23fb85d
commit 1ee984eda2
2 changed files with 42 additions and 5 deletions

View File

@ -135,11 +135,27 @@ if(n!=q.size()) laerror("product of incompatible permutations");
NRPerm<T> r(n); NRPerm<T> r(n);
for(T i=1; i<=n; ++i) r[i] = (*this)[q[i]]; for(T i=1; i<=n; ++i) r[i] = (*this)[q[i]];
return r; return r;
} }
template <typename T> template <typename T>
NRPerm<T> NRPerm<T>::conjugate_by(const NRPerm<T> &q) const NRPerm<T> NRPerm<T>::multiply(const NRPerm<T> &q, bool inverse) const
{
#ifdef DEBUG
if(!this->is_valid() || !q.is_valid()) laerror("multiplication of invalid permutation");
#endif
T n=this->size();
if(n!=q.size()) laerror("product of incompatible permutations");
NRPerm<T> r(n);
if(inverse) for(T i=1; i<=n; ++i) r[q[i]] = (*this)[i];
else for(T i=1; i<=n; ++i) r[i] = (*this)[q[i]];
return r;
}
template <typename T>
NRPerm<T> NRPerm<T>::conjugate_by(const NRPerm<T> &q, bool inverse) const
{ {
#ifdef DEBUG #ifdef DEBUG
if(!this->is_valid() || !q.is_valid()) laerror("multiplication of invalid permutation"); if(!this->is_valid() || !q.is_valid()) laerror("multiplication of invalid permutation");
@ -149,11 +165,30 @@ T n=this->size();
if(n!=q.size()) laerror("product of incompatible permutations"); if(n!=q.size()) laerror("product of incompatible permutations");
NRPerm<T> qi=q.inverse(); NRPerm<T> qi=q.inverse();
NRPerm<T> r(n); NRPerm<T> r(n);
for(T i=1; i<=n; ++i) r[i] = qi[(*this)[q[i]]]; if(inverse) for(T i=1; i<=n; ++i) r[i] = q[(*this)[qi[i]]];
else for(T i=1; i<=n; ++i) r[i] = qi[(*this)[q[i]]];
return r; return r;
} }
template <typename T>
NRPerm<T> NRPerm<T>::commutator(const NRPerm<T> &q, bool inverse) const
{
#ifdef DEBUG
if(!this->is_valid() || !q.is_valid()) laerror("multiplication of invalid permutation");
#endif
T n=this->size();
if(n!=q.size()) laerror("product of incompatible permutations");
NRPerm<T> qi=q.inverse();
NRPerm<T> pi=this->inverse();
NRPerm<T> r(n);
if(inverse) for(T i=1; i<=n; ++i) r[i] = qi[pi[q[(*this)[i]]]];
else for(T i=1; i<=n; ++i) r[i] = pi[qi[(*this)[q[i]]]];
return r;
}
template <typename T> template <typename T>
CyclePerm<T> CyclePerm<T>::conjugate_by(const CyclePerm<T> &q) const CyclePerm<T> CyclePerm<T>::conjugate_by(const CyclePerm<T> &q) const
{ {

View File

@ -67,7 +67,9 @@ public:
NRPerm operator|(const NRPerm &rhs) const; //concatenate the permutations rhs,this, renumbering rhs (not commutative) NRPerm operator|(const NRPerm &rhs) const; //concatenate the permutations rhs,this, renumbering rhs (not commutative)
NRPerm operator*(const NRPerm &q) const; //q is rhs and applied first, this applied second NRPerm operator*(const NRPerm &q) const; //q is rhs and applied first, this applied second
NRPerm operator*(const CyclePerm<T> &r) const; NRPerm operator*(const CyclePerm<T> &r) const;
NRPerm conjugate_by(const NRPerm &q) const; //q^-1 p q NRPerm multiply(const NRPerm<T> &q, bool inverse) const; //multiplication but optionally q inversed
NRPerm conjugate_by(const NRPerm &q, bool reverse=false) const; //q^-1 p q or q p q^-1
NRPerm commutator(const NRPerm &q, bool inverse=false) const; //p^-1 q^-1 p q or q^-1 p^-1 q p
int parity() const; //returns +/- 1 int parity() const; //returns +/- 1
void randomize(void); //uniformly random by Fisher-Yates shuffle void randomize(void); //uniformly random by Fisher-Yates shuffle
bool next(); //generate next permutation in lex order bool next(); //generate next permutation in lex order