CoCoALib-0.9905 date: 23 May 2007


degree.H

Go to the documentation of this file.
00001 #ifndef CoCoA_degree_H
00002 #define CoCoA_degree_H
00003 
00004 //   Copyright (c)  2005  John Abbott
00005 
00006 //   This file is part of the source of CoCoALib, the CoCoA Library.
00007 
00008 //   CoCoALib is free software; you can redistribute it and/or modify
00009 //   it under the terms of the GNU General Public License (version 2)
00010 //   as published by the Free Software Foundation.  A copy of the full
00011 //   licence may be found in the file COPYING in this directory.
00012 
00013 //   CoCoALib is distributed in the hope that it will be useful,
00014 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 //   GNU General Public License for more details.
00017 
00018 //   You should have received a copy of the GNU General Public License
00019 //   along with CoCoA; if not, write to the Free Software
00020 //   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 
00022 
00023 // Header file for the class degree
00024 
00025 
00026 #include "CoCoA/utils.H"
00027 #include "CoCoA/ZZ.H"
00028 
00029 #include <cstddef>
00030 //using std::size_t;
00031 #include <vector>
00032 //using std::vector;
00033 #include <iosfwd>
00034 // using std::ostream;
00035 
00036 
00037 namespace CoCoA
00038 {
00039 
00040   namespace OrdvArith { class base; } // forward declaration for friend declaration
00041 
00042   /*-----------------------------------------------------------------*/
00043   /** \include degree.txt  */
00044   /*-----------------------------------------------------------------*/
00045   class degree
00046   {
00047   public:
00048     degree(std::size_t dim);
00049 //???    friend std::size_t dim(const degree& deg);  // unnecessary because of GradingDim???
00050     const ZZ& operator[](std::size_t index) const;                   ///< deg[index] (READ ONLY)
00051     std::size_t myGradingDim() const;
00052     void mySetComponent(std::size_t index, const ZZ& VALUE);         ///< deg[index] = VALUE
00053     void mySetComponent(std::size_t index, long value);              ///< deg[index] = value
00054     degree& operator+=(const degree& d);                             ///< Computes deg1+=deg2
00055     degree& operator-=(const degree& d);                             ///< Computes deg1-=deg2
00056     friend int FastCmp(const degree& d1, const degree& d2);          ///< like cmp but inline and no checks
00057     friend inline bool IsZero(const degree& d);
00058     static void CheckCompatible(const degree& d1, const degree& d2, const char* fn); ///< checks dims are equal, throws if not.
00059   private: // data members
00060     std::vector<ZZ> myCoords;
00061   };
00062 
00063 
00064   std::size_t GradingDim(const degree& d);                           ///< Computes "dimension" of the degree
00065   degree operator+(const degree& d1, const degree& d2);              ///< Computes d1+d2
00066   degree operator-(const degree& d1, const degree& d2);              ///< Computes d1-d2
00067   degree top(const degree& d1, const degree& d2);                    ///< i-th compt is max(d1[i], d2[i])
00068   int cmp(const degree& d1, const degree& d2);                       ///< lex comparison, result is <0,=0,>0
00069   void SetComponent(degree& d, std::size_t index, const ZZ& value);
00070   void SetComponent(degree& d, std::size_t index, long value);
00071   std::ostream& operator<<(std::ostream& out, const degree& d);      ///< prints out the degree, handles dim=1 specially.
00072 
00073   //---------------------------------------------------------------------------
00074   // inline functions
00075 
00076   inline degree::degree(std::size_t dim):
00077       myCoords(dim)
00078   {}
00079 
00080 
00081   inline std::size_t degree::myGradingDim() const
00082   {
00083     return myCoords.size();
00084   }
00085 
00086 
00087   // FastCmp is the same as cmp except it is inline and does not check compatibility
00088   inline int FastCmp(const degree& d1, const degree& d2)
00089   {
00090     const std::size_t dim = d1.myGradingDim();
00091     return LexCmp3(&d1.myCoords[0], &d1.myCoords[dim],
00092                    &d2.myCoords[0], &d2.myCoords[dim]);
00093 //     for (std::size_t i=0; i < dim; ++i)
00094 //       if (d1.myCoords[i] != d2.myCoords[i])
00095 //         return cmp(d1.myCoords[i], d2.myCoords[i]);
00096 //     return 0;
00097   }
00098 
00099 
00100   inline bool operator<(const degree& d1, const degree& d2)
00101   {
00102     return cmp(d1, d2) < 0;
00103   }
00104 
00105 
00106   inline bool operator<=(const degree& d1, const degree& d2)
00107   {
00108     return cmp(d1, d2) <= 0;
00109   }
00110 
00111 
00112   inline bool operator>(const degree& d1, const degree& d2)
00113   {
00114     return cmp(d1, d2) > 0;
00115   }
00116 
00117 
00118   inline bool operator>=(const degree& d1, const degree& d2)
00119   {
00120     return cmp(d1, d2) >= 0;
00121   }
00122 
00123 
00124   inline bool operator==(const degree& d1, const degree& d2)
00125   {
00126     return cmp(d1, d2) == 0;
00127   }
00128 
00129 
00130   inline bool operator!=(const degree& d1, const degree& d2)
00131   {
00132     return cmp(d1, d2) != 0;
00133   }
00134 
00135 
00136   inline size_t GradingDim(const degree& d)
00137   {
00138     return d.myGradingDim();
00139   }
00140 
00141 } // end of namespace CoCoA
00142 
00143 // RCS header/log in the next few lines
00144 // $Header: /Volumes/Home/cocoa/cvs-repository/CoCoALib-0.99/include/CoCoA/degree.H,v 1.1.1.1 2007/03/09 15:16:11 abbott Exp $
00145 // $Log: degree.H,v $
00146 // Revision 1.1.1.1  2007/03/09 15:16:11  abbott
00147 // Imported files
00148 //
00149 // Revision 1.5  2007/03/08 18:42:05  cocoa
00150 // Cleaned up whitespace.
00151 //
00152 // Revision 1.4  2006/12/06 17:17:44  cocoa
00153 // -- removed #include "config.H"
00154 //
00155 // Revision 1.3  2006/10/06 14:04:15  cocoa
00156 // Corrected position of #ifndef in header files.
00157 // Separated CoCoA_ASSERT into assert.H from config.H;
00158 // many minor consequential changes (have to #include assert.H).
00159 // A little tidying of #include directives (esp. in Max's code).
00160 //
00161 // Revision 1.2  2006/08/07 21:23:25  cocoa
00162 // Removed almost all publicly visible references to SmallExponent_t;
00163 // changed to long in all PPMonoid functions and SparsePolyRing functions.
00164 // DivMask remains to sorted out.
00165 //
00166 // Revision 1.1.1.1  2006/05/30 11:39:36  cocoa
00167 // Imported files
00168 //
00169 // Revision 1.1.1.1  2005/10/17 10:46:54  cocoa
00170 // Imported files
00171 //
00172 // Revision 1.5  2005/08/08 16:36:32  cocoa
00173 // Just checking in before going on holiday.
00174 // Don't really recall what changes have been made.
00175 // Added IsIndet function for RingElem, PPMonoidElem,
00176 // and a member function of OrdvArith.
00177 // Improved the way failed assertions are handled.
00178 //
00179 // Revision 1.4  2005/07/01 16:09:14  cocoa
00180 // Degrees may now have negative components.
00181 //
00182 // Revision 1.3  2005/06/27 16:23:04  cocoa
00183 // -- Added: GradingDim, operator+=, operator-=
00184 // -- Removed: IsSubtractable (and calls to it in operator-)
00185 //
00186 // Revision 1.2  2005/05/04 16:44:57  cocoa
00187 // -- changed: in FastCmp  ">" --> cmp
00188 //
00189 // Revision 1.1.1.1  2005/05/03 15:47:30  cocoa
00190 // Imported files
00191 //
00192 // Revision 1.4  2005/04/29 14:21:17  cocoa
00193 // -- changed: ElementType is now ZZ (was int)
00194 //
00195 // Revision 1.3  2005/04/19 14:06:04  cocoa
00196 // Added GPL and GFDL licence stuff.
00197 //
00198 // Revision 1.2  2005/02/28 15:58:56  cocoa
00199 // Resynch after some minor changes.
00200 //
00201 // Revision 1.1.1.1  2005/01/27 15:12:13  cocoa
00202 // Imported files
00203 //
00204 // Revision 1.6  2004/11/12 15:49:29  cocoa
00205 // Tidying prior to 0.90 release.
00206 // (a) documentation improved (or marked as poor)
00207 // (b) sundry minor improvements to the code
00208 //
00209 // Revision 1.5  2004/11/11 13:02:58  cocoa
00210 // -- added \include *.txt for doxygen
00211 //
00212 // Revision 1.4  2004/10/21 17:16:37  cocoa
00213 // Fairly major change: new OrdvArith namspace with various members,
00214 //   new global typedef  SmallExponent_t (defined in config.H).
00215 //
00216 // Revision 1.3  2004/05/27 16:14:02  cocoa
00217 // Minor revision for new coding conventions.
00218 //
00219 // Revision 1.2  2004/01/28 15:29:42  cocoa
00220 // Added IsZero function, and changed name of coordinate type used
00221 // in the representation of degree objects.
00222 //
00223 // Revision 1.1.1.1  2003/09/24 12:55:43  cocoa
00224 // Imported files
00225 //
00226 // Revision 1.3  2003/06/23 16:22:46  abbott
00227 // Minor cleaning prior to public release.
00228 //
00229 // Revision 1.2  2003/05/14 17:07:47  abbott
00230 // Changed name of PPOrderingBase (following PPOrdering.H).
00231 // Added (read-only) accessor function (via []).
00232 // Added FastCmp (like cmp but no checks) with inline definition.
00233 // Added top function (need a better name?).
00234 // Added SetComponent private member function.
00235 //
00236 // Revision 1.1  2002/12/18 18:19:06  abbott
00237 // Initial revision
00238 //
00239 
00240 #endif

Generated on Wed May 23 13:45:22 2007 for CoCoALib by  doxygen 1.4.6