CoCoALib-0.9905 date: 23 May 2007


OrdvArith.H

Go to the documentation of this file.
00001 #ifndef CoCoA_OrdvArith_H
00002 #define CoCoA_OrdvArith_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 #include "CoCoA/SmartPtrIRC.H"
00024 
00025 #include <vector>
00026 // using std::vector;
00027 
00028 
00029 namespace CoCoA
00030 {
00031 
00032   class ConstRefRingElem; // forward declaration -- defined in ring.H
00033   class PPOrdering;       // forward declaration -- defined in PPOrdering.H
00034   class degree;           // forward declaration -- defined in degree.H
00035   class matrix;           // forward declaration -- defined in matrix.H
00036 
00037   namespace OrdvArith
00038   {
00039 
00040     typedef unsigned int OrdvElem;
00041 
00042     class base; // forward reference
00043     class reference
00044     {
00045     public:
00046       explicit reference(const base* ptr): mySmartPtr(ptr) {}
00047       // assignment disabled because SmartPtrIRC has no assignment
00048       const base* operator->() const { return mySmartPtr.operator->(); }  ///< Allow const member fns to be called.
00049       const base* myRawPtr() const { return mySmartPtr.myRawPtr(); }
00050       bool operator==(const reference& ref) const { return mySmartPtr==ref.mySmartPtr; }
00051     private: // data members
00052       SmartPtrIRC<const base> mySmartPtr;
00053     };
00054 
00055     //    class base
00056     class base: protected IntrusiveReferenceCount
00057     {
00058       friend class SmartPtrIRC<const base>;  // morally "friend base", so it can alter reference count
00059 
00060     protected:
00061       base(std::size_t NumIndets, std::size_t OrdvWords, std::size_t NumOrdvEntries);
00062       virtual ~base();
00063 
00064     public:
00065       virtual void myAssignZero(OrdvElem* ordv) const;
00066       virtual void myAssignFromExpv(OrdvElem* ordv, const std::vector<long>& expv) const = 0;
00067       void myAssign(OrdvElem* dest, const OrdvElem* src) const;
00068       void mySwap(OrdvElem* ordv1, OrdvElem* ordv2) const;
00069       void myMul(OrdvElem* ordv, const OrdvElem* ordv1, const OrdvElem* ordv2) const;
00070       virtual void myMulIndetPower(OrdvElem* ordv, std::size_t var, unsigned long exp) const; ///< NOT PURE!!
00071       void myDiv(OrdvElem* ordv, const OrdvElem* ordv1, const OrdvElem* ordv2) const;
00072       void myPower(OrdvElem* ordv, const OrdvElem* ordv1, unsigned long exp) const;
00073       int myCmp(const OrdvElem* l_ordv, const OrdvElem* r_ordv) const;
00074       void myComputeExpvBuffer(const OrdvElem* ordv) const;
00075       virtual void myComputeExpv(std::vector<long>& expv, const OrdvElem* ordv) const = 0;
00076       virtual long myLog(const OrdvElem* ordv, std::size_t var) const = 0;
00077       virtual std::size_t myStdDeg(const OrdvElem* ordv) const;
00078       virtual void myWDeg(degree& d, const OrdvElem* ordv) const;
00079       virtual int myCmpWDeg(const OrdvElem* ordv1, const OrdvElem* ordv2) const;
00080       virtual bool myIsZero(const OrdvElem* ordv) const;
00081       virtual bool myIsIndet(std::size_t& index, const OrdvElem* ordv) const;
00082       virtual void myOutputSelf(std::ostream& out) const = 0;
00083 
00084     protected:
00085       OrdvElem myOrdvGetNth(const OrdvElem* ordv, std::size_t n) const;
00086       void myCompress(OrdvElem* ordv, const std::vector<OrdvElem>& buffer) const;
00087       void myDecompress(std::vector<OrdvElem>& buffer, const OrdvElem* ordv, std::size_t NumCompts) const;
00088 
00089     protected: // data members
00090       OrdvElem myOrdvMask;
00091       std::size_t myPackingDensity;
00092       std::size_t myBitsPerOrdvEntry;
00093       mutable std::vector<OrdvElem> myOrdvBuffer;
00094       mutable std::vector<long> myExpvBuffer;
00095     protected:
00096       friend std::size_t OrdvWords(const reference& OA);
00097 
00098       std::size_t myNumIndets;        ///< Number of indeterminates
00099       std::size_t myGradingDim;       ///< zero if not graded, otherwise grading is in Z^myGradingDim
00100       std::size_t myOrdvWords;        ///< byte-size-of-an-order-vector/sizeof(OrdvElem)
00101       std::size_t myOrdvWordsForCmp;  ///< might be smaller than myOrdvWords
00102     };
00103 
00104 
00105     class LexImpl: public base
00106     {
00107     public:
00108       LexImpl(std::size_t NumIndets);
00109       virtual void myAssignFromExpv(OrdvElem* ordv, const std::vector<long>& expv) const;
00110       virtual void myComputeExpv(std::vector<long>& expv, const OrdvElem* ordv) const;
00111       virtual long myLog(const OrdvElem* ordv, std::size_t var) const;
00112       virtual void myOutputSelf(std::ostream& out) const;
00113     };
00114 
00115 
00116     class StdDegLexImpl: public base
00117     {
00118     public:
00119       StdDegLexImpl(std::size_t NumIndets);
00120       virtual void myAssignFromExpv(OrdvElem* ordv, const std::vector<long>& expv) const;
00121       virtual void myComputeExpv(std::vector<long>& expv, const OrdvElem* ordv) const;
00122       virtual std::size_t myStdDeg(const OrdvElem* ordv) const;
00123       virtual long myLog(const OrdvElem* ordv, std::size_t var) const;
00124       virtual void myOutputSelf(std::ostream& out) const;
00125     };
00126 
00127 
00128     class StdDegRevLexImpl: public base
00129     {
00130     public:
00131       StdDegRevLexImpl(std::size_t NumIndets);
00132       virtual void myAssignFromExpv(OrdvElem* ordv, const std::vector<long>& expv) const;
00133       virtual void myComputeExpv(std::vector<long>& expv, const OrdvElem* ordv) const;
00134       virtual std::size_t myStdDeg(const OrdvElem* ordv) const;
00135       virtual long myLog(const OrdvElem* ordv, std::size_t var) const;
00136       virtual void myOutputSelf(std::ostream& out) const;
00137     };
00138 
00139 
00140     class MatrixOrderingImpl: public base // only partially implemented
00141     {
00142     public:
00143       MatrixOrderingImpl(std::size_t NumIndets, std::size_t GradingDim, const matrix& OrderMatrix);
00144       virtual void myAssignFromExpv(OrdvElem* ordv, const std::vector<long>& expv) const;
00145       virtual void myComputeExpv(std::vector<long>& expv, const OrdvElem* ordv) const;
00146       virtual long myLog(const OrdvElem* ordv, std::size_t var) const;
00147       virtual void myOutputSelf(std::ostream& out) const;
00148     private:
00149       int myOrderMatrixDet;
00150       std::vector< std::vector<int> > myOrderMatrix;
00151       std::vector< std::vector<int> > myAdjointOrderMatrix;
00152     };
00153 
00154 
00155     class MatrixOrderingMod32749Impl: public base
00156     {
00157     public:
00158       MatrixOrderingMod32749Impl(std::size_t NumIndets, std::size_t GradingDim, const matrix& OrderMatrix);
00159       virtual void myAssignFromExpv(OrdvElem* ordv, const std::vector<long>& expv) const;
00160       virtual void myComputeExpv(std::vector<long>& expv, const OrdvElem* ordv) const;
00161       virtual long myLog(const OrdvElem* ordv, std::size_t var) const;
00162       virtual void myOutputSelf(std::ostream& out) const;
00163     private:
00164       std::vector< std::vector<int> > myOrderMatrix;
00165       std::vector< std::vector<int> > myInverseOrderMatrix;
00166     };
00167 
00168 
00169 
00170     //---------------------------------------------------------------------------
00171     // INLINE FUNCTIONS
00172 
00173 
00174     inline std::size_t OrdvWords(const reference& OA)
00175     {
00176       return OA->myOrdvWords;
00177     }
00178 
00179 
00180     inline void base::myMul(OrdvElem* ordv, const OrdvElem* ordv1, const OrdvElem* ordv2) const
00181     {
00182       for (std::size_t i=0; i < myOrdvWords; ++i)
00183         ordv[i] = ordv1[i]+ordv2[i];
00184     }
00185 
00186 
00187     inline void base::myDiv(OrdvElem* ordv, const OrdvElem* ordv1, const OrdvElem* ordv2) const
00188     {
00189       for (std::size_t i=0; i < myOrdvWords; ++i)
00190         ordv[i] = ordv1[i]-ordv2[i];
00191     }
00192 
00193 
00194     inline int base::myCmp(const OrdvElem* l_ordv, const OrdvElem* r_ordv) const
00195     {
00196       for (std::size_t i=0; i < myOrdvWordsForCmp; ++i)
00197         if (l_ordv[i] != r_ordv[i]) return (l_ordv[i] < r_ordv[i])? -1:1;
00198       return 0;
00199     }
00200 
00201 
00202     inline void base::myComputeExpvBuffer(const OrdvElem* ordv) const
00203     {
00204       myComputeExpv(myExpvBuffer, ordv);
00205     }
00206 
00207 
00208     inline std::ostream& operator<<(std::ostream& out, const OrdvArith::reference& OA)
00209     {
00210       OA->myOutputSelf(out);
00211       return out;
00212     }
00213 
00214   } // end of namespace OrdvArith
00215 
00216 
00217   OrdvArith::reference NewOrdvArith(const PPOrdering& PPO);
00218 
00219   std::vector< std::vector<int> > NewElimMatrix(std::size_t NumIndets, const std::vector<std::size_t>& ElimIndets);
00220   std::vector< std::vector<int> > NewElimMatrixAdj(std::size_t NumIndets, const std::vector<std::size_t>& ElimIndets);
00221 
00222 
00223 
00224 
00225 } // end of namespace CoCoA
00226 
00227 
00228 
00229 // RCS header/log in the next few lines
00230 // $Header: /Volumes/Home/cocoa/cvs-repository/CoCoALib-0.99/include/CoCoA/OrdvArith.H,v 1.1.1.1 2007/03/09 15:16:11 abbott Exp $
00231 // $Log: OrdvArith.H,v $
00232 // Revision 1.1.1.1  2007/03/09 15:16:11  abbott
00233 // Imported files
00234 //
00235 // Revision 1.11  2007/03/08 18:42:06  cocoa
00236 // Cleaned up whitespace.
00237 //
00238 // Revision 1.10  2007/03/07 13:49:30  bigatti
00239 // -- minor cleanup
00240 //
00241 // Revision 1.9  2007/03/02 10:47:53  cocoa
00242 // First stage of RingZ modifications -- tests do not compile currently, Anna will fix this.
00243 //
00244 // Revision 1.8  2006/12/06 17:14:12  cocoa
00245 // -- removed #include "config.H"
00246 //
00247 // Revision 1.7  2006/11/24 17:29:12  cocoa
00248 // -- reorganized includes of header files
00249 //
00250 // Revision 1.6  2006/11/23 17:33:10  cocoa
00251 // -- changed: OrdvArith::base is now a class (instead of typedef)
00252 //
00253 // Revision 1.5  2006/11/03 15:37:47  cocoa
00254 // -- cleaned up code after testing on usage of SmartPtrIRC
00255 //
00256 // Revision 1.4  2006/11/03 14:01:46  cocoa
00257 // -- changed: reference counting in ring, PPMonoids and OrdvArith now
00258 //    uses SmartPtrIRC
00259 //
00260 // Revision 1.3  2006/10/06 14:04:15  cocoa
00261 // Corrected position of #ifndef in header files.
00262 // Separated CoCoA_ASSERT into assert.H from config.H;
00263 // many minor consequential changes (have to #include assert.H).
00264 // A little tidying of #include directives (esp. in Max's code).
00265 //
00266 // Revision 1.2  2006/08/07 21:23:25  cocoa
00267 // Removed almost all publicly visible references to SmallExponent_t;
00268 // changed to long in all PPMonoid functions and SparsePolyRing functions.
00269 // DivMask remains to sorted out.
00270 //
00271 // Revision 1.1.1.1  2006/05/30 11:39:37  cocoa
00272 // Imported files
00273 //
00274 // Revision 1.5  2006/03/15 18:09:31  cocoa
00275 // Changed names of member functions which print out their object
00276 // into myOutputSelf -- hope this will appease the Intel C++ compiler.
00277 //
00278 // Revision 1.4  2006/03/12 21:28:34  cocoa
00279 // Major check in after many changes
00280 //
00281 // Revision 1.3  2006/02/20 22:41:20  cocoa
00282 // All forms of the log function for power products now return SmallExponent_t
00283 // (instead of int).  exponents now resizes the vector rather than requiring
00284 // the user to pass in the correct size.
00285 //
00286 // Revision 1.2  2006/01/20 17:44:20  cocoa
00287 // Friday afternoon check-in: you have been warned!
00288 // Fixed ref counting bug in SmartPtrIRC.
00289 // Added sum/product functions in tmp.H.
00290 // Minor tidying here and there.
00291 //
00292 // Revision 1.1.1.1  2005/10/17 10:46:54  cocoa
00293 // Imported files
00294 //
00295 // Revision 1.5  2005/08/08 16:36:33  cocoa
00296 // Just checking in before going on holiday.
00297 // Don't really recall what changes have been made.
00298 // Added IsIndet function for RingElem, PPMonoidElem,
00299 // and a member function of OrdvArith.
00300 // Improved the way failed assertions are handled.
00301 //
00302 // Revision 1.4  2005/07/01 16:08:16  cocoa
00303 // Friday check-in.  Major change to structure under PolyRing:
00304 // now SparsePolyRing and DUPolyRing are separated (in preparation
00305 // for implementing iterators).
00306 //
00307 // A number of other relatively minor changes had to be chased through
00308 // (e.g. IndetPower).
00309 //
00310 // Revision 1.3  2005/06/23 15:42:41  cocoa
00311 // Fixed typo in GNU fdl -- all doc/*.txt files affected.
00312 // Minor corrections to PPMonoid (discovered while writing doc).
00313 //
00314 // Revision 1.2  2005/06/22 14:47:56  cocoa
00315 // PPMonoids and PPMonoidElems updated to mirror the structure
00316 // used for rings and RingElems.  Many consequential changes.
00317 //
00318 // Revision 1.1.1.1  2005/05/03 15:47:30  cocoa
00319 // Imported files
00320 //
00321 // Revision 1.3  2005/04/19 14:06:04  cocoa
00322 // Added GPL and GFDL licence stuff.
00323 //
00324 // Revision 1.2  2005/02/11 14:15:20  cocoa
00325 // New style ring elements and references to ring elements;
00326 // I hope I have finally got it right!
00327 //
00328 // Revision 1.1.1.1  2005/01/27 15:12:13  cocoa
00329 // Imported files
00330 //
00331 // Revision 1.9  2004/11/29 16:22:35  cocoa
00332 // -- added function for computing adjoint and inverse for DenseMatrix
00333 //    (so adjoint/inverse matrix is computed by OrdvArith and is no
00334 //    longer needed by PPOrdering)
00335 //
00336 // Revision 1.8  2004/11/12 16:11:05  cocoa
00337 // Some missing semicolons... oops.
00338 // Now it compiles OK.
00339 //
00340 // Revision 1.7  2004/11/08 14:03:32  cocoa
00341 // -- small changes for doxygen support
00342 //
00343 // Revision 1.6  2004/11/05 16:37:27  cocoa
00344 // -- change: inverse matrix computed modulo 32749 using RingHom
00345 //
00346 // Revision 1.5  2004/11/03 17:50:31  cocoa
00347 // -- added  mySetMatrix and mySetInverseMatrixTmp  for MatrixOrderingMod32749Impl
00348 //
00349 // Revision 1.4  2004/11/02 18:21:21  cocoa
00350 // -- changed: myGetExpvBuffer --> myExpvBufferRef
00351 //
00352 // Revision 1.3  2004/11/02 15:05:30  cocoa
00353 // -- new: base::myGetExpvBuffer()
00354 // -- new: base::myComputeExpvBuffer
00355 // -- fixed: reference count in destructor
00356 // -- new field: myExpvBuffer
00357 // -- changed: class base is now protected
00358 //
00359 // Revision 1.2  2004/10/29 15:29:55  cocoa
00360 // -- added MatrixOrderingMod32749Impl (not tested)
00361 // -- added myOAPtr
00362 //
00363 // Revision 1.1  2004/10/21 17:16:37  cocoa
00364 // Fairly major change: new OrdvArith namspace with various members,
00365 //   new global typedef  SmallExponent_t (defined in config.H).
00366 //
00367 
00368 #endif

Generated on Wed May 23 13:43:35 2007 for CoCoALib by  doxygen 1.4.6