CoCoALib-0.9905 date: 23 May 2007


ideal.H

Go to the documentation of this file.
00001 #ifndef CoCoA_ideal_H
00002 #define CoCoA_ideal_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 ideal
00024 
00025 
00026 #include "CoCoA/ring.H"
00027 #include "CoCoA/bool3.H"
00028 #include "CoCoA/SmartPtrIRC.H"
00029 
00030 #include <cstddef>
00031 //using std::size_t;
00032 #include <iosfwd>
00033 //using std::ostream;
00034 #include <vector>
00035 //using std::vector;
00036 
00037 namespace CoCoA
00038 {
00039 
00040   class OpenMathOutput; // forward declaration -- defined in OpenMath.H
00041 
00042   class IdealBase; // fwd declaration, defined later in this file
00043   /*-----------------------------------------------------------------*/
00044   /** \include ideal.txt  */
00045   /*-----------------------------------------------------------------*/
00046   class ideal
00047   {
00048   public:
00049     explicit ideal(IdealBase* IPtr);    //??? public???
00050     explicit ideal(const ring& R);                           // make the zero ideal
00051     ideal(const ring& R, ConstRefRingElem r);                // make a principal ideal
00052     ideal(const ring& R, const ZZ& N);                       // make a principal ideal
00053     ideal(const ring& R, long n);                            // make a principal ideal
00054     ideal(const ring& R, const std::vector<RingElem>& gens); // make the ideal generated by gens
00055     ideal(const ideal& copy);          // ???? explicit???
00056     ideal& operator=(const ideal& rhs);
00057     ~ideal();
00058 
00059     const IdealBase* myIdealPtr() const;
00060 //???    IdealBase* operator->();              // allow non-const member fns to be called
00061     const IdealBase* operator->() const;  // allow const member fns to be called
00062   private:
00063     IdealBase* myPtr;
00064     friend IdealBase* MakeUnique(ideal& I);
00065   };
00066 
00067 //   class IdealBase; // fwd decl, defn immediately below.
00068 //   typedef SmartPtrIRC<const IdealBase> ideal;  //???? const???
00069 
00070   class IdealBase  //???: protected IntrusiveReferenceCount
00071   {
00072   protected: // ref count accessible only to friends and derived classes.
00073     friend class ideal;
00074     friend IdealBase* MakeUnique(ideal& I); // so it can call RefCountIsOne
00075     mutable std::size_t myRefCount; // every ideal has an intrusive reference count
00076     void myRefCountInc() const;
00077     void myRefCountDec() const;
00078     bool myRefCountIsOne() const;
00079 
00080   protected:
00081     mutable bool3 IamPrimeFlag;       // NB these two values are NOT INDEPENDENT
00082     mutable bool3 IamMaximalFlag;     // (because maximality implies primality)
00083 
00084   protected:
00085     IdealBase(): myRefCount(0), IamPrimeFlag(), IamMaximalFlag() {};
00086     virtual ~IdealBase();
00087 
00088   public:
00089     virtual IdealBase* clone() const = 0;
00090 //???    virtual void swap(ideal& other) = 0;
00091 
00092     virtual const ring& myAmbientRing() const = 0;
00093     virtual bool IamZero() const = 0;
00094     virtual bool IamOne() const = 0;
00095 
00096     bool IamMaximal() const;
00097     virtual void mySetMaximalFlag(bool b) const;    // virtual + default impl
00098     bool IamPrime() const;
00099     virtual void mySetPrimeFlag(bool b) const;      // virtual + default impl
00100 
00101     virtual void myReduceMod(RingElemRawPtr rawx) const = 0; // r elem of R, where I is ideal in R
00102     virtual bool contains(RingElemConstRawPtr rawx) const = 0;
00103     virtual void add(const ideal&) = 0;
00104     virtual void intersect(const ideal&) = 0;
00105     virtual void colon(const ideal&) = 0;
00106     virtual void myDivMod(RingElemRawPtr rawlhs, RingElemConstRawPtr rawnum, RingElemConstRawPtr rawden) const = 0; // lhs = num/den modulo the ideal  (lhs = 0 if quotient does not exist)
00107 
00108     virtual const std::vector<RingElem>& myGens() const = 0; // gens as specified by user
00109     virtual const std::vector<RingElem>& myTidyGens() const = 0; // tidier set of gens
00110 
00111     virtual void myOutputSelf(std::ostream& out) const;
00112     virtual void myOutputSelf(OpenMathOutput& OMOut) const;
00113   protected:
00114     virtual void myMaximalTest() const = 0; // sets IamMaximalFlag accordingly, may also set IamPrimeFlag to true
00115     virtual void myPrimeTest() const = 0;   // sets IamPrimeFlag accordingly, may also set IamMaximalFlag to false
00116   };
00117 
00118 
00119   RingElem operator%(long n, const ideal& I);             ///< reduce n modulo I
00120   RingElem operator%(const ZZ& N, const ideal& I);        ///< reduce N modulo I
00121   RingElem operator%(ConstRefRingElem r, const ideal& I); ///< reduce r modulo I
00122   RingElem NF(ConstRefRingElem r, const ideal& I); ///< reduce r modulo I, same as %
00123   const ring& AmbientRing(const ideal& I);
00124   const ideal operator+(const ideal& I, const ideal& J);
00125   ideal& operator+=(ideal& I, const ideal& J);
00126   const ideal intersect(const ideal& I, const ideal& J);
00127   const ideal colon(const ideal& I, const ideal& J);
00128   bool IsContained(const ideal& I, const ideal& J);  // Is ideal I contained in ideal J?
00129   bool operator==(const ideal& I, const ideal& J);
00130   bool IsElem(ConstRefRingElem r, const ideal& I);
00131   std::ostream& operator<<(std::ostream& out, const ideal& I);
00132   OpenMathOutput& operator<<(OpenMathOutput& OMOut, const ideal& I);
00133 
00134   //---------------------------------------------------------------------------
00135   // Inline functions
00136 
00137   inline void IdealBase::myRefCountInc() const { ++myRefCount; }
00138   inline void IdealBase::myRefCountDec() const { if (--myRefCount == 0) delete this; }
00139   inline bool IdealBase::myRefCountIsOne() const { return myRefCount == 1; }
00140 
00141 
00142   inline const IdealBase* ideal::myIdealPtr() const
00143   { return myPtr; }
00144 
00145 
00146 //   inline IdealBase* ideal::operator->()              // allow non-const member fns to be called
00147 //   {
00148 //     CoCoA_ASSERT(myPtr->RefCountIsOne());
00149 //     return myPtr;
00150 //   }
00151 
00152 
00153   inline const IdealBase* ideal::operator->() const  // allow const member fns to be called
00154   { return myPtr; }
00155 
00156 
00157   inline bool IsZero(const ideal& I)
00158   {
00159     return I->IamZero();
00160   }
00161 
00162 
00163   inline bool IsOne(const ideal& I)
00164   {
00165     return I->IamOne();
00166   }
00167 
00168 
00169   inline bool IsMaximal(const ideal& I)
00170   {
00171     return I->IamMaximal();
00172   }
00173 
00174 
00175   inline bool IsPrime(const ideal& I)
00176   {
00177     return I->IamPrime();
00178   }
00179 
00180 
00181   inline const std::vector<RingElem>& gens(const ideal& I)
00182   {
00183     return I->myGens();
00184   }
00185 
00186 
00187   inline const std::vector<RingElem>& TidyGens(const ideal& I)
00188   {
00189     return I->myTidyGens();
00190   }
00191 
00192 
00193   inline const ring& AmbientRing(const ideal& I)
00194   {
00195     return I->myAmbientRing();
00196   }
00197 
00198 
00199   inline bool IsElem(ConstRefRingElem r, const ideal& I)
00200   {
00201     if (owner(r) != AmbientRing(I)) CoCoA_ERROR(ERR::MixedRings, "IsElem(r, I)");
00202     return I->contains(raw(r));
00203   }
00204 
00205   inline RingElem NF(ConstRefRingElem r, const ideal& I)
00206   {
00207     return r%I;
00208   }
00209 
00210 } // end of namespace CoCoA
00211 
00212 
00213 
00214 
00215 // RCS header/log in the next few lines
00216 // $Header: /Volumes/Home/cocoa/cvs-repository/CoCoALib-0.99/include/CoCoA/ideal.H,v 1.1.1.1 2007/03/09 15:16:11 abbott Exp $
00217 // $Log: ideal.H,v $
00218 // Revision 1.1.1.1  2007/03/09 15:16:11  abbott
00219 // Imported files
00220 //
00221 // Revision 1.6  2007/01/15 13:33:34  cocoa
00222 // -- added prefix "raw" to RawPtr arguments names
00223 //
00224 // Revision 1.5  2006/12/06 17:17:44  cocoa
00225 // -- removed #include "config.H"
00226 //
00227 // Revision 1.4  2006/11/24 17:40:58  cocoa
00228 // -- removed OpenMathFwd.H
00229 //
00230 // Revision 1.3  2006/11/02 13:25:44  cocoa
00231 // Simplification of header files: the OpenMath classes have been renamed.
00232 // Many minor consequential changes.
00233 //
00234 // Revision 1.2  2006/10/06 14:04:15  cocoa
00235 // Corrected position of #ifndef in header files.
00236 // Separated CoCoA_ASSERT into assert.H from config.H;
00237 // many minor consequential changes (have to #include assert.H).
00238 // A little tidying of #include directives (esp. in Max's code).
00239 //
00240 // Revision 1.1.1.1  2006/05/30 11:39:36  cocoa
00241 // Imported files
00242 //
00243 // Revision 1.5  2006/05/12 16:10:58  cocoa
00244 // Added OpenMathFwd.H, and tidied OpenMath.H.
00245 // Many consequential but trivial changes.
00246 //
00247 // Revision 1.4  2006/03/21 09:43:14  cocoa
00248 // Changed names of some member fns of ideals (dealing with setting and testing
00249 // the flags for primeness and maximality).  Hope icc will complain less now.
00250 //
00251 // Revision 1.3  2006/03/15 18:09:31  cocoa
00252 // Changed names of member functions which print out their object
00253 // into myOutputSelf -- hope this will appease the Intel C++ compiler.
00254 //
00255 // Revision 1.2  2006/01/19 16:34:42  cocoa
00256 // -- added NF, myReduceMod functions (not yet tested)
00257 //
00258 // Revision 1.1.1.1  2005/10/17 10:46:54  cocoa
00259 // Imported files
00260 //
00261 // Revision 1.1.1.1  2005/05/03 15:47:30  cocoa
00262 // Imported files
00263 //
00264 // Revision 1.5  2005/04/29 15:42:02  cocoa
00265 // Improved documentation for GMPAllocator.
00266 // Added example program for GMPAllocator.
00267 // Added example program for simple ops on polynomials.
00268 // Added two new ctors for (principal) ideals (from long, and from ZZ).
00269 // Added (crude) printing for PPMonoids.
00270 // Updated library.H (#included GMPAllocator.H).
00271 //
00272 // Revision 1.4  2005/04/20 15:40:48  cocoa
00273 // Major change: modified the standard way errors are to be signalled
00274 // (now via a macro which records filename and line number).  Updated
00275 // documentation in error.txt accordingly.
00276 //
00277 // Improved the documentation in matrix.txt (still more work to be done).
00278 //
00279 // Revision 1.3  2005/04/19 14:06:04  cocoa
00280 // Added GPL and GFDL licence stuff.
00281 //
00282 // Revision 1.2  2005/02/11 14:15:20  cocoa
00283 // New style ring elements and references to ring elements;
00284 // I hope I have finally got it right!
00285 //
00286 // Revision 1.1.1.1  2005/01/27 15:12:13  cocoa
00287 // Imported files
00288 //
00289 // Revision 1.11  2004/11/12 15:49:29  cocoa
00290 // Tidying prior to 0.90 release.
00291 // (a) documentation improved (or marked as poor)
00292 // (b) sundry minor improvements to the code
00293 //
00294 // Revision 1.10  2004/11/11 13:02:16  cocoa
00295 // -- added \include *.txt for doxygen
00296 //
00297 // Revision 1.9  2004/11/05 15:30:57  cocoa
00298 // Separated FieldIdealImpl from the "abstract" classes ideal and
00299 // IdealBase.
00300 //
00301 // Revision 1.8  2004/07/20 15:04:06  cocoa
00302 // The next step in the new "ring element" conversion process:
00303 // handling the case of creating a "const RefRingElem" object
00304 // (since C++ refuses to do this properly itself).
00305 //
00306 // Revision 1.7  2004/06/29 17:10:22  cocoa
00307 // Partially tidied use of "protected" and "private" in various
00308 // base classes.  Checking in at the end of the day -- it works,
00309 // and I wouldn't want it to be lost next time point's disk
00310 // misbehaves.
00311 //
00312 // Revision 1.6  2004/06/25 16:04:37  cocoa
00313 // -- removed 1 comma for new compiler on vector
00314 //
00315 // Revision 1.5  2004/05/27 16:14:02  cocoa
00316 // Minor revision for new coding conventions.
00317 //
00318 // Revision 1.4  2004/03/20 17:46:10  cocoa
00319 // Check in prior to departure to RWCA
00320 //
00321 // Revision 1.3  2003/10/17 10:51:06  cocoa
00322 // Major cleaning, and new naming convention.
00323 //
00324 // Revision 1.2  2003/10/09 12:16:38  cocoa
00325 // New coding convention for rings.
00326 //
00327 // Revision 1.3  2003/06/23 17:00:21  abbott
00328 // Minor cleaning prior to public release.
00329 //
00330 // Revision 1.2  2003/05/30 11:59:35  abbott
00331 // Corrected ctor for a principal ideal (was missing const).
00332 //
00333 // Revision 1.1  2003/04/24 14:43:23  abbott
00334 // Initial revision
00335 //
00336 //
00337 
00338 #endif

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