From 8bc2179f3b8ad8ac81a8fe516bcc84743befedc0 Mon Sep 17 00:00:00 2001 From: Jiri Pittner Date: Wed, 17 Jan 2024 22:53:59 +0100 Subject: [PATCH] permutation - implemented general antisymmetrizer --- permutation.cc | 40 ++++++++++++++++++++++++++++++---------- permutation.h | 12 +++++++----- t.cc | 26 ++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 15 deletions(-) diff --git a/permutation.cc b/permutation.cc index 0efdd46..79b3f0e 100644 --- a/permutation.cc +++ b/permutation.cc @@ -440,8 +440,6 @@ static NRPerm *_perm2; template static const T *pclasses2; -template -static T *_pperm; static int sameclass; @@ -454,7 +452,7 @@ if(n<=_n2) T c=pclasses2[n]; for(i=1;i<=_n2;i++) { - if(_pperm[i]>=1) goto skipme; /*place already occupied*/ + if((*_perm2)[i]>=1) goto skipme; /*place already occupied*/ if (sameclass) { if(sameclass==1 && c!=pclasses2[i]) goto skipme; @@ -463,14 +461,14 @@ if(n<=_n2) { T j,k; for(j=i+1; j<=_n2; j++) - if((k=_pperm[j])>=1) + if((k=(*_perm2)[j])>=1) if(/* automatically fulfilled k[k]) goto skipme; } } /*put it there and next number*/ - _pperm[i]=n; + (*_perm2)[i]=n; permg2(n+1); - _pperm[i]=0; + (*_perm2)[i]=0; skipme:; } } @@ -493,7 +491,6 @@ _n2 = this->size(); _callback2 =callback; _sumperm2=0; _perm2 = this; -_pperm = &(*this)[1]-1; pclasses2 = &classes[1]-1; sameclass=restriction_type; permg2(1); @@ -505,22 +502,25 @@ static PermutationAlgebra *list_restricted_return; static PERM_RANK_TYPE list_restricted_index; +static bool list_restricted_invert; + template static void list_restricted_callback(const NRPerm &p) { (*list_restricted_return)[list_restricted_index].weight=p.parity(); -(*list_restricted_return)[list_restricted_index].perm=p; -(*list_restricted_return)[list_restricted_index].copyonwrite(); +(*list_restricted_return)[list_restricted_index].perm= list_restricted_invert?p.inverse():p; +(*list_restricted_return)[list_restricted_index].perm.copyonwrite(); ++list_restricted_index; } template -PermutationAlgebra NRPerm::list_restricted(const NRVec_from1 &classes, int restriction_type) +PermutationAlgebra NRPerm::list_restricted(const NRVec_from1 &classes, int restriction_type, bool invert) { PERM_RANK_TYPE number = this->generate_restricted(NULL,classes,restriction_type); PermutationAlgebra ret(number); list_restricted_return = &ret; list_restricted_index=0; +list_restricted_invert=invert; generate_restricted(list_restricted_callback,classes,restriction_type); return ret; } @@ -2040,6 +2040,25 @@ return r; } +template +PermutationAlgebra general_antisymmetrizer(const NRVec > &groups, int restriction_type, bool inverted) +{ +PermutationAlgebra r; +int ngroups=groups.size(); +if(ngroups==0) return r; +NRVec > lists(ngroups); +for(int i=0; i tmp(ni); + lists[i] = tmp.list_restricted(groups[i],restriction_type,inverted); + } +//cross-product the lists +r=lists[0]; +for(int i=1; i; \ template class YoungTableaux; \ template class Sn_characters; \ template class CycleIndex; \ +template PermutationAlgebra general_antisymmetrizer(const NRVec > &groups, int, bool); \ template std::istream & operator>>(std::istream &s, CyclePerm &x); \ template std::ostream & operator<<(std::ostream &s, const CyclePerm &x); \ template std::ostream & operator<<(std::ostream &s, const CompressedPartition &x); \ diff --git a/permutation.h b/permutation.h index 596c1d3..a43c5f3 100644 --- a/permutation.h +++ b/permutation.h @@ -76,7 +76,7 @@ public: PERM_RANK_TYPE generate_all2(void (*callback)(const NRPerm&)); //recursive method, also not lexicographic PERM_RANK_TYPE generate_all_lex(void (*callback)(const NRPerm&)); //generate in lex order using next() PERM_RANK_TYPE generate_restricted(void (*callback)(const NRPerm&), const NRVec_from1 &classes, int restriction_type=0); - PermutationAlgebra list_restricted(const NRVec_from1 &classes, int restriction_type=0); //weight is set to parity (antisymmetrizer) by default + PermutationAlgebra list_restricted(const NRVec_from1 &classes, int restriction_type=0, bool inverted=false); //weight is set to parity (antisymmetrizer) by default PERM_RANK_TYPE rank() const; //counted from 0 to n!-1 NRVec_from1 inversions(const int type, PERM_RANK_TYPE *prank=NULL) const; //inversion tables explicit NRPerm(const int type, const NRVec_from1 &inversions); //compute permutation from inversions @@ -94,8 +94,8 @@ NRVec_from1 applypermutation(const NRPerm &p, const NRVec_from1 &set, b if(p.size()!=set.size()) laerror("size mismatch in applypermutation"); #endif NRVec_from1 r(set.size()); -if(inverse) for(int i=1; i +PermutationAlgebra general_antisymmetrizer(const NRVec > &groups, int restriction_type=0, bool inverted=false); + + }//namespace #endif diff --git a/t.cc b/t.cc index d706401..5f6cf38 100644 --- a/t.cc +++ b/t.cc @@ -3083,8 +3083,34 @@ if(!dif.is_zero()) laerror("error in gf 2^n sqrt"); } +if(0) +{ +int n; +cin>>n; +NRPerm p(n); +PermutationAlgebra a=p.list_all(); +for(int i=0; i > groups; +cin >> groups; +int ntot=0; +for(int i=0; i indices(ntot); +cin >>indices; + +PermutationAlgebra a=general_antisymmetrizer(groups,-2,true); +for(int i=0; i pindices=applypermutation(a[i].perm,indices,false); + for(int j=1; j<=pindices.size(); ++j) cout <