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

/magnus/back_end/NilpotentGroup/include/Letter.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 structure Letter
00005 //
00006 // This is a helper class for Free Nilpotent Groups.
00007 //
00008 //  Letter is an element of word: a generator together with its power,
00009 //  i.e. an expression g^p. Generator value is always positive.
00010 //
00011 // Principal Author: Eugene Paderin
00012 //
00013 // Status: In progress
00014 //
00015 // Revision History:
00016 //
00017 // Special Notes:
00018 //
00019 
00020 #ifndef _LETTER_H_
00021 #define _LETTER_H_
00022 
00023 #include "Word.h"
00024 #include "Generator.h"
00025 
00026 struct Letter {
00027 
00028   // constructors
00029 
00030   Letter() : gen(1), power(0) {}
00031   // Default constructor makes fictive letter
00032 
00033   Letter(Generator g, int pow = 1) {
00034     if( ord(g) > 0 ) {
00035       gen = g; 
00036       power = pow; 
00037     }
00038     else { 
00039       gen = inv(g); 
00040       power = -pow; 
00041     }
00042   }
00043 
00044   Letter(int g, int pow = 1) {
00045     if( g > 0 ) { 
00046       gen = Generator(g); 
00047       power = pow; 
00048     }
00049     else { 
00050       gen = Generator(-g); 
00051       power = -pow; 
00052     }
00053   }
00054 
00055   // collects letters
00056   void collectWith (Generator g) {
00057     if( power == 0 ) {
00058       gen = abs(g);
00059       power = ::power(g);
00060     }
00061     else if( abs(g) == ord(gen) ) 
00062       power += ::power(g);
00063     else error("Attempt to collect two distinct letters.");
00064   }
00065 
00066   // conversion to Word
00067   operator Word() const {
00068     Word w;
00069     Generator g;
00070     int r;
00071     if(power > 0) {
00072       g = gen;
00073       r = power;
00074     } else if(power < 0) {
00075       g = inv(gen);
00076       r = -power;
00077     } else {
00078       return w;
00079     }
00080     for( ; r > 0; r--) w *= g;
00081     return w;
00082   }
00083 
00084   void printOn(ostream& os) const {
00085     os << gen;
00086     if(power != 1) os << "^" << power;
00087   }
00088 
00089   void invert() {  power = -power; }
00090   // Inverts the letter. Do not confuse with inv() global function.
00091 
00092   int shortLexIndex() const {
00093     int g = ord(gen);
00094     return (power > 0) ? 2*(g-1) : 2*g-1;
00095   }
00096   // Returns generator's ShortLex index. Does not work with power==0.
00097 
00098   // IPC write
00099   friend ostream& operator < (ostream& os, const Letter& let) {
00100     os < let.gen < let.power;
00101   }
00102 
00103   // IPC read
00104   friend istream& operator > (istream& is, Letter& let) {
00105     is > let.gen > let.power;
00106   }
00107 
00108   // Data
00109 
00110   Generator gen;
00111   int power;
00112 };
00113 
00114 // Global functions
00115 
00116 inline ostream& operator<< (ostream& os, const Letter& let) {
00117   let.printOn(os);
00118   return os;
00119 }
00120 
00121 // inversion
00122 inline Letter inv( const Letter& let) {
00123   return Letter(let.gen, -let.power); 
00124 }
00125 
00126 // comparison
00127 
00128 inline bool operator == (const Letter& let1, const Letter& let2) {
00129   if( let1.power != let2.power ) return false;
00130   if( let1.power == 0 ) return true;
00131   return (let1.gen == let2.gen);
00132 }
00133 
00134 inline bool operator != (const Letter& let1, const Letter& let2) {
00135   return ! (let1 == let2);
00136 }
00137 
00138 #endif
00139 
00140 

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