added some operations to permutation.h

This commit is contained in:
2025-11-13 17:05:57 +01:00
parent d764589232
commit 883b8565c0
2 changed files with 99 additions and 9 deletions

View File

@@ -96,6 +96,39 @@ for(T i=1; i<=this->size(); ++i) q[i]=(*this)[this->size()-i+1];
return q; return q;
} }
template <typename T>
NRPerm<T> NRPerm<T>::cutleft(int n) const
{
if(n<0||n>size()) laerror("illegal n in ::cutleft");
if(n==0) return *this;
for(int i=1; i<=n; ++i) if((*this)[i]!=i) laerror("left subset is not identity permutation");
if(n==size()) return NRPerm<T>();
NRPerm<T> res(size()-n);
for(int i=n+1; i<=size(); ++i) res[i-n] = (*this)[i]-n;
#ifdef DEBUG
if(!res.is_valid()) laerror("inetrnal error in cutleft");
#endif
return res;
}
template <typename T>
NRPerm<T> NRPerm<T>::cutright(int n) const
{
if(n<0||n>size()) laerror("illegal n in ::cutright");
if(n==0) return *this;
for(int i=size(); i>size()-n; --i) if((*this)[i]!=i) laerror("right subset is not identity permutation");
if(n==size()) return NRPerm<T>();
NRPerm<T> res(size()-n);
for(int i=1; i<=size()-n; ++i) res[i] = (*this)[i];
#ifdef DEBUG
if(!res.is_valid()) laerror("inetrnal error in cutleft");
#endif
return res;
}
template <typename T> template <typename T>
NRPerm<T> NRPerm<T>::operator&(const NRPerm<T> &q) const NRPerm<T> NRPerm<T>::operator&(const NRPerm<T> &q) const
{ {
@@ -730,6 +763,56 @@ for(k=n-1; k>=0; --k)
*this = NRPerm(3,inv); *this = NRPerm(3,inv);
} }
template <typename T, typename R>
PermutationAlgebra<T,R> PermutationAlgebra<T,R>::cutleft(int n) const
{
PermutationAlgebra<T,R> res(this->size());
for(int i=0; i<this->size(); ++i) {res[i].perm = (*this)[i].perm.cutleft(n) ; res[i].weight=(*this)[i].weight;}
return res;
}
template <typename T, typename R>
PermutationAlgebra<T,R> PermutationAlgebra<T,R>::cutright(int n) const
{
PermutationAlgebra<T,R> res(this->size());
for(int i=0; i<this->size(); ++i) {res[i].perm = (*this)[i].perm.cutright(n) ; res[i].weight=(*this)[i].weight;}
return res;
}
template <typename T, typename R>
PermutationAlgebra<T,R> PermutationAlgebra<T,R>::operator&(const NRPerm<T> &rhs) const
{
PermutationAlgebra<T,R> res(this->size());
for(int i=0; i<this->size(); ++i) {res[i].perm = (*this)[i].perm & rhs; res[i].weight=(*this)[i].weight;}
return res;
}
template <typename T, typename R>
PermutationAlgebra<T,R> PermutationAlgebra<T,R>::operator|(const NRPerm<T> &rhs) const
{
PermutationAlgebra<T,R> res(this->size());
for(int i=0; i<this->size(); ++i) {res[i].perm = (*this)[i].perm | rhs; res[i].weight=(*this)[i].weight;}
return res;
}
template <typename T, typename R>
PermutationAlgebra<T,R> PermutationAlgebra<T,R>::operator*(const NRPerm<T> &rhs) const
{
PermutationAlgebra<T,R> res(this->size());
for(int i=0; i<this->size(); ++i) {res[i].perm = (*this)[i].perm * rhs; res[i].weight=(*this)[i].weight;}
return res;
}
template <typename T> template<typename R>
PermutationAlgebra<T,R> NRPerm<T>::operator*(const PermutationAlgebra<T,R> &pa) const
{
PermutationAlgebra<T,R> res(pa.size());
for(int i=0; i<pa.size(); ++i) {res[i].perm = *this * pa[i]; res[i].weight= pa[i].weight;}
return res;
}
template <typename T, typename R> template <typename T, typename R>

View File

