CoCoALib-0.9905 date: 23 May 2007


PolyRing.H

Go to the documentation of this file.
00001 #ifndef CoCoA_PolyRing_H
00002 #define CoCoA_PolyRing_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 abstract class PolyRing
00024 
00025 
00026 #include "CoCoA/error.H"
00027 #include "CoCoA/ring.H"
00028 
00029 #include <cstddef>
00030 //using std::size_t;
00031 #include <iosfwd>
00032 //using std::ostream;
00033 #include <vector>
00034 //using std::vector;
00035 
00036 
00037 namespace CoCoA
00038 {
00039 
00040   class PolyRingBase: public RingBase
00041   {
00042   private: // This class has no data members.
00043   public:
00044     /*----------------------------------------------------------------------
00045      Member functions every concrete PolyRing must have
00046      in addition to those of a plain ring.
00047     ----------------------------------------------------------------------*/
00048 
00049     virtual std::size_t myNumIndets() const = 0;
00050     virtual const ring& myCoeffRing() const = 0;
00051 
00052     ///@name Simple functions on polynomials
00053     //@{
00054     virtual const std::vector<RingElem>& myIndets() const = 0;
00055     virtual void myIndetPower(RawPtr rawf, std::size_t var, unsigned int exp) const = 0;
00056     virtual std::size_t myNumTerms(ConstRawPtr rawf) const = 0;
00057     virtual bool myIsConstant(ConstRawPtr rawf) const = 0;
00058     virtual bool myIsIndet(std::size_t& index, ConstRawPtr rawf) const = 0;
00059     virtual bool myIsMonomial(ConstRawPtr rawf) const = 0;
00060     virtual std::size_t myStdDeg(ConstRawPtr rawf) const = 0;
00061     virtual long myLog(ConstRawPtr rawf, std::size_t var) const = 0;
00062     virtual ConstRefRingElem myLC(ConstRawPtr rawf) const = 0;
00063     virtual void myContent(RawPtr rawcontent, ConstRawPtr rawf) const = 0;
00064     virtual void myRemoveBigContent(RawPtr rawf) const = 0;
00065     virtual void myMulByCoeff(RawPtr rawf, ConstRawPtr rawc) const = 0;
00066     virtual void myDivByCoeff(RawPtr rawf, ConstRawPtr rawc) const = 0;
00067     virtual void myDeriv(RawPtr rawlhs, ConstRawPtr rawf, ConstRawPtr rawx) const = 0; ///< lhs = deriv(f, x)
00068     //@}
00069 
00070 
00071     virtual RingHom myHomCtor(const ring& codomain, const RingHom& CoeffHom, const std::vector<RingElem>& IndetImages) const = 0;
00072     virtual const RingHom& myCoeffEmbeddingHom() const = 0;
00073   };
00074 
00075 
00076   /*-----------------------------------------------------------------*/
00077   /** \include PolyRing.txt  */
00078   /*-----------------------------------------------------------------*/
00079   class PolyRing: public ring
00080   {
00081     // Data member inherited from class ring.
00082   public:
00083     explicit PolyRing(const PolyRingBase* RingPtr);
00084     // Default copy ctor works fine.
00085     // Default dtor works fine.
00086   private: // disable assignment
00087     PolyRing& operator=(const PolyRing& rhs); // NEVER DEFINED -- assignment disabled
00088   public:
00089     const PolyRingBase* operator->() const; // allow member fns to be called
00090   };
00091 
00092 
00093   bool IsPolyRing(const ring& R);                         // inline
00094   PolyRing AsPolyRing(const ring& R);                     // inline
00095   const ring& CoeffRing(const PolyRing& Rx);              // inline
00096   std::size_t NumIndets(const PolyRing& Rx);              // inline
00097   const RingHom& CoeffEmbeddingHom(const PolyRing& Rx);   // inline
00098   const std::vector<RingElem>& indets(const PolyRing& Rx);// inline
00099 
00100   const RingElem& indet(const PolyRing& P, std::size_t var); // returns x[var] as a polynomial
00101   RingElem IndetPower(const PolyRing& P, std::size_t var, unsigned int n); // returns x[var]^n as a polynomial
00102   std::size_t NumTerms(ConstRefRingElem f);
00103   bool IsMonomial(ConstRefRingElem f);        ///< f == coeff*pp
00104   bool IsConstant(ConstRefRingElem f);        ///< f == coeff
00105   bool IsIndet(ConstRefRingElem f);           ///< f == x[i]
00106   bool IsIndet(std::size_t& index, ConstRefRingElem f);  ///< f == x[i]; index=i
00107   std::size_t StdDeg(ConstRefRingElem f);                 // inline
00108   std::size_t deg(ConstRefRingElem f);                    // inline (identical to StdDeg)
00109   long log(ConstRefRingElem f, std::size_t var);
00110   ConstRefRingElem LC(ConstRefRingElem f);                // inline
00111   RingElem content(ConstRefRingElem f);
00112   RingElem deriv(ConstRefRingElem f, ConstRefRingElem x); ///< derivative of f w.r.t. x, x must be an indeterminate
00113   RingElem deriv(ConstRefRingElem f, std::size_t x);      ///< here x is the index of the indeterminate
00114 
00115   RingHom PolyRingHom(const PolyRing& domain, const ring& codomain, const RingHom& CoeffHom, const std::vector<RingElem>& IndetImages); ///< R[x] -> S, defined by CoeffHom: R->S and x->IndetImages
00116   RingHom PolyAlgebraHom(const PolyRing& domain, const ring& codomain, const std::vector<RingElem>& IndetImages); ///< R[x] -> R or R[x]->R[y], defined by R->R and x->IndetImages
00117 
00118 
00119   //----------------------------------------------------------------------
00120   // Inline functions
00121 
00122   inline bool IsPolyRing(const ring& R)
00123   {
00124     return dynamic_cast<const PolyRingBase*>(R.myRawPtr()) != 0;
00125   }
00126 
00127 
00128   inline PolyRing::PolyRing(const PolyRingBase* RingPtr):
00129       ring(RingPtr)
00130   {}
00131 
00132 
00133   inline PolyRing AsPolyRing(const ring& R)
00134   {
00135     if (!IsPolyRing(R))
00136       CoCoA_ERROR(ERR::NotPolyRing, "AsPolyRing(ring)");
00137     return PolyRing(static_cast<const PolyRingBase*>(R.myRawPtr()));
00138   }
00139 
00140 
00141   inline const PolyRingBase* PolyRing::operator->() const
00142   {
00143     return static_cast<const PolyRingBase*>(ring::operator->());
00144   }
00145 
00146 
00147   inline const ring& CoeffRing(const PolyRing& Rx)
00148   {
00149     return Rx->myCoeffRing();
00150   }
00151 
00152 
00153   inline std::size_t NumIndets(const PolyRing& Rx)
00154   {
00155     return Rx->myNumIndets();
00156   }
00157 
00158 
00159   inline const RingHom& CoeffEmbeddingHom(const PolyRing& Rx)
00160   {
00161     return Rx->myCoeffEmbeddingHom();
00162   }
00163 
00164 
00165   inline const std::vector<RingElem>& indets(const PolyRing& Rx)
00166   {
00167     return Rx->myIndets();
00168   }
00169 
00170 
00171   inline std::size_t StdDeg(ConstRefRingElem f)
00172   {
00173     if (!IsPolyRing(owner(f)))
00174       CoCoA_ERROR(ERR::NotElemPolyRing, "StdDeg(f)");
00175     if (IsZero(f)) CoCoA_ERROR(ERR::ZeroPoly, "StdDeg(f)");
00176     return AsPolyRing(owner(f))->myStdDeg(raw(f));
00177   }
00178 
00179   inline std::size_t deg(ConstRefRingElem f)
00180   {
00181     return StdDeg(f);
00182   }
00183 
00184 
00185   inline ConstRefRingElem LC(ConstRefRingElem f)
00186   {
00187     if (!IsPolyRing(owner(f)))
00188       CoCoA_ERROR(ERR::NotElemPolyRing, "LC(f)");
00189     if (IsZero(f)) CoCoA_ERROR(ERR::ZeroPoly, "LC(f)");
00190     return AsPolyRing(owner(f))->myLC(raw(f));
00191   }
00192 
00193 
00194 } // end of namespace CoCoA
00195 
00196 
00197 
00198 // RCS header/log in the next few lines
00199 // $Header: /Volumes/Home/cocoa/cvs-repository/CoCoALib-0.99/include/CoCoA/PolyRing.H,v 1.1.1.1 2007/03/09 15:16:11 abbott Exp $
00200 // $Log: PolyRing.H,v $
00201 // Revision 1.1.1.1  2007/03/09 15:16:11  abbott
00202 // Imported files
00203 //
00204 // Revision 1.13  2007/03/08 18:42:05  cocoa
00205 // Cleaned up whitespace.
00206 //
00207 // Revision 1.12  2007/03/07 13:59:45  bigatti
00208 // -- added PolyAlgebraHom(Rx, Ry, IndetImages)
00209 //
00210 // Revision 1.11  2007/03/05 21:06:07  cocoa
00211 // New names for homomorphism pseudo-ctors: removed the "New" prefix.
00212 //
00213 // Revision 1.10  2007/02/28 13:58:35  bigatti
00214 // -- added documentation for IsMonomial, IsConstant, IsIndet
00215 //
00216 // Revision 1.9  2007/02/28 13:51:59  bigatti
00217 // -- added function IsMonomial
00218 //
00219 // Revision 1.8  2007/01/11 14:06:15  cocoa
00220 // -- added prefix "raw" to RawPtr arguments names
00221 //
00222 // Revision 1.7  2006/12/06 17:15:26  cocoa
00223 // -- removed #include "config.H"
00224 //
00225 // Revision 1.6  2006/11/21 18:09:24  cocoa
00226 // -- added myIsMonomial
00227 // -- implemented myIsOne, myIsMinusOne, myIsConstant, myIsIndet in SparsePolyRing
00228 // -- removed the 4 functions from DistrMPoly(..) and RingDistrMPoly(..)
00229 // -- changed all names of RawPtr arguments into "raw(..)"
00230 //
00231 // Revision 1.5  2006/11/20 15:55:03  cocoa
00232 // ring is now a class again.  Improved definitions of operator-> in derived classes.
00233 //
00234 // Revision 1.4  2006/11/03 14:01:46  cocoa
00235 // -- changed: reference counting in ring, PPMonoids and OrdvArith now
00236 //    uses SmartPtrIRC
00237 //
00238 // Revision 1.3  2006/10/06 14:04:15  cocoa
00239 // Corrected position of #ifndef in header files.
00240 // Separated CoCoA_ASSERT into assert.H from config.H;
00241 // many minor consequential changes (have to #include assert.H).
00242 // A little tidying of #include directives (esp. in Max's code).
00243 //
00244 // Revision 1.2  2006/08/07 21:23:25  cocoa
00245 // Removed almost all publicly visible references to SmallExponent_t;
00246 // changed to long in all PPMonoid functions and SparsePolyRing functions.
00247 // DivMask remains to sorted out.
00248 //
00249 // Revision 1.1.1.1  2006/05/30 11:39:37  cocoa
00250 // Imported files
00251 //
00252 // Revision 1.3  2006/03/12 21:28:34  cocoa
00253 // Major check in after many changes
00254 //
00255 // Revision 1.2  2006/02/20 22:41:20  cocoa
00256 // All forms of the log function for power products now return SmallExponent_t
00257 // (instead of int).  exponents now resizes the vector rather than requiring
00258 // the user to pass in the correct size.
00259 //
00260 // Revision 1.1.1.1  2005/10/17 10:46:54  cocoa
00261 // Imported files
00262 //
00263 // Revision 1.5  2005/08/08 16:36:33  cocoa
00264 // Just checking in before going on holiday.
00265 // Don't really recall what changes have been made.
00266 // Added IsIndet function for RingElem, PPMonoidElem,
00267 // and a member function of OrdvArith.
00268 // Improved the way failed assertions are handled.
00269 //
00270 // Revision 1.4  2005/07/19 15:30:20  cocoa
00271 // A first attempt at iterators over sparse polynomials.
00272 // Main additions are to SparsePolyRing, DistrMPoly*.
00273 // Some consequential changes to PPMonoid*.
00274 //
00275 // Revision 1.3  2005/07/01 16:08:16  cocoa
00276 // Friday check-in.  Major change to structure under PolyRing:
00277 // now SparsePolyRing and DUPolyRing are separated (in preparation
00278 // for implementing iterators).
00279 //
00280 // A number of other relatively minor changes had to be chased through
00281 // (e.g. IndetPower).
00282 //
00283 // Revision 1.2  2005/06/22 14:47:56  cocoa
00284 // PPMonoids and PPMonoidElems updated to mirror the structure
00285 // used for rings and RingElems.  Many consequential changes.
00286 //
00287 // Revision 1.1.1.1  2005/05/03 15:47:30  cocoa
00288 // Imported files
00289 //
00290 // Revision 1.8  2005/04/29 15:42:02  cocoa
00291 // Improved documentation for GMPAllocator.
00292 // Added example program for GMPAllocator.
00293 // Added example program for simple ops on polynomials.
00294 // Added two new ctors for (principal) ideals (from long, and from ZZ).
00295 // Added (crude) printing for PPMonoids.
00296 // Updated library.H (#included GMPAllocator.H).
00297 //
00298 // Revision 1.7  2005/04/27 16:14:56  cocoa
00299 // Cleaned up example programs -- added "free use" permit.
00300 // Changed a couple of ErrorInfo object names, and added
00301 // ERR::NotTrueGCDDomain.
00302 //
00303 // Revision 1.6  2005/04/20 15:40:48  cocoa
00304 // Major change: modified the standard way errors are to be signalled
00305 // (now via a macro which records filename and line number).  Updated
00306 // documentation in error.txt accordingly.
00307 //
00308 // Improved the documentation in matrix.txt (still more work to be done).
00309 //
00310 // Revision 1.5  2005/04/19 14:06:04  cocoa
00311 // Added GPL and GFDL licence stuff.
00312 //
00313 // Revision 1.4  2005/03/11 18:36:36  cocoa
00314 // -- new: NewPolyRingHom Rx-->Ry ; code is still commented out
00315 //
00316 // Revision 1.3  2005/02/11 16:45:24  cocoa
00317 // Removed the useless and misleading functions myInit and myKill
00318 // from the SmallFp*Impl classes; various consequential changes.
00319 //
00320 // Revision 1.2  2005/02/11 14:15:20  cocoa
00321 // New style ring elements and references to ring elements;
00322 // I hope I have finally got it right!
00323 //
00324 // Revision 1.1.1.1  2005/01/27 15:12:13  cocoa
00325 // Imported files
00326 //
00327 // Revision 1.15  2004/12/16 13:35:01  cocoa
00328 // Added new monomial functions (with more coherent signatures).
00329 //
00330 // Revision 1.14  2004/11/25 16:14:21  cocoa
00331 // (1) Fixed definition of specialization of std::swap template function
00332 //     so that it compiles with gcc 3.4.3
00333 // (2) Implemented monomial function for polynomial rings.
00334 // (3) Added one(PPM) and PPM->myOne() functions.
00335 //
00336 // Revision 1.13  2004/11/19 16:15:51  cocoa
00337 // (a) Removed unused error message about degree of zero;
00338 //     replaced it by a more general message about needing a
00339 //     non-zero polynomial (for various ops such as LC, LPP).
00340 // (b) Added some missing arg checking in LC, LPP and deg
00341 //     (for elems of a PolyRing).
00342 // (c) Updated some commented out code in GPair and GPoly.
00343 //
00344 // Revision 1.12  2004/11/19 15:44:27  cocoa
00345 // Changed names of "casting" functions which convert a ring into
00346 // one with a more special structure (e.g. FractionField).  These
00347 // functions now have names starting with "As".  There were several
00348 // consequential changes.
00349 //
00350 // Revision 1.11  2004/11/12 15:49:29  cocoa
00351 // Tidying prior to 0.90 release.
00352 // (a) documentation improved (or marked as poor)
00353 // (b) sundry minor improvements to the code
00354 //
00355 // Revision 1.10  2004/11/08 14:04:47  cocoa
00356 // -- small changes for doxygen support
00357 //
00358 // Revision 1.9  2004/10/29 16:05:03  cocoa
00359 // -- changed PPOrdering::ExpvElem --> SmallExponent_t
00360 //
00361 // Revision 1.8  2004/07/27 16:03:39  cocoa
00362 // Added IsCommutative test and IamCommutative member function
00363 // to all rings.  Tidied geobuckets a little.
00364 //
00365 // Revision 1.7  2004/07/20 15:04:06  cocoa
00366 // The next step in the new "ring element" conversion process:
00367 // handling the case of creating a "const RefRingElem" object
00368 // (since C++ refuses to do this properly itself).
00369 //
00370 // Revision 1.6  2004/06/29 17:10:22  cocoa
00371 // Partially tidied use of "protected" and "private" in various
00372 // base classes.  Checking in at the end of the day -- it works,
00373 // and I wouldn't want it to be lost next time point's disk
00374 // misbehaves.
00375 //
00376 // Revision 1.5  2004/05/24 15:52:14  cocoa
00377 // Major update:
00378 //   new error mechanism
00379 //   many fixes
00380 //   RingHoms almost work now
00381 //   RingFloat much improved
00382 //
00383 // Revision 1.4  2004/01/28 15:27:55  cocoa
00384 // Added function CmpDeg and related member functions myCmpDeg.
00385 //
00386 // Revision 1.3  2003/10/17 10:51:06  cocoa
00387 // Major cleaning, and new naming convention.
00388 //
00389 // Revision 1.2  2003/10/09 12:18:42  cocoa
00390 // New coding convention for rings.
00391 //
00392 // Revision 1.6  2003/06/23 17:04:39  abbott
00393 // Minor cleaning prior to public release.
00394 //
00395 // Revision 1.5  2003/05/30 12:24:03  abbott
00396 // Added CoeffEmbeddingHom.  Added declaration of plain multiplication
00397 // which had become hidden by C++'s "extraordinary" visibility rules.
00398 // ["extraordinary" is the abridged adjective]
00399 //
00400 // Revision 1.4  2003/05/14 16:50:48  abbott
00401 // WIDESPREAD CHANGES, some consequential, and some due to restructuring.
00402 // Updated AbstractRing to RingBase (hmm, should have checked in
00403 // ages ago), and numerous other related and consequential changes.
00404 // Eliminated PolyRing::owner since it cannot work.
00405 // Renamed the old class PolyRing to PolyRingBase, and created a
00406 // new class called PolyRing.
00407 //
00408 // Revision 1.3  2002/11/18 17:59:03  bigatti
00409 // - added  DontSkipLMg  in  SkipLMFlag  enum
00410 // - added  ReductionStep  and  ReductionStepGCD
00411 //
00412 // Revision 1.2  2002/11/15 15:14:47  abbott
00413 // Revised according to the renaming in ring.H.
00414 // Extensively modified and reorganized.  Still in a state of flux.
00415 //
00416 // Revision 1.1  2002/06/22 16:55:27  abbott
00417 // Initial revision
00418 //
00419 
00420 #endif

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