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

/magnus/back_end/SMApps/include/CommutatorIterator.h

Go to the documentation of this file.
00001 /*
00002  *   $Id: CommutatorIterator.h,v 1.3 1997/02/19 21:20:23 alex Exp $
00003  */
00004  
00005 // Copyright (C) 1995 The New York Group Theory Cooperative
00006 // See magnus/doc/COPYRIGHT for the full notice.
00007 //
00008 // Contents: Declaration of class CommutatorIterator
00009 //
00010 // Principal Author: Dmitry Bormotov
00011 //
00012 // Status: useable
00013 //
00014 // Revision History:
00015 //
00016 
00017 
00018 #ifndef _CommutatorIterator_h_
00019 #define _CommutatorIterator_h_
00020 
00021 
00022 // ------------------------ CommutatorIterator ----------------------------- //
00023 
00024 
00025 class CommutatorIterator {
00026 
00027 public:
00028 
00029 
00030   ///////////////////////////////////////////////////////
00031   //                                                   //
00032   //  Constructors:                                    //
00033   //                                                   //
00034   ///////////////////////////////////////////////////////
00035 
00036   // No default constructor.
00037 
00038   // Copy constructor, operator=, and destructor supplied by compiler.
00039   
00040   CommutatorIterator( int numberOfGenerators, int length ) : 
00041     theLength( length ), numbers( length ), bDone( false ), 
00042     theWords( numberOfGenerators )
00043   { 
00044   #if SAFETY > 0
00045     if( numberOfGenerators <= 0 || theLength < 2 )
00046       error("CommutatorIterator( int numberOfGenerators, int length ) : "
00047             "bad parameters.");
00048   #endif
00049 
00050     for( int i = 0; i < numberOfGenerators; ++i )
00051       theWords[i] = Word(Generator(i+1));
00052     reset();
00053   }
00054 
00055   CommutatorIterator( const VectorOf<Word>& V, int length ) : 
00056     theLength( length ), numbers( length ), bDone( false ), theWords( V )
00057   { 
00058   #if SAFETY > 0
00059     if(  V.length() <= 0 || theLength < 2 )
00060       error("CommutatorIterator(  const VectorOf<Word>& V, int length ) : "
00061             "bad parameters.");
00062   #endif
00063 
00064     reset();
00065   }
00066   
00067 
00068   ///////////////////////////////////////////////////////
00069   //                                                   //
00070   //  Accessors                                        //
00071   //                                                   //
00072   ///////////////////////////////////////////////////////
00073 
00074   Word value( ) const {
00075   #if SAFETY > 0
00076     if( done() )
00077       error("tried to retrieve value from SymmetricRelatorsIterator "
00078             "which is done");
00079   #endif
00080     return current;
00081   }
00082   // Returns the current commutator.
00083   //Calling this is a fatal error if done().
00084 
00085   
00086   bool next( ) {
00087 
00088     if( bDone ) return false;
00089     
00090     for(int i = theLength-1; i >= 0; --i ) {
00091 
00092       numbers[i] = int(numbers[i]) + 1;
00093       
00094       if( numbers[i] <= theWords.length() ) {
00095         current = makeCommutator();
00096         return bDone;
00097       }
00098       
00099       numbers[i] = 1;
00100     }
00101     
00102     return (bDone = true);
00103   }
00104   // Advances this iterator.
00105   // Returns value of done().
00106 
00107   
00108   bool done( ) const { return bDone; }
00109   // Returns TRUE iff the iteration has finished. This may
00110   // be called after it returns TRUE with no side effect.
00111   
00112   void reset( )
00113   {
00114     for(int i = 0; i < theLength; ++i )
00115       numbers[i] = 1;
00116     bDone = false;
00117     current = makeCommutator();
00118   }
00119   // Resets this iterator to the state it was in after construction.
00120 
00121   VectorOf<int> components() { return numbers; }
00122   // Returns all components of the current commutator.  F.e. for the
00123   // commutator [a,b,c] it returns {a,b,c}.
00124   
00125 
00126 private:
00127 
00128   ///////////////////////////////////////////////////////
00129   //                                                   //
00130   //  Private functons:                                //
00131   //                                                   //
00132   ///////////////////////////////////////////////////////
00133 
00134   Word makeCommutator( )
00135   {
00136     Word result = theWords[int(numbers[0])-1];
00137     for( int i = 1; i < theLength; ++i )
00138       result = result.inverse() * Word(theWords[int(numbers[i])-1]).inverse()
00139         * result * theWords[int(numbers[i])-1];
00140     return result.freelyReduce();
00141   }
00142 
00143   
00144   ///////////////////////////////////////////////////////
00145   //                                                   //
00146   //  Data members:                                    //
00147   //                                                   //
00148   ///////////////////////////////////////////////////////
00149 
00150   bool bDone;
00151   int theLength;
00152   Word current; // current commutator
00153   VectorOf<int> numbers;
00154   VectorOf<Word> theWords;
00155 };
00156 
00157 #endif

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