@@ -65,8 +65,11 @@ public:
NRPerm reverse() const; //backward order NRPerm reverse() const; //backward order
NRPerm operator&(const NRPerm &rhs) const; //concatenate the permutations this,rhs, renumbering rhs (not commutative) NRPerm operator&(const NRPerm &rhs) const; //concatenate the permutations this,rhs, renumbering rhs (not commutative)
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 cutleft(int n) const; //remove left identity subset and renumber
NRPerm cutright(int n) const; //remove right identity subset
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;
template<typename R> PermutationAlgebra<T,R> operator*(const PermutationAlgebra<T,R> &pa) const;
NRPerm multiply(const NRPerm<T> &q, bool inverse) const; //multiplication but optionally q inversed 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 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 NRPerm commutator(const NRPerm &q, bool inverse=false) const; //p^-1 q^-1 p q or q^-1 p^-1 q p
@@ -117,13 +120,12 @@ public:
bool is_identity() const {return weight==1 && is_scaledidentity();} bool is_identity() const {return weight==1 && is_scaledidentity();}
bool is_plaindata() const {return false;}; bool is_plaindata() const {return false;};
WeightPermutation() : weight(0) {}; WeightPermutation() : weight(0) {};
WeightPermutation(const R w, const NRPerm<T> &p) : weight(w), perm(p) {}; explicit WeightPermutation(const NRPerm<T> &p, const R w=1) : weight(w), perm(p) {};
WeightPermutation(const NRPerm<T> &p) : perm(p) {weight= p.parity();};
void copyonwrite() {perm.copyonwrite();}; void copyonwrite() {perm.copyonwrite();};
WeightPermutation operator&(const WeightPermutation &rhs) const {return WeightPermutation(weight*rhs.weight,perm&rhs.perm);}; WeightPermutation operator&(const WeightPermutation &rhs) const {return WeightPermutation(perm&rhs.perm,weight*rhs.weight);};
WeightPermutation operator|(const WeightPermutation &rhs) const {return WeightPermutation(weight*rhs.weight,perm|rhs.perm);}; WeightPermutation operator|(const WeightPermutation &rhs) const {return WeightPermutation(perm|rhs.perm,weight*rhs.weight);};
WeightPermutation operator*(const WeightPermutation &rhs) const {return WeightPermutation(weight*rhs.weight,perm*rhs.perm);}; WeightPermutation operator*(const WeightPermutation &rhs) const {return WeightPermutation(perm*rhs.perm,weight*rhs.weight);};
WeightPermutation operator*(const R &x) const {return WeightPermutation(weight*x,perm); } WeightPermutation operator*(const R &x) const {return WeightPermutation(perm,weight*x); }
bool operator==(const WeightPermutation &rhs) const {return this->perm == rhs.perm;}; //NOTE for sorting, compares only the permutation not the weight! bool operator==(const WeightPermutation &rhs) const {return this->perm == rhs.perm;}; //NOTE for sorting, compares only the permutation not the weight!
bool operator!=(const WeightPermutation &rhs) const {return !(*this==rhs);} //NOTE: compares only the permutation bool operator!=(const WeightPermutation &rhs) const {return !(*this==rhs);} //NOTE: compares only the permutation
@@ -186,9 +188,14 @@ public:
void copyonwrite() {NRVec<WeightPermutation<T,R> >::copyonwrite();}; void copyonwrite() {NRVec<WeightPermutation<T,R> >::copyonwrite();};
int sort(int direction = 0, int from = 0, int to = -1, int *permut = NULL, bool stable=false) {return NRVec<WeightPermutation<T,R> >::sort(direction,from, to,permut,stable);}; int sort(int direction = 0, int from = 0, int to = -1, int *permut = NULL, bool stable=false) {return NRVec<WeightPermutation<T,R> >::sort(direction,from, to,permut,stable);};
PermutationAlgebra operator&(const PermutationAlgebra &rhs) const; PermutationAlgebra operator&(const NRPerm<T> &rhs) const; //applied to all terms
PermutationAlgebra operator|(const PermutationAlgebra &rhs) const; PermutationAlgebra operator|(const NRPerm<T> &rhs) const; //applied to all terms
PermutationAlgebra operator*(const PermutationAlgebra &rhs) const; PermutationAlgebra operator*(const NRPerm<T> &rhs) const; //applied to all terms
PermutationAlgebra cutleft(int n) const; //applied to all terms
PermutationAlgebra cutright(int n) const; //applied to all terms
PermutationAlgebra operator&(const PermutationAlgebra &rhs) const; //each term with each
PermutationAlgebra operator|(const PermutationAlgebra &rhs) const; //each term with each
PermutationAlgebra operator*(const PermutationAlgebra &rhs) const; //each term with each
PermutationAlgebra operator+(const PermutationAlgebra &rhs) const; PermutationAlgebra operator+(const PermutationAlgebra &rhs) const;
PermutationAlgebra &operator*=(const R &x) {this->copyonwrite(); for(int i=1; i<=size(); ++i) (*this)[i].weight *= x; return *this;}; PermutationAlgebra &operator*=(const R &x) {this->copyonwrite(); for(int i=1; i<=size(); ++i) (*this)[i].weight *= x; return *this;};
PermutationAlgebra operator*(const R &x) const {PermutationAlgebra r(*this); return r*=x;}; PermutationAlgebra operator*(const R &x) const {PermutationAlgebra r(*this); return r*=x;};