Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

/magnus/back_end/NilpotentGroup/include/PolyWord.h

Go to the documentation of this file.
00001 // Copyright (C) 1994 The New York Group Theory Cooperative
00002 // See magnus/doc/COPYRIGHT for the full notice.
00003 
00004 // Contents: Definition of PolyWord class.
00005 //           
00006 //
00007 // Principal Author: Eugene Paderin
00008 //
00009 // Status: Experimental version
00010 //
00011 // Revision History:
00012 //
00013 // Special Notes:
00014 //
00015 //  * You can find set of methods being incomplete. For example, there is
00016 //    firstLetter() method, but no lastLetter(). The reason is that I added
00017 //    only those methods I needed.
00018 //
00019 
00020 #ifndef _POLY_WORD_H_
00021 #define _POLY_WORD_H_
00022 
00023 #include "Letter.h"
00024 #include "PureRep.h"
00025 #include "PolyWordRep.h"
00026 
00027 class PolyWord : public ObjectOf<PolyWordRep> {
00028 
00029   //--------------------------------------------------------
00030   //    Constructors
00031   //--------------------------------------------------------
00032 
00033 public:
00034   
00035   PolyWord() : ObjectOf<PolyWordRep>( new PolyWordRep() ) {}
00036 
00037   PolyWord( const Letter& let) : 
00038     ObjectOf<PolyWordRep>( new PolyWordRep(let) ) {}
00039 
00040   PolyWord( const Word& w) :
00041     ObjectOf<PolyWordRep>( new PolyWordRep(w) ) {}
00042 
00043   PolyWord( const AbelianWord& aw) :
00044     ObjectOf<PolyWordRep>( new PolyWordRep(aw) ) {}
00045 
00046   PolyWord(PolyWordRep* rep) :
00047     ObjectOf<PolyWordRep>(rep) { enhance()->addRef(); }     
00048 
00049 
00050   // copy constructor and destructor provided by compiler
00051 
00052   //--------------------------------------------------------
00053   //    Accessors to word properties
00054   //--------------------------------------------------------
00055 
00056   int length() const {
00057     return look()->length();
00058   }
00059   // length of the word (sum of absolute values of powers).
00060 
00061   int numberOfLetters() const { 
00062     return look()->numberOfLetters(); 
00063   }
00064   // number of Letters (length of the list)
00065 
00066   bool isEmpty() const { return numberOfLetters() == 0; }
00067 
00068   bool isCollected() const {
00069     look()->isCollected();
00070   }
00071   // returns true iff the word is collected
00072 
00073   //--------------------------------------------------------
00074   //    Accessors to word elements
00075   //--------------------------------------------------------
00076 
00077   const Letter& firstLetter() const {
00078     return look()->firstLetter();
00079   }
00080   // returns reference to the first letter
00081 
00082   const Letter& lastLetter() const {
00083     return look()->lastLetter();
00084   }
00085   // returns reference to the last letter
00086 
00087   // To access the other word elements, use PolyWordIterator
00088   friend class PolyWordIterator;
00089   friend class ConstPolyWordIterator;
00090 
00091   //--------------------------------------------------------
00092   //    I/O
00093   //--------------------------------------------------------
00094 
00095   void printOn (ostream& s) const {
00096     look()->printOn(s);
00097   }
00098   // output
00099 
00100   friend ostream& operator < (ostream& s, const PolyWord& w) {
00101     return w.look()->write(s);
00102   }
00103   // IPC output
00104 
00105   friend istream& operator > (istream& s, PolyWord& w) {
00106     return w.change()->read(s);
00107   }
00108   // IPC input
00109  
00110   void debugInfo() const {
00111     look()->debugInfo();
00112   }
00113   // Prints debug info to cout
00114 
00115  
00116   //--------------------------------------------------------
00117   //    General methods
00118   //--------------------------------------------------------
00119 
00120   operator Word() const {
00121     return look()->toWord();
00122   }
00123   // cast to common Word (not reduced)
00124 
00125   Chars toChars( const VectorOf<Chars>& names ) const {
00126     return look()->toChars(names);
00127   }
00128   // outputs word to string using given Chars as names of generators
00129 
00130   void freelyReduce() {
00131     change()->freelyReduce();
00132   }
00133   // freely reduces the word
00134 
00135   PolyWord inverse() const {
00136     return look()->inverse();
00137   }
00138   // returns the inverse word
00139 
00140   void append(const PolyWord& w) {
00141     change()->append(w);
00142   }
00143   // appends w to the end of this word
00144 
00145   void append(const Letter& w) {
00146     change()->append(w);
00147   }
00148   // appends w to the end of this word
00149 
00150   void clear() { change()->clear(); }
00151   // clears the list
00152 
00153   void duplicate(PolyWordNode*& ptrToFirst, PolyWordNode*& ptrToLast) const {
00154     look()->duplicate(ptrToFirst, ptrToLast);
00155   }
00156   // duplicates the list and writes addresses of the new copy's
00157   // first and last nodes to ptrToFirst and ptrToLast.
00158 
00159   void removeFirstLetter() {
00160     change()->removeFirstLetter();
00161   }
00162   // removes first letter (node) from the list
00163 
00164   PolyWord raiseToPower( int power ) const {
00165     return look()->raiseToPower(power);
00166   }
00167   // Raises the word to given power (can be negative or 0)
00168 
00169 };
00170 
00171 //----------------- Inline global functions -----------------
00172 
00173 inline ostream& operator<<(ostream& s, const PolyWord& w) {
00174   w.printOn(s);
00175   return s;
00176 }
00177 // stream output
00178 
00179 inline PolyWord operator * (const PolyWord& p1, const PolyWord& p2) {
00180   PolyWord res(p1);
00181   res.append(p2);
00182   return res;
00183 }
00184 // catenation of words
00185 
00186 
00187 inline PolyWord commutator(const PolyWord& w1, const PolyWord& w2) {
00188   return w1.inverse() * w2.inverse() * w1 * w2;
00189 }
00190 // returns commutator [w1, w2]
00191 
00192 inline PolyWord commutatorOfInverses(const PolyWord& w1, const PolyWord& w2) {
00193   return w1 * w2 * w1.inverse() * w2.inverse();
00194 }
00195 // returns commutator [w1^-1, w2^-1]
00196 
00197 PolyWord evaluateWord( const Word& w, const VectorOf<PolyWord>& pw );
00198 // Evaluates the word w by replacing its generators ai -> pw[i].
00199 
00200 PolyWord evaluateWord(const PolyWord& pw, const VectorOf<PolyWord>& v);
00201 //Evaluates the word replacing generator g by word v[g-1].
00202 //@ep cannot make it a class member due to gcc template bugs
00203 
00204 #endif
00205 
00206 

Generated at Tue Jun 19 09:49:37 2001 for Magnus Classes by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001