33 #ifndef PERMUTATIONWORD_H_ 34 #define PERMUTATIONWORD_H_ 36 #include <permlib/permutation.h> 39 #include <boost/shared_ptr.hpp> 40 #include <boost/foreach.hpp> 44 typedef boost::shared_ptr<Permutation> PermutationPtr;
56 typedef boost::shared_ptr<PermutationWord>
ptr;
87 inline unsigned long operator/(
unsigned long val)
const {
return at(val); }
89 unsigned long at(
unsigned long val)
const;
91 unsigned long operator%(
unsigned long val)
const;
107 inline unsigned int size()
const {
return m_n; }
115 static std::vector<PermutationPtr> ms_elements;
116 static std::vector<PermutationPtr> ms_elementsInverse;
117 static void addElement(
const perm &p);
118 static void addElement(
const perm &p,
const perm &pInv);
119 static void addElement(PermutationPtr p);
121 mutable std::vector<int> m_word;
125 std::vector<PermutationPtr> PermutationWord::ms_elements(1);
126 std::vector<PermutationPtr> PermutationWord::ms_elementsInverse(1);
136 ms_elements.push_back(PermutationPtr(pp));
137 ms_elementsInverse.push_back(PermutationPtr(
new Permutation(~*pp)));
139 m_word.push_back(ms_elements.size()-1);
143 : m_word(p.m_word), m_n(p.m_n)
151 m_word.push_back(ms_elements.size()-1);
154 inline void PermutationWord::addElement(
const perm &p) {
156 ms_elements.push_back(gen);
158 ms_elementsInverse.push_back(genInv);
160 inline void PermutationWord::addElement(PermutationPtr p) {
161 ms_elements.push_back(p);
162 PermutationPtr genInv(
new Permutation(~*p));
163 ms_elementsInverse.push_back(genInv);
166 inline void PermutationWord::addElement(
const perm &p,
const perm &pInv) {
167 PermutationPtr gen(
new Permutation(p));
168 ms_elements.push_back(gen);
169 PermutationPtr genInv(
new Permutation(pInv));
170 ms_elementsInverse.push_back(genInv);
181 if (m_word.empty()) {
182 m_word.insert(m_word.end(), p.m_word.begin(), p.m_word.end());
184 }
else if (p.m_word.empty())
187 m_word.insert(m_word.end(), p.m_word.begin(), p.m_word.end());
192 if (m_word.empty()) {
193 m_word.insert(m_word.end(), p.m_word.begin(), p.m_word.end());
195 }
else if (p.m_word.empty())
198 m_word.insert(m_word.begin(), p.m_word.begin(), p.m_word.end());
204 std::vector<int> oldWord(m_word);
205 for (
unsigned int i=0; i<oldWord.size(); ++i) {
206 m_word[i] = -oldWord[oldWord.size() - 1 - i];
213 for (
unsigned int i=0; i<m_word.size(); ++i) {
214 inv.m_word[i] = -m_word[m_word.size() - 1 - i];
220 unsigned long ret = val;
221 BOOST_FOREACH(
int e, m_word) {
223 ret = *(ms_elements[e]) / ret;
225 ret = *(ms_elementsInverse[-e]) / ret;
231 unsigned long ret = val;
232 for (std::vector<int>::reverse_iterator lit = m_word.rbegin(); lit != m_word.rend(); ++lit) {
235 ret = *(ms_elements[-e]) / ret;
237 ret = *(ms_elementsInverse[e]) / ret;
243 if (m_word.empty()) {
246 if (m_word.size() == 1) {
249 int e = m_word.front();
251 return ms_elements[e]->isIdentity();
253 return ms_elementsInverse[-e]->isIdentity();
260 BOOST_FOREACH(
int e, m_word) {
262 ? *ms_elements[e].
get()
263 : *ms_elementsInverse[-e].get();
266 const bool permIsIdentity = resMult->isIdentity();
268 if (!permIsIdentity) {
272 m_word.push_back(ms_elements.size()-1);
276 return permIsIdentity;
281 BOOST_FOREACH(
int g, p.m_word) {
297 return m_word == p2.m_word;
302 ms_elements.resize(1);
303 ms_elementsInverse.clear();
304 ms_elementsInverse.resize(1);
309 #endif // -- PERMUTATIONWORD_H_ unsigned long operator%(unsigned long val) const
lets inverse permutation act on val, i.e. compute j such that (this->at(j) == val) ...
Definition: permutationword.h:230
bool operator==(const PermutationWord &p2) const
equals operator
Definition: permutationword.h:288
static void clearStorage()
deletes all elementary permutations from the storage. use ONLY if there is currently no PermutationWo...
Definition: permutationword.h:300
friend std::ostream & operator<<(std::ostream &out, const PermutationWord &p)
output
Definition: permutationword.h:279
PermutationWord & operator^=(const PermutationWord &p)
permutation inplace multiplication from the left
Definition: permutationword.h:191
PermutationWord(unsigned int n)
constructs identity permutation acting on n elements
Definition: permutationword.h:128
PermutationWord & operator*=(const PermutationWord &p)
permutation inplace multiplication from the right
Definition: permutationword.h:180
void flush()
force that permutation word is multiplied out
Definition: permutationword.h:105
unsigned long at(unsigned long val) const
lets permutation act on val
Definition: permutationword.h:219
unsigned long operator/(unsigned long val) const
lets permutation act on val
Definition: permutationword.h:87
bool isIdentity(bool flush=false) const
returns true if this permutation is identity
Definition: permutationword.h:242
PermutationWord & invertInplace()
permutation inplace inversion
Definition: permutationword.h:203
PermutationWord operator~() const
permutation inversion
Definition: permutationword.h:211
PermutationWord operator*(const PermutationWord &p) const
permutation multiplication from the right
Definition: permutationword.h:174
unsigned int size() const
number of points this permutation acts on
Definition: permutationword.h:107
permutation class storing permutations as words of elementary Permutation 's
Definition: permutationword.h:50
std::vector< dom_int > perm
typedef for permutation image
Definition: permutation.h:61
Permutation class storing all values explicitly.
Definition: permutation.h:58
Permutation::perm perm
typedef for permutation image
Definition: permutationword.h:53
static unsigned long elementsNumber()
number of generators in the word generator pool
Definition: permutationword.h:110
boost::shared_ptr< PermutationWord > ptr
boost shared_ptr of this class
Definition: permutationword.h:56
Definition: abstract_bsgs.h:49