From 1e83fcfaf940c5d22205223bc923cf2ab23dd60e Mon Sep 17 00:00:00 2001 From: Jiri Pittner Date: Tue, 16 Jan 2024 22:03:46 +0100 Subject: [PATCH] working on permutation --- permutation.cc | 49 ++++++++++++++++++++++++++++++++++++++ permutation.h | 64 +++++++++++++++++++++++++++++++++++++++++++++++--- t.cc | 7 ++++-- vec.h | 11 +++++++++ 4 files changed, 126 insertions(+), 5 deletions(-) diff --git a/permutation.cc b/permutation.cc index 3f0a1fc..4cf3878 100644 --- a/permutation.cc +++ b/permutation.cc @@ -727,6 +727,55 @@ return value; #undef MAXBINOM +template +PermutationAlgebra PermutationAlgebra::operator&(const PermutationAlgebra &rhs) const +{ +PermutationAlgebra res(this->size()*rhs.size()); +for(int i=0; isize(); ++i) + for(int j=0; j +PermutationAlgebra PermutationAlgebra::operator|(const PermutationAlgebra &rhs) const +{ +PermutationAlgebra res(this->size()*rhs.size()); +for(int i=0; isize(); ++i) + for(int j=0; j +PermutationAlgebra PermutationAlgebra::operator*(const PermutationAlgebra &rhs) const +{ +if(this->size()>0 && rhs.size()>0 && (*this)[0].perm.size()!=rhs[0].perm.size()) laerror("permutation sizes do not match"); +PermutationAlgebra res(this->size()*rhs.size()); +for(int i=0; isize(); ++i) + for(int j=0; j +PermutationAlgebra PermutationAlgebra::operator+(const PermutationAlgebra &rhs) const +{ +if(this->size()>0 && rhs.size()>0 && (*this)[0].perm.size()!=rhs[0].perm.size()) laerror("permutation sizes do not match"); +return this->concat(rhs); +} + + +template +void PermutationAlgebra::simplify() +{ +copyonwrite(); +sort(); +//@@@@implement merging weights of identical permutations and resize like we did in qubithamiltonian with other stuff +} + + + //////////////////////////////////////////////////////// diff --git a/permutation.h b/permutation.h index eadb07e..9978d49 100644 --- a/permutation.h +++ b/permutation.h @@ -29,7 +29,6 @@ typedef unsigned long long PERM_RANK_TYPE; //permutations are always numbered from 1; offset is employed when applied to vectors and matrices -//TODO@@@ permutace - substitute jako multiplikace ale x[p[i]] = y[i] kde ale x a y nejsou prave permutace namespace LA { @@ -42,6 +41,9 @@ template class YoungTableaux; template class WeightPermutation; template class PermutationAlgebra; + +//operator== != < > inherited from NRVec + template class NRPerm : public NRVec_from1 { public: @@ -82,20 +84,65 @@ public: NRPerm pow(const int n) const {return power(*this,n);}; }; + +//this is not a class memeber due to double templating +//it is also possible to use member function permuted of NRVec(_from1) +template +NRVec_from1 applypermutation(const NRPerm &p, const NRVec_from1 &set, bool inverse=false) +{ +#ifdef DEBUG +if(p.size()!=set.size()) laerror("size mismatch in applypermutation"); +#endif +NRVec_from1 r(set.size()); +if(inverse) for(int i=1; i class WeightPermutation { public: R weight; NRPerm perm; + int size() const {return perm.size();}; + bool is_plaindata() const {return false;}; WeightPermutation() : weight(0) {}; WeightPermutation(const R w, const NRPerm &p) : weight(w), perm(p) {}; WeightPermutation(const NRPerm &p) : perm(p) {weight= p.parity();}; 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(weight*rhs.weight,perm|rhs.perm);}; + WeightPermutation operator*(const WeightPermutation &rhs) const {return WeightPermutation(weight*rhs.weight,perm*rhs.perm);}; + WeightPermutation operator*(const R &x) const {return WeightPermutation(weight*x,perm); } +//@@@operator+ and - yielding Permutationalgebra + + 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;}; + bool operator<(const WeightPermutation &rhs) const {return this->perm < rhs.perm;}; + bool operator>=(const WeightPermutation &rhs) const {return !(*this < rhs);}; + bool operator<=(const WeightPermutation &rhs) const {return !(*this > rhs);}; + }; +//some necessary traits of the non-scalar class to be able to use LA methods +template +class LA_traits > { +public: + static bool is_plaindata() {return false;}; + static void copyonwrite(WeightPermutation& x) {x.perm.copyonwrite();}; + typedef typename LA_traits::normtype normtype; + static inline bool smaller(const WeightPermutation& x, const WeightPermutation& y) {return x.perm& x, const WeightPermutation& y) {return x.perm>y.perm;}; + +}; + + + + template std::istream & operator>>(std::istream &s, WeightPermutation &x) { @@ -118,10 +165,21 @@ class PermutationAlgebra : public NRVec > public: PermutationAlgebra() {}; PermutationAlgebra(int n) : NRVec >(n) {}; - + PermutationAlgebra(const NRVec > &x) : NRVec >(x) {}; + int size() const {return NRVec >::size();}; + void copyonwrite() {NRVec >::copyonwrite();}; + void sort(int direction = 0, int from = 0, int to = -1, int *permut = NULL, bool stable=false) {NRVec >::sort(direction,from, to,permut,stable);}; + + PermutationAlgebra operator&(const PermutationAlgebra &rhs) const; + PermutationAlgebra operator|(const PermutationAlgebra &rhs) const; + 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) const {PermutationAlgebra r(*this); return r*=x;}; + void simplify(); }; -//TODO@@@ basic operators for the algebra, possibly also simplification after operation +//TODO@@@ also simplification after operation //TODO@@@ permutationalgebra for Kucharski style antisymmetrizers diff --git a/t.cc b/t.cc index b391900..31ef544 100644 --- a/t.cc +++ b/t.cc @@ -2218,8 +2218,11 @@ NRPerm p(n); NRVec_from1 classes; cin>>classes; if(classes.size()!=p.size()) laerror("sizes do not match"); PermutationAlgebra tot = p.list_restricted(classes,-2); -cout <<"generated\n"< all= p.list_all(); +all.sort(); +cout <<"ALL\n"<