Changeset a388ae in git
- Timestamp:
- Oct 21, 2009, 5:36:00 PM (14 years ago)
- Branches:
- (u'spielwiese', '0d6b7fcd9813a1ca1ed4220cfa2b104b97a0a003')
- Children:
- 9b4a332909ecddda93d19e235977388831620db1
- Parents:
- bb503c7363e3c90a3b0c5ae93374d5b7b20cc34a
- Location:
- Singular
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/CanonicalPoly.cc
rbb503c7 ra388ae 3 3 #ifdef HAVE_WRAPPERS 4 4 5 #include <iostream> 5 6 #include "structs.h" 6 7 #include "polys.h" 8 #include "Wrappers.h" 7 9 #include "CanonicalPoly.h" 8 #include "Wrappers.h"9 #include <iostream>10 10 11 11 CanonicalPoly::CanonicalPoly (const SingularPoly& sp, const RingWrapper& r):InternPoly(r) … … 17 17 18 18 CanonicalPoly::CanonicalPoly (const int i, const RingWrapper& r):InternPoly(r) 19 { // this method seems to work in char 0 only; is this due to a malfunction of p_ISet?19 { 20 20 +prpr > "CanonicalPoly constructor with int argument = " < i; 21 21 m_poly = p_ISet(i, r.getSingularRing()); … … 25 25 { 26 26 +prpr > "CanonicalPoly destructor, object = " < this->toString(); 27 //p_Delete(&m_poly, m_ring.getSingularRing());28 27 } 29 28 … … 36 35 void CanonicalPoly::addCompatible (const InternPoly* ip) 37 36 { 38 if (ip->getPolyType() == 1)37 if (ip->getPolyType() == CANONICAL_POLY_TYPE) 39 38 { 40 39 const CanonicalPoly* pcp = static_cast<const CanonicalPoly*>(ip); … … 49 48 } 50 49 else 51 {52 50 assume(false); 53 }54 51 } 55 52 … … 67 64 { 68 65 +prpr > "creating a deep copy of CanonicalPoly, argument = " < this->toString(); 69 SingularPoly sp = p_Copy(this->getSingularPoly(), this->getRing().getSingularRing()); // SINGULAR poly is deeply copied.70 CanonicalPoly* pcp = new CanonicalPoly(sp, this->getRing()); // ring is not deeply copied!66 SingularPoly sp = p_Copy(this->getSingularPoly(), this->getRing().getSingularRing()); /* SINGULAR poly is deeply copied. */ 67 CanonicalPoly* pcp = new CanonicalPoly(sp, this->getRing()); /* ring is not deeply copied! */ 71 68 return pcp; 72 69 } 73 70 74 #endif // HAVE_WRAPPERS 71 #endif 72 /* HAVE_WRAPPERS */ -
Singular/CanonicalPoly.h
rbb503c7 ra388ae 5 5 6 6 #include "ring.h" 7 #include "InternPoly.h"8 7 #include <string> 9 8 #include "Wrappers.h" 9 #include "InternPoly.h" 10 10 11 class CanonicalPoly : public InternPoly // class for wrapping canonical SINGULAR polynomials 11 /*! \class CanonicalPoly 12 * \brief Class CanonicalPoly is the class for representing SINGULAR-internal, 13 * so-called canonical polynomials. 14 * 15 * CanonicalPoly is derived from InternPoly which is derived from ReferenceCounter, 16 * thus any instance of CanonicalPoly deploys reference counting and 17 * facilities for fast shallow copying.<br> 18 * Any instance of CanonicalPoly wraps an actual SINGULAR polynomial. 19 * \author Frank Seelisch, http://www.mathematik.uni-kl.de/~seelisch 20 */ 21 class CanonicalPoly : public InternPoly 12 22 { 13 23 private: 24 /*! placeholder for a SINGULAR-internal polynomial */ 14 25 SingularPoly m_poly; 26 27 /*! 28 * A method for retrieving the stored SINGULAR-internal polynomial. 29 * @return the stored SINGULAR-internal polynomial 30 */ 15 31 const SingularPoly& getSingularPoly () const; 32 protected: 33 /*! 34 * A method for deeply copying the given instance of CanonicalPoly.<br> 35 * @return a pointer to the deep copy of <c>this</c> CanonicalPoly 36 */ 37 CanonicalPoly* deepCopy () const; 38 39 /*! 40 * A method for adding an instance of CanonicalPoly and an instance of 41 * InternPoly.<br> 42 * Both polynomials are known to live in compatible rings. For the time being, 43 * the implementation of this method will only succeed when the argument InternPoly 44 * can also be casted to CanonicalPoly. This cast will be performed static in case 45 * that <c>ip.getPolyType()</c> yields the enum CANONICAL_POLY_TYPE. Otherwise the 46 * program will halt.<br> 47 * In case of success, the result of the addition will be stored in the 48 * CanonicalPoly given by <c>*this</c>, hence the given object will then be modified 49 * by the operation.<br> 50 * @param ip another InternPoly to be added to <c>this</c> CanonicalPoly 51 * @see InternPoly::addCompatible (const InternPoly* ip) 52 * @see InternPoly::add (const InternPoly* ip) 53 * @see RingWrapper::isCompatible (const RingWrapper& r) const 54 */ 55 void addCompatible (const InternPoly* ip); 56 57 /*! 58 * A method for retrieving the type of the represented poly. 59 * For any class C derived from InternPoly, the call <c>C::getPolyType ()</c> 60 * is to return one of the defined enums so that, based on the return value, the 61 * programmer may perform a <em>static</em> cast to cast any given instance 62 * of InternPoly to the correct derived class.<br> 63 * This method needs to be reimplemented in each class derived from InternPoly. 64 * @return the enum CANONICAL_POLY_TYPE 65 */ 66 int getPolyType () const; 67 68 /*! 69 * A method for obtaining a string representation of the given instance. 70 */ 71 char* toString () const; 16 72 public: 17 73 ~CanonicalPoly (); 74 75 /*! 76 * A constructor for CanonicalPoly.<br> 77 * This constructor will create a representation of the given integer 78 * as a wrapped SINGULAR-internal polynomial. 79 * @param r a RingWrapper wrapping the ring in which the polynomial lives 80 * @see CanonicalPoly::CanonicalPoly (const SingularPoly&, const RingWrapper& r) 81 */ 18 82 CanonicalPoly (const int i, const RingWrapper& r); 83 84 /*! 85 * A constructor for CanonicalPoly.<br> 86 * This constructor will wrap the given SINGULAR-internal polynomial. 87 * @param r a RingWrapper wrapping the ring in which the polynomial lives 88 * @see CanonicalPoly::CanonicalPoly (const int i, const RingWrapper& r) 89 */ 19 90 CanonicalPoly (const SingularPoly&, const RingWrapper& r); 20 void addCompatible (const InternPoly* ip); // changes m_poly, i.e. given object 21 CanonicalPoly* deepCopy () const; 22 int getPolyType () const; 23 char* toString () const; 91 92 /*! We enable PolyWrapper to "see" all methods of CanonicalPoly. */ 93 friend class PolyWrapper; 24 94 }; 25 95 26 #endif // HAVE_WRAPPERS 96 #endif 97 /* HAVE_WRAPPERS */ 27 98 28 99 #endif -
Singular/InternPoly.cc
rbb503c7 ra388ae 3 3 #ifdef HAVE_WRAPPERS 4 4 5 #include <iostream> 6 #include "Wrappers.h" 5 7 #include "InternPoly.h" 6 #include "Wrappers.h"7 #include <iostream>8 8 9 9 InternPoly::InternPoly (const RingWrapper& r):m_ring(r) … … 15 15 InternPoly::InternPoly (const InternPoly& ip):m_ring(ip.getRing()) 16 16 { 17 assume(false); / / shallow copy constructor should never be called17 assume(false); /* shallow copy constructor should never be called */ 18 18 } 19 19 20 20 InternPoly* InternPoly::deepCopy () const 21 21 { 22 assume(false); / / deep copy constructor should never be called22 assume(false); /* deep copy constructor should never be called */ 23 23 } 24 24 25 InternPoly::~InternPoly ()25 InternPoly::~InternPoly () 26 26 { 27 27 +prpr > "InternPoly destructor"; … … 30 30 char* InternPoly::toString () const 31 31 { 32 assume(false); / / should be overridden by each derived class32 assume(false); /* should be overridden by each derived class */ 33 33 } 34 34 … … 40 40 void InternPoly::add (const InternPoly* ip) { 41 41 if (this->getRing().isCompatible(ip->getRing())) 42 {43 42 this->addCompatible(ip); 44 }45 43 else 46 44 { 45 +prpr > "addition of objects in incompatible rings encountered"; 47 46 assume(false); 48 47 } … … 56 55 void InternPoly::addCompatible (const InternPoly* ip) 57 56 { 58 assume(false); / / should be overridden by each derived class57 assume(false); /* should be overridden by each derived class */ 59 58 } 60 59 61 #endif // HAVE_WRAPPERS 60 #endif 61 /* HAVE_WRAPPERS */ -
Singular/InternPoly.h
rbb503c7 ra388ae 4 4 #ifdef HAVE_WRAPPERS 5 5 6 #include "Wrappers.h" 6 7 #include "ReferenceCounter.h" 7 8 #include "RingWrapper.h" 8 9 10 /*! \class InternPoly 11 * \brief Class InternPoly is the superclass of all classes which 12 * wrap specific polynomial representations. 13 * 14 * InternPoly is derived from ReferenceCounter, thus any instance of 15 * InternPoly and of its derived classes deploys reference counting and 16 * facilities for fast shallow copying.<br> 17 * Classes derived from InternPoly are intended to wrap specific polynomial 18 * representations such as SINGULAR-internal polynomials, as done by 19 * CanonicalPoly. Each such instance needs to <em>know</em> in which ring it 20 * lives. Therefore, InterPoly has a private member for storing a reference 21 * to some instance of RingWrapper.<br> 22 * Any instance of PolyWrapper holds a pointer to an instance of InternPoly 23 * wherein the polynomial is actually wrapped. This way, technicalities 24 * can be implemented inside InternPoly (and in the classes derived from it) 25 * and only the user interface for polynomail actions can by made available 26 * through PolyWrapper.<br> 27 * \author Frank Seelisch, http://www.mathematik.uni-kl.de/~seelisch 28 */ 9 29 class InternPoly : public ReferenceCounter 10 30 { 11 31 protected: 32 /*! private member for storing a reference to a RingWrapper 33 which wraps the ring in which the polynomial lives */ 12 34 const RingWrapper& m_ring; 35 36 /*! an enumeration variable for making the code more readable; 37 for any class C derived from InternPoly, the call <c>C::getPolyType ()</c> 38 is to return one of these enums so that, based on the return value, the 39 programmer may perform a <em>static</em> cast to cast a given instance 40 of InternPoly to the correct derived class */ 41 static const int UNSPECIFIED_POLY_TYPE = 0; 42 43 /*! an enumeration variable for making the code more readable; 44 for any class C derived from InternPoly, the call <c>C::getPolyType ()</c> 45 is to return one of these enums so that, based on the return value, the 46 programmer may perform a <em>static</em> cast to cast a given instance 47 of InternPoly to the correct derived class */ 48 static const int CANONICAL_POLY_TYPE = 1; 49 50 /*! 51 * A method for retrieving the type of the represented poly. 52 * For any class C derived from InternPoly, the call <c>C::getPolyType ()</c> 53 * is to return one of the defined enums so that, based on the return value, the 54 * programmer may perform a <em>static</em> cast to cast any given instance 55 * of InternPoly to the correct derived class.<br> 56 * This method needs to be reimplemented in each class derived from InternPoly. 57 * @return the polynomial type, one of the defined enums 58 */ 59 virtual int getPolyType () const; 60 61 /*! 62 * A method for adding two instances of InterPoly which are known to 63 * live in the same, or at least in compatible rings.<br> 64 * The result of the addition will be stored in the InternPoly given by <c>*this</c>; 65 * hence the given object will be modified by the operation.<br> 66 * This method needs to be reimplemented in each class derived from InternPoly. 67 * @param ip another InternPoly to be added to <c>this</c> InternPoly 68 * @see InternPoly::add (const InternPoly* ip) 69 * @see RingWrapper::isCompatible (const RingWrapper& r) const 70 */ 71 virtual void addCompatible (const InternPoly* ip); 72 73 /*! 74 * A method for deeply copying the given instance of InternPoly.<br> 75 * This method needs to be reimplemented in each class derived from InternPoly. 76 * @return a pointer to the deep copy of <c>this</c> InternPoly 77 */ 78 virtual InternPoly* deepCopy () const; 79 80 /*! 81 * A method for retrieving the RingWrapper which wraps the ring in 82 * which the represented polynomial lives.<br> 83 * This method needs to be reimplemented in each class derived from InternPoly. 84 * @return a RingWrapper wrapping the ring in which the polynomial lives 85 */ 86 const RingWrapper& getRing () const; 87 88 /*! 89 * A method for adding two instances of InterPoly which are not known to 90 * live in compatible rings.<br> 91 * In case of compatibility, the result of the addition will be stored 92 * in the InternPoly given by <c>*this</c>, hence the given object will be 93 * modified by the operation.<br> 94 * @param ip another InternPoly to be added to <c>this</c> InternPoly 95 * @see InternPoly::addCompatible (const InternPoly* ip) 96 * @see RingWrapper::isCompatible (const RingWrapper& r) const 97 */ 98 void add (const InternPoly* ip); 99 100 /*! 101 * A method for obtaining a string representation of the given instance.<br> 102 * This method needs to be reimplemented in each class derived from InternPoly. 103 */ 104 virtual char* toString () const; 13 105 public: 106 /*! 107 * A constructor for InternPoly which just sets the RingWrapper.<br> 108 * This constructor is assumed to be called implicitely when a constructor 109 * of one of the classes derived from InternPoly will be called. 110 * @param r a RingWrapper wrapping the ring in which the polynomial lives 111 */ 14 112 InternPoly (const RingWrapper& r); 113 114 /*! 115 * A copy constructor for InternPoly.<br> 116 * As this constructor should neither be called by the user nor 117 * implicitely by some method, it will halt the program. 118 * @param p a reference to another InternPoly 119 */ 15 120 InternPoly (const InternPoly& p); 121 122 /*! 123 * A destructor for InternPoly. 124 */ 16 125 virtual ~InternPoly (); 17 const RingWrapper& getRing () const; 18 void add (const InternPoly* ip); // changes given object 19 virtual void addCompatible (const InternPoly* ip); // changes given object 20 virtual InternPoly* deepCopy () const; 21 virtual int getPolyType () const; 22 virtual char* toString () const;126 127 /*! We enable PolyWrapper to "see" all methods of InternPoly. */ 128 friend class PolyWrapper; 129 130 /*! We enable CanonicalPoly to "see" all methods of InternPoly. */ 131 friend class CanonicalPoly; 23 132 }; 24 133 25 #endif // HAVE_WRAPPERS 134 #endif 135 /* HAVE_WRAPPERS */ 26 136 27 137 #endif -
Singular/PolyWrapper.cc
rbb503c7 ra388ae 3 3 #ifdef HAVE_WRAPPERS 4 4 5 #include "PolyWrapper.h"6 #include "CanonicalPoly.h"7 #include "Wrappers.h"8 5 #include <iostream> 9 6 #include "febase.h" 7 #include "Wrappers.h" 8 #include "PolyWrapper.h" 9 #include "RingWrapper.h" 10 #include "CanonicalPoly.h" 10 11 11 12 PolyWrapper PolyWrapper::operator+ (const PolyWrapper& p) const … … 16 17 +prpr > "second argument = " < p.toString(); 17 18 prpr-1; 18 PolyWrapper q(this->getInternPoly()->deepCopy()); // deep copy of given PolyWrapper19 PolyWrapper q(this->getInternPoly()->deepCopy()); /* deep copy of given PolyWrapper */ 19 20 q.getInternPoly()->add(p.getInternPoly()); 20 21 return q; … … 44 45 PolyWrapper::PolyWrapper (): m_pInternPoly(0) 45 46 { 46 assume(false); / /the default constructor, i.e. the one47 // without arguments should never be called47 assume(false); /* the default constructor, i.e. the one 48 without arguments should never be called */ 48 49 } 49 50 … … 113 114 } 114 115 115 #endif // HAVE_WRAPPERS 116 PolyWrapper::PolyWrapper (const SingularPoly& sp, const RingWrapper& r) { 117 +prpr > "creating a new PolyWrapper (internal type: CanonicalPoly)"; 118 m_pInternPoly = new CanonicalPoly(sp, r); 119 } 120 121 #endif 122 /* HAVE_WRAPPERS */ -
Singular/PolyWrapper.h
rbb503c7 ra388ae 4 4 #ifdef HAVE_WRAPPERS 5 5 6 #include "Wrappers.h" 6 7 #include "InternPoly.h" 7 8 #include "RingWrapper.h" 8 #include "Wrappers.h"9 9 10 /*! \class PolyWrapper 11 * \brief Class PolyWrapper provides a uniform interface to different 12 * representations of polynomials. 13 * 14 * Instances of PolyWrapper uniformly represent different kinds of 15 * polynomials that play a role in the computer algebra system SINGULAR 16 * and related suites such as PolyBoRi. Especially SINGULAR-internal 17 * polynomials can be wrapped by instances of PolyWrapper.<br> 18 * This implementation comes with an automatic reference counting so that copying 19 * PolyWrappers is cheap as it will simply be done by incrementing the 20 * respective reference counter. Constructors and destructors automatically 21 * manage the reference counting. Methods that create new instances of 22 * PolyWrapper, e.g. PolyWrapper::operator+ (const PolyWrapper& p) const, 23 * will internally enforce the instantiation of a new ReferenceCounter.<br> 24 * Summarizing this means that all methods of PolyWrapper <em>know</em> when 25 * to make a shallow copy (by incrementing the ReferenceCounter) and when to 26 * make a deep copy.<br> 27 * Polynomials wrapped by PolyWrapper <em>know</em> in which ring they live. 28 * A wrapper object of that ring can be obtained by calling 29 * PolyWrapper::getRing () const. 30 * \author Frank Seelisch, http://www.mathematik.uni-kl.de/~seelisch 31 */ 10 32 class PolyWrapper 11 33 { 12 34 private: 35 /*! a pointer to an internal polynomial representation, 36 e.g. to a SINGULAR-internal polynomial */ 13 37 InternPoly* m_pInternPoly; 38 39 /*! 40 * A constructor for PolyWrapper.<br> 41 * This constructor just wraps the provided instance of InternPoly, 42 * which may e.g. be a SINGULAR-internal polynomial. 43 * @param ip the internal polynomial to be wrapped 44 * @see PolyWrapper::PolyWrapper () 45 * @see PolyWrapper::PolyWrapper (const PolyWrapper& p) 46 * @see PolyWrapper::PolyWrapper (const int i, const RingWrapper& r) 47 * @see PolyWrapper::PolyWrapper (const SingularPoly& sp, const RingWrapper& r) 48 */ 14 49 PolyWrapper (InternPoly* ip); 50 51 /*! 52 * A method for retrieving the wrapped InternPoly. 53 * @return the wrapped InternPoly 54 * @see PolyWrapper::PolyWrapper (InternPoly* ip) 55 */ 15 56 InternPoly* getInternPoly () const; 16 57 public: 58 /*! 59 * A default constructor for PolyWrapper.<br> 60 * This constructor will make the program stop as it should 61 * never be called by the user or as a side-effect of any action. 62 * @see PolyWrapper::PolyWrapper (InternPoly* ip) 63 * @see PolyWrapper::PolyWrapper (const PolyWrapper& p) 64 * @see PolyWrapper::PolyWrapper (const int i, const RingWrapper& r) 65 * @see PolyWrapper::PolyWrapper (const SingularPoly& sp, const RingWrapper& r) 66 */ 17 67 PolyWrapper (); 18 PolyWrapper (const PolyWrapper& p); // shallow copy 19 PolyWrapper (const int i, const RingWrapper& r); // integer i as a poly 68 69 /*! 70 * A copy constructor for PolyWrapper.<br> 71 * This constructor creates a shallow copy of the argument. This is 72 * simply done by incrementing the ReferenceCounter. 73 * @param p the PolyWrapper to be shallow-copied 74 * @see PolyWrapper::PolyWrapper () 75 * @see PolyWrapper::PolyWrapper (InternPoly* ip) 76 * @see PolyWrapper::PolyWrapper (const int i, const RingWrapper& r) 77 * @see PolyWrapper::PolyWrapper (const SingularPoly& sp, const RingWrapper& r) 78 */ 79 PolyWrapper (const PolyWrapper& p); 80 81 /*! 82 * A constructor for PolyWrapper.<br> 83 * This constructor creates a SINGULAR-internal polynomial representing 84 * the given argument integer, and then a wrapped version of it.<br> 85 * The user may use RingWrapper::RingWrapper () to create a RingWrapper wrapping 86 * the current SINGULAR-internal ring (<c>currRing</c>). 87 * @param i the integer to be represented as a polynomial 88 * @param r a RingWrapper wrapping the internal ring in which the polynomial lives 89 * @see PolyWrapper::PolyWrapper () 90 * @see PolyWrapper::PolyWrapper (InternPoly* ip) 91 * @see PolyWrapper::PolyWrapper (const PolyWrapper& p) 92 * @see PolyWrapper::PolyWrapper (const SingularPoly& sp, const RingWrapper& r) 93 */ 94 PolyWrapper (const int i, const RingWrapper& r); 95 96 /*! 97 * A constructor for PolyWrapper.<br> 98 * This constructor creates a wrapped version of the given SINGULAR-internal 99 * polynomial.<br> 100 * The user may use RingWrapper::RingWrapper () to create a RingWrapper wrapping 101 * the current SINGULAR-internal ring (<c>currRing</c>). 102 * @param sp a SINGULAR-internal polynomial 103 * @param r a RingWrapper wrapping the internal ring in which the polynomial lives 104 * @see PolyWrapper::PolyWrapper () 105 * @see PolyWrapper::PolyWrapper (InternPoly* ip) 106 * @see PolyWrapper::PolyWrapper (const PolyWrapper& p) 107 * @see PolyWrapper::PolyWrapper (const int i, const RingWrapper& r) 108 */ 109 PolyWrapper (const SingularPoly& sp, const RingWrapper& r); 110 111 /*! 112 * A destructor for PolyWrapper.<br> 113 * This constructor creates a wrapped version of the given SINGULAR-internal 114 * polynomial.<br> 115 * This routine will automatically decrement the ReferenceCounter and, in case 116 * the counter reaches zero, enforce the destruction of related objects. 117 * @see PolyWrapper::PolyWrapper () 118 * @see PolyWrapper::PolyWrapper (InternPoly* ip) 119 * @see PolyWrapper::PolyWrapper (const PolyWrapper& p) 120 * @see PolyWrapper::PolyWrapper (const int i, const RingWrapper& r) 121 * @see PolyWrapper::PolyWrapper (const SingularPoly& sp, const RingWrapper& r) 122 */ 20 123 ~PolyWrapper (); 124 125 /*! 126 * A method for printing a string representation of the given instance.<br> 127 * This method does not use std::cout but only SINGULAR-internal print routines. 128 * @see PolyWrapper::printLn () const 129 * @see PolyWrapper::toString () const 130 */ 21 131 void print () const; 132 133 /*! 134 * A method for printing a string representation of the given instance 135 * followed by a linefeed.<br> 136 * This method does not use std::cout but only SINGULAR-internal print routines. 137 * @see PolyWrapper::print () const 138 * @see PolyWrapper::toString () const 139 */ 22 140 void printLn () const; 141 142 /*! 143 * A method for obtaining a string representation of the given instance. 144 * @see PolyWrapper::print () const 145 * @see PolyWrapper::printLn () const 146 */ 23 147 char* toString () const; 148 149 /*! 150 * Assignment operator for PolyWrapper.<br> 151 * This method will just exchange the wrapped instance of InternPoly. 152 * Consequently, the ReferenceCounter of the InternPoly wrapped by the 153 * given argument will be decremented (and in case of reaching zero, 154 * the destruction of related objects will be enforced). 155 * @param p an instance of PolyWrapper 156 * @return a reference to the new PolyWrapper 157 */ 24 158 PolyWrapper& operator= (const PolyWrapper& p); 159 160 /*! 161 * Addition operator for PolyWrapper.<br> 162 * This method will compute a PolyWrapper which wraps the result of 163 * adding the polynomials wrapped by <c>this</c> PolyWrapper and by 164 * the argument PolyWrapper. 165 * @param p an instance of PolyWrapper 166 * @return a PolyWrapper representing the sum 167 */ 25 168 PolyWrapper operator+ (const PolyWrapper& p) const; 169 170 /*! 171 * Modifying addition operator for PolyWrapper.<br> 172 * This method will compute (in the PolyWrapper given by <c>this</c>), 173 * the result of adding the polynomials wrapped by <c>this</c> PolyWrapper and by 174 * the argument PolyWrapper. Note that this method will in general change the 175 * given object. 176 * @param p an instance of PolyWrapper 177 * @return a reference to <c>this</c> PolyWrapper now representing the sum 178 */ 26 179 PolyWrapper& operator+= (const PolyWrapper& p); 180 181 /*! 182 * A method for retrieving a RingWrapper wrapping the internal ring in which 183 * the given polynomial lives. 184 * @return a reference to a RingWrapper 185 */ 27 186 const RingWrapper& getRing () const; 28 187 }; 29 188 30 #endif // HAVE_WRAPPERS 189 #endif 190 /* HAVE_WRAPPERS */ 31 191 32 192 #endif -
Singular/PrettyPrinter.cc
rbb503c7 ra388ae 8 8 #include "PrettyPrinter.h" 9 9 10 PrettyPrinter::PrettyPrinter (const char* fileName1, const char* fileName2, // choose filename "" for no output file10 PrettyPrinter::PrettyPrinter (const char* fileName1, const char* fileName2, 11 11 const bool append1, const bool append2, 12 12 const int console, const char* baseIndent) … … 48 48 { 49 49 if (strcmp(m_fileName1, "") != 0) 50 { 51 m_file1 << s; 52 } 50 m_file1 << s; 53 51 if (m_console == 0 || m_console == 1) 54 { 55 PrintS(s); 56 } 52 PrintS(s); 57 53 return *this; 58 54 } … … 61 57 { 62 58 if (strcmp(m_fileName1, "") != 0) 63 { 64 m_file1 << s; 65 } 66 if (strcmp(m_fileName2, "") != 0) 67 { 59 m_file1 << s; 60 if (strcmp(m_fileName2, "") != 0) 68 61 m_file2 << s; 69 }70 62 if (m_console == 0 || m_console == 1 || m_console == 2) 71 { 72 PrintS(s); 73 } 63 PrintS(s); 74 64 return *this; 75 65 } … … 180 170 181 171 PrettyPrinter& PrettyPrinter::operator+ () 182 { 183 if (strcmp(m_fileName1, "") != 0) 184 { 172 { 173 if (strcmp(m_fileName1, "") != 0) 185 174 m_file1 << "\n"; 186 }187 175 if (m_console == 0 || m_console == 1) 188 {189 176 PrintLn(); 190 }191 177 return *this; 192 178 } … … 195 181 { 196 182 if (strcmp(m_fileName1, "") != 0) 197 {198 183 m_file1 << "\n"; 199 } 200 if (strcmp(m_fileName2, "") != 0) 201 { 184 if (strcmp(m_fileName2, "") != 0) 202 185 m_file2 << "\n"; 203 }204 186 if (m_console == 0 || m_console == 1 || m_console == 2) 205 {206 187 PrintLn(); 207 }208 188 return *this; 209 189 } … … 286 266 } 287 267 288 #endif // defined(HAVE_MINOR) || defined(HAVE_WRAPPERS) 268 #endif 269 /* defined(HAVE_MINOR) || defined(HAVE_WRAPPERS) */ -
Singular/PrettyPrinter.h
rbb503c7 ra388ae 7 7 #include <string> 8 8 9 /*! \class PrettyPrinter 10 * \brief Class PrettyPrinter is a utility for pretty-printing any kind of 11 * output to one or two files and/or the console. 12 * 13 * The user may use an instance of PrettyPrinter to define two files to 14 * which output can be directed. Then, whenever an item is written to the 15 * PrettyPrinter, the user can decide whether the output goes only to the 16 * first of the files or to both. Thereby, the user may write, e.g., <em>all</em> 17 * output to the first file, and only <em>asorted</em> parts to the second, e.g., 18 * only the most important bits, for instance to generate some kind of overview 19 * of the data that is written to the first file.<br> 20 * Furthermore, the user can decide whether the output will also go to the 21 * console. If so, he/she can decide whether the console will display 22 * all that output which goes to the first file, or only that which goes 23 * to the second one. 24 * Moreover, PrettyPrinter offers functionality to easily include linefeeds 25 * and tabs in the output to give it a better readable format. 26 * \author Frank Seelisch, http://www.mathematik.uni-kl.de/~seelisch 27 */ 9 28 class PrettyPrinter 10 29 { 11 30 private: 31 /*! the number of times, the m_baseIndent is used to make up the current 32 indent string; see e.g. PrettyPrinter::operator> (const char* s); 33 Example: if m_baseIndent is "~~~" and m_indents == 2, then the current 34 indent string is set to "~~~~~~" */ 12 35 int m_indents; 36 37 /*! the base string to define the entire current indent string; 38 see description of m_indents */ 13 39 char* m_baseIndent; 40 41 /*! the container for the entire current indent string; 42 see descriptions of m_indents and m_baseIndent */ 14 43 char* m_indent; 15 char* m_fileName1; // file name for outputs to primary output file 16 char* m_fileName2; // file name for outputs to secondary output file 17 int m_console; // == -1: no output to console 18 // == 0: just output to console, i.e. no file output 19 // == 1: identical outputs to file1 and console; 20 // == 2: identical outputs to file2 and console; 21 // (file1 contains at least as much output as file2) 44 45 /*! file name of primary output file m_file1; 46 m_file1 will always contain at least as much output as m_file2 */ 47 char* m_fileName1; 48 49 /*! file name of secondary output file m_file2; 50 m_file1 will always contain at least as much output as m_file2 */ 51 char* m_fileName2; 52 53 /*! for controlling output to the console;<br> 54 if == -1: no output to the console<br> 55 if == 0: just output to the console, i.e. no file output<br> 56 if == 1: identical outputs to file1 and console<br> 57 if == 2: identical outputs to file2 and console */ 58 int m_console; 59 60 /*! file handle to primary output file */ 22 61 std::ofstream m_file1; 62 63 /*! file handle to secondary output file */ 23 64 std::ofstream m_file2; 24 65 public: 25 PrettyPrinter (const char* fileName1, const char* fileName2, // choose filename "" for no output file 66 /*! 67 * A constructor for PrettyPrinter.<br> 68 * Set filenames equal to "" in order to omit the usage of that file. I.e., 69 * the user should set fileName2 to "" when he/she wants to use only one 70 * output file and set both filenames to "" when he/she does not want any file output.<br> 71 * Set console to -1, if no console output is desired; to 0 if there should be 72 * console output but no file output; to 1 if console output should be identical to 73 * output to primary file; and to 2 if console output should be identical to 74 * output to secondary file.<br> 75 * The baseIndent will be used to build the current indent string which will be included 76 * in the output using e.g. PrettyPrinter::operator> (const char* s). 77 * @param fileName1 a file name for the primary output file 78 * @param fileName2 a file name for the secondary output file 79 * @param append1 if true, m_file1 is being appended, otherwise initially cleared 80 * @param append2 if true, m_file2 is being appended, otherwise initially cleared 81 * @param console control integer for setting up console output 82 * @param baseIndent the base string for the indent string 83 * @see PrettyPrinter::operator+ (const int i) 84 */ 85 PrettyPrinter (const char* fileName1, const char* fileName2, 26 86 const bool append1, const bool append2, 27 87 const int console, const char* baseIndent); 88 89 /*! 90 * A destructor for PrettyPrinter. 91 */ 28 92 ~PrettyPrinter (); 93 94 /*! 95 * A method for including a linefeed in the output to the primary file 96 * (if any) and to the console (if console output has been declared accordingly). 97 * @return a reference to the modified instance of PrettyPrinter 98 * @see PrettyPrinter::operator++ () 99 */ 29 100 PrettyPrinter& operator+ (); 101 102 /*! 103 * A method for including a linefeed in the output to the primary file 104 * (if any), the secondary file (if any), and to the console (if console 105 * output has been declared accordingly). 106 * @return a reference to the modified instance of PrettyPrinter 107 * @see PrettyPrinter::operator+ () 108 */ 30 109 PrettyPrinter& operator++ (); 110 111 /*! 112 * A method for including the current indent string followed by the argument string 113 * in the output to the primary file (if any) and to the console (if console output 114 * has been declared accordingly). 115 * @param s the string to be written to the output devices 116 * @return a reference to the modified instance of PrettyPrinter 117 * @see PrettyPrinter::operator>> (const char* s) 118 */ 31 119 PrettyPrinter& operator> (const char* s); 120 121 /*! 122 * A method for including the current indent string followed by the argument string 123 * in the output to the primary file (if any), to the secondary file (if any), and to 124 * the console (if console output has been declared accordingly). 125 * @param s the string to be written to the output devices 126 * @return a reference to the modified instance of PrettyPrinter 127 * @see PrettyPrinter::operator> (const char* s) 128 */ 32 129 PrettyPrinter& operator>> (const char* s); 130 131 /*! 132 * A method for including the current indent string followed by the argument integer 133 * in the output to the primary file (if any) and to the console (if console output 134 * has been declared accordingly). 135 * @param i the integer to be written to the output devices 136 * @return a reference to the modified instance of PrettyPrinter 137 * @see PrettyPrinter::operator>> (const int i) 138 */ 33 139 PrettyPrinter& operator> (const int i); 140 141 /*! 142 * A method for including the current indent string followed by the argument integer 143 * in the output to the primary file (if any), to the secondary file (if any), and to 144 * the console (if console output has been declared accordingly). 145 * @param i the integer to be written to the output devices 146 * @return a reference to the modified instance of PrettyPrinter 147 * @see PrettyPrinter::operator> (const int i) 148 */ 34 149 PrettyPrinter& operator>> (const int i); 150 151 /*! 152 * A method for including the current indent string followed by the argument long 153 * in the output to the primary file (if any) and to the console (if console output 154 * has been declared accordingly). 155 * @param l the long to be written to the output devices 156 * @return a reference to the modified instance of PrettyPrinter 157 * @see PrettyPrinter::operator>> (const long l) 158 */ 35 159 PrettyPrinter& operator> (const long l); 160 161 /*! 162 * A method for including the current indent string followed by the argument long 163 * in the output to the primary file (if any), to the secondary file (if any), and to 164 * the console (if console output has been declared accordingly). 165 * @param l the long to be written to the output devices 166 * @return a reference to the modified instance of PrettyPrinter 167 * @see PrettyPrinter::operator> (const long l) 168 */ 36 169 PrettyPrinter& operator>> (const long l); 170 171 /*! 172 * A method for including the current indent string followed by the argument unsigned long 173 * in the output to the primary file (if any) and to the console (if console output 174 * has been declared accordingly). 175 * @param ul the unsigned long to be written to the output devices 176 * @return a reference to the modified instance of PrettyPrinter 177 * @see PrettyPrinter::operator>> (const unsigned long ul) 178 */ 37 179 PrettyPrinter& operator> (const unsigned long ul); 180 181 /*! 182 * A method for including the current indent string followed by the argument unsigned long 183 * in the output to the primary file (if any), to the secondary file (if any), and to 184 * the console (if console output has been declared accordingly). 185 * @param ul the unsigned long to be written to the output devices 186 * @return a reference to the modified instance of PrettyPrinter 187 * @see PrettyPrinter::operator> (const unsigned long ul) 188 */ 38 189 PrettyPrinter& operator>> (const unsigned long ul); 190 191 /*! 192 * A method for including the current indent string followed by the argument string 193 * in the output to the primary file (if any) and to the console (if console output 194 * has been declared accordingly). 195 * @return a reference to the modified instance of PrettyPrinter 196 * @see PrettyPrinter::operator>> (const std::string s) 197 */ 39 198 PrettyPrinter& operator> (const std::string s); 199 200 /*! 201 * A method for including the current indent string followed by the argument string 202 * in the output to the primary file (if any), to the secondary file (if any), and to 203 * the console (if console output has been declared accordingly). 204 * @param s the string to be written to the output devices 205 * @return a reference to the modified instance of PrettyPrinter 206 * @see PrettyPrinter::operator> (const std::string s) 207 */ 40 208 PrettyPrinter& operator>> (const std::string s); 209 210 /*! 211 * A method for including the argument string in the output to the primary file 212 * (if any) and to the console (if console output has been declared accordingly). 213 * @param s the string to be written to the output devices 214 * @return a reference to the modified instance of PrettyPrinter 215 * @see PrettyPrinter::operator<< (const char* s) 216 */ 41 217 PrettyPrinter& operator< (const char* s); 218 219 /*! 220 * A method for including the argument string in the output to the primary file 221 * (if any), to the secondary file (if any), and to the console (if console 222 * output has been declared accordingly). 223 * @param s the string to be written to the output devices 224 * @return a reference to the modified instance of PrettyPrinter 225 * @see PrettyPrinter::operator< (const char* s) 226 */ 42 227 PrettyPrinter& operator<< (const char* s); 228 229 /*! 230 * A method for including the argument integer in the output to the primary file 231 * (if any) and to the console (if console output has been declared accordingly). 232 * @param i the integer to be written to the output devices 233 * @return a reference to the modified instance of PrettyPrinter 234 * @see PrettyPrinter::operator<< (const int i) 235 */ 43 236 PrettyPrinter& operator< (const int i); 237 238 /*! 239 * A method for including the argument integer in the output to the primary file 240 * (if any), to the secondary file (if any), and to the console (if console 241 * output has been declared accordingly). 242 * @param i the integer to be written to the output devices 243 * @return a reference to the modified instance of PrettyPrinter 244 * @see PrettyPrinter::operator< (const int i) 245 */ 44 246 PrettyPrinter& operator<< (const int i); 247 248 /*! 249 * A method for including the argument long in the output to the primary file 250 * (if any) and to the console (if console output has been declared accordingly). 251 * @param l the long to be written to the output devices 252 * @return a reference to the modified instance of PrettyPrinter 253 * @see PrettyPrinter::operator<< (const long l) 254 */ 45 255 PrettyPrinter& operator< (const long l); 256 257 /*! 258 * A method for including the argument long in the output to the primary file 259 * (if any), to the secondary file (if any), and to the console (if console 260 * output has been declared accordingly). 261 * @param l the long to be written to the output devices 262 * @return a reference to the modified instance of PrettyPrinter 263 * @see PrettyPrinter::operator< (const long l) 264 */ 46 265 PrettyPrinter& operator<< (const long l); 266 267 /*! 268 * A method for including the argument unsigned long in the output to the primary file 269 * (if any) and to the console (if console output has been declared accordingly). 270 * @param ul the unsigned long to be written to the output devices 271 * @return a reference to the modified instance of PrettyPrinter 272 * @see PrettyPrinter::operator<< (const unsigned long ul) 273 */ 47 274 PrettyPrinter& operator< (const unsigned long ul); 275 276 /*! 277 * A method for including the argument unsigned long in the output to the primary file 278 * (if any), to the secondary file (if any), and to the console (if console 279 * output has been declared accordingly). 280 * @param ul the unsigned long to be written to the output devices 281 * @return a reference to the modified instance of PrettyPrinter 282 * @see PrettyPrinter::operator< (const unsigned long ul) 283 */ 48 284 PrettyPrinter& operator<< (const unsigned long ul); 285 286 /*! 287 * A method for including the argument string in the output to the primary file 288 * (if any) and to the console (if console output has been declared accordingly). 289 * @param s the string to be written to the output devices 290 * @return a reference to the modified instance of PrettyPrinter 291 * @see PrettyPrinter::operator<< (const std::string s) 292 */ 49 293 PrettyPrinter& operator< (const std::string s); 294 295 /*! 296 * A method for including the argument string in the output to the primary file 297 * (if any), to the secondary file (if any), and to the console (if console 298 * output has been declared accordingly). 299 * @param s the string to be written to the output devices 300 * @return a reference to the modified instance of PrettyPrinter 301 * @see PrettyPrinter::operator< (const std::string s) 302 */ 50 303 PrettyPrinter& operator<< (const std::string s); 304 305 /*! 306 * A method for incrementing the number of times the baseIndent string is 307 * concatenated in order to form the current entire indent string. The increment equals 308 * the argument integer.<br> 309 * Use PrettyPrinter::setBaseIndent (const char* baseIndent) to define the 310 * baseIndent string. If e.g. baseIndent == "~~", and the incremented number of times 311 * this baseIndent will be used equals 3, then the current indent string will be set to 312 * "~~~~~~". 313 * @param i the number of times the baseIndent is use to form the current indent string 314 * @return a reference to the modified instance of PrettyPrinter 315 * @see PrettyPrinter::operator- (const int i) 316 */ 51 317 PrettyPrinter& operator+ (const int i); 318 319 /*! 320 * A method for decrementing the number of times the baseIndent string is 321 * concatenated in order to form the current entire indent string. The decrement equals 322 * the argument integer.<br> 323 * Use PrettyPrinter::setBaseIndent (const char* baseIndent) to define the 324 * baseIndent string. If e.g. baseIndent == "~~", and the decremented number of times 325 * this baseIndent will be used equals 3, then the current indent string will be set to 326 * "~~~~~~". 327 * @param i the number of times the baseIndent is use to form the current indent string 328 * @return a reference to the modified instance of PrettyPrinter 329 * @see PrettyPrinter::operator+ (const int i) 330 */ 52 331 PrettyPrinter& operator- (const int i); 332 333 /*! 334 * A method for setting the baseIndent string.<br> 335 * Note that this string is used to form the current entire indent string. 336 * @param baseIndent the new baseIndent string 337 * @return a reference to the modified instance of PrettyPrinter 338 * @see PrettyPrinter::getBaseIndent () const 339 */ 53 340 void setBaseIndent (const char* baseIndent); 341 342 /*! 343 * A method for retrieving the baseIndent string.<br> 344 * Note that this string is used to form the current entire indent string. 345 * @return the current baseIndent string 346 * @see PrettyPrinter::setBaseIndent (const char* baseIndent) 347 */ 54 348 char* getBaseIndent () const; 349 350 /*! 351 * A method for controling console output.<br> 352 * Use the parameter -1, if no console output is desired; 0 if there should be 353 * console output but no file output; 1 if console output should be identical to 354 * output to the primary file; and 2 if console output should be identical to 355 * output to the secondary file. 356 * @param console the control number as described in the method comment 357 * @see PrettyPrinter::getConsole () const 358 */ 55 359 void setConsole (const int console); 360 361 /*! 362 * A method for retrieving the console output control parameter.<br> 363 * @see PrettyPrinter::setConsole (const int console) 364 */ 56 365 int getConsole () const; 57 366 }; 58 367 59 #endif // defined(HAVE_MINOR) || defined(HAVE_WRAPPERS) 368 #endif 369 /* defined(HAVE_MINOR) || defined(HAVE_WRAPPERS) */ 60 370 61 371 #endif -
Singular/ReferenceCounter.cc
rbb503c7 ra388ae 3 3 #ifdef HAVE_WRAPPERS 4 4 5 #include <iostream> 6 #include "Wrappers.h" 5 7 #include "ReferenceCounter.h" 6 #include "Wrappers.h"7 #include <iostream>8 8 9 refcount_type ReferenceCounter::decrement ()9 ReferenceCounterType ReferenceCounter::decrement () 10 10 { 11 assume(m_counter > 0); / / Ensure positivity of counter11 assume(m_counter > 0); /* ensure positivity of counter */ 12 12 +prpr > "ReferenceCounter decremented to " < m_counter - 1; 13 13 return --m_counter; 14 } ;14 } 15 15 16 refcount_type ReferenceCounter::increment ()16 ReferenceCounterType ReferenceCounter::increment () 17 17 { 18 18 +prpr > "ReferenceCounter incremented to " < m_counter + 1; … … 26 26 27 27 ReferenceCounter::ReferenceCounter (const ReferenceCounter& rc) 28 { 28 { 29 29 assume(false); /* copy constructor should never be called */ 30 30 } … … 35 35 } 36 36 37 refcount_type ReferenceCounter::getCounter () const37 ReferenceCounterType ReferenceCounter::getCounter () const 38 38 { 39 39 return m_counter; … … 45 45 } 46 46 47 #endif // HAVE_WRAPPERS 47 #endif 48 /* HAVE_WRAPPERS */ -
Singular/ReferenceCounter.h
rbb503c7 ra388ae 4 4 #ifdef HAVE_WRAPPERS 5 5 6 /// Set type for storing reference counter 7 typedef unsigned long refcount_type; 6 #include "Wrappers.h" 8 7 8 /*! \class ReferenceCounter 9 * \brief Class ReferenceCounter may be used to derive classes from it 10 * which deploy reference counting. 11 * 12 * Any instance of a class, say C, derived from ReferenceCounter is 13 * equipped with a counter that stores how many instances of C exist. 14 * Thereby, it becomes possible to better manage instances of C and 15 * make shallow copies of instances of C by simply incrementing the 16 * reference counter (which is a member of the superclass of C, i.e., 17 * of ReferenceCounter). 18 * \author Frank Seelisch, http://www.mathematik.uni-kl.de/~seelisch 19 */ 9 20 class ReferenceCounter { 10 21 private: 11 /// Store reference counter 12 refcount_type m_counter; 22 /*! private member for storing the actual reference counter */ 23 ReferenceCounterType m_counter; 24 protected: 25 /*! 26 * A method for retrieving the actual reference counter. 27 * @return the actual reference counter 28 */ 29 ReferenceCounterType getCounter () const; 30 31 /*! 32 * A method for retrieving whether the reference counter is 33 * greater than 1. In this case, at least two references to the given 34 * instance of ReferenceCounter exist. 35 * @return true if the reference counter is greater than 1 36 */ 37 bool isShared () const; 38 39 /*! 40 * A method for incrementing the reference counter. 41 * @return the value of the reference counter after incrementing 42 * @see ReferenceCounterType::decrement (); 43 */ 44 ReferenceCounterType increment (); 45 46 /*! 47 * A method for decrementing the reference counter. 48 * @return the value of the reference counter after decrementing 49 * @see ReferenceCounterType::increment (); 50 */ 51 ReferenceCounterType decrement (); 13 52 public: 53 /*! 54 * A constructor for ReferenceCounter.<br> 55 * This constructor will create a new instance with actual 56 * reference counter set to zero. 57 */ 14 58 ReferenceCounter (); 15 59 16 /// Deep copy 60 /*! 61 * A copy constructor for ReferenceCounter.<br> 62 * As this constructor should neither be called by the user nor 63 * implicitely by some method, it will halt the program. 64 */ 17 65 ReferenceCounter (const ReferenceCounter& rc); 18 66 19 /// Destructor 67 /*! 68 * A destructor for ReferenceCounter. 69 */ 20 70 ~ReferenceCounter (); 21 22 /// Get reference counter 23 refcount_type getCounter () const; 24 25 /// Check, whether reference is used multiple times 26 bool isShared () const; 27 28 /// Increase reference counter 29 refcount_type increment (); 30 31 /// Decrease reference counter 32 refcount_type decrement (); 71 /*! We enable PolyWrapper to "see" all methods of ReferenceCounter. */ 72 friend class PolyWrapper; 33 73 }; 34 74 35 #endif // HAVE_WRAPPERS 75 #endif 76 /* HAVE_WRAPPERS */ 36 77 37 78 #endif -
Singular/RingWrapper.cc
rbb503c7 ra388ae 3 3 #ifdef HAVE_WRAPPERS 4 4 5 #include <iostream> 6 #include <stdio.h> 7 #include <string.h> 8 #include "febase.h" 5 9 #include "ipshell.h" 6 10 #include "grammar.h" 7 11 #include "ipid.h" 8 12 #include "polys.h" 9 #include <iostream>13 #include "Wrappers.h" 10 14 #include "RingWrapper.h" 11 #include "Wrappers.h"12 #include <stdio.h>13 #include <string.h>14 #include "febase.h"15 15 16 16 RingWrapper::RingWrapper (const char* ringName, const int characteristic, … … 30 30 m_singularRing->block0 = (int *)omAlloc0(2 * sizeof(int *)); 31 31 m_singularRing->block1 = (int *)omAlloc0(2 * sizeof(int *)); 32 /* ringorder 'ringOrder' for the first block: var 1.. N*/32 /* ringorder 'ringOrder' for the first block: var 1..varNumber */ 33 33 if (strcmp(ringOrder, "dp") == 0) m_singularRing->order[0] = ringorder_dp; 34 34 if (strcmp(ringOrder, "lp") == 0) m_singularRing->order[0] = ringorder_lp; … … 41 41 /* the last block: everything is 0 */ 42 42 m_singularRing->order[1] = 0; 43 /* polynomial ring*/43 /* polynomial ring */ 44 44 m_singularRing->OrdSgn = 1; 45 45 … … 50 50 RingWrapper::RingWrapper () 51 51 { 52 assume(false); // the default constructor, i.e. the one53 // without arguments should never be called52 +prpr > "creating a new RingWrapper (internal type: SINGULAR ring)"; 53 m_singularRing = currRing; 54 54 } 55 55 … … 66 66 int n = rVar(m_singularRing); 67 67 if (ch == 0) 68 {69 68 strcat(str, "Q"); 70 }71 69 else 72 70 { … … 76 74 } 77 75 strcat(str, "["); 78 for (int i = 0; i < n; i++) { 76 for (int i = 0; i < n; i++) 77 { 79 78 if (i > 0) strcat(str, ","); 80 79 strcat(str, m_singularRing->names[i]); … … 114 113 } 115 114 116 #endif // HAVE_WRAPPERS 115 #endif 116 /* HAVE_WRAPPERS */ -
Singular/RingWrapper.h
rbb503c7 ra388ae 7 7 #include "Wrappers.h" 8 8 9 /*! \class RingWrapper 10 * \brief Class RingWrapper provides a uniform interface to different 11 * representations of rings. 12 * 13 * Instances of RingWrapper uniformly represent different kinds of 14 * rings that play a role in the computer algebra system SINGULAR 15 * and related suites such as PolyBoRi. Especially SINGULAR-internal 16 * rings can be wrapped by instances of RingWrapper.<br> 17 * This is just a first implementation, so far for wrapping SINGULAR-internal 18 * rings only.<br> 19 * An important feature of RingWrapper is the check whether two given rings 20 * (wrapped as instances of RingWrapper) are compatible with respect to 21 * basic arithmetics; such as PolyWrapper::operator+ (const PolyWrapper& p) const. 22 * \author Frank Seelisch, http://www.mathematik.uni-kl.de/~seelisch 23 */ 9 24 class RingWrapper 10 25 { 11 26 private: 27 /*! a member for storing a SINGULAR-internal ring; 28 note that this is not just a reference to but an instance 29 of a SINGULAR-internal ring */ 12 30 SingularRing m_singularRing; 13 31 public: 32 /*! 33 * A constructor for RingWrapper.<br> 34 * This constructor builds a SINGULAR-internal ring with a given 35 * name, characteristic and list of variables. The monomial order 36 * must also be provided and must be one of {dp, lp, Dp, ds, ls, Ds}. 37 * @param ringName the name of the wrapped SINGULAR-internal ring 38 * @param characteristic the characteristic of the wrapped SINGULAR-internal ring 39 * @param varNumber the number of variables in the wrapped SINGULAR-internal ring 40 * @param varNames the array of names of variables in the wrapped SINGULAR-internal ring 41 * @param ringOrder one of {dp, lp, Dp, ds, ls, Ds} 42 * @see RingWrapper::RingWrapper () 43 */ 14 44 RingWrapper (const char* ringName, const int characteristic, 15 45 const int varNumber, const char** varNames, const char* ringOrder); 46 47 /*! 48 * A default constructor for RingWrapper.<br> 49 * This constructor wraps the current SINGULAR-internal ring which is 50 * assumed to use one of the monomial orderings of {dp, lp, Dp, ds, ls, Ds}. 51 * @see RingWrapper::RingWrapper (const char* ringName, const int characteristic, 52 const int varNumber, const char** varNames, const char* ringOrder) 53 */ 16 54 RingWrapper (); 55 56 /*! 57 * A destructor for RingWrapper.<br> 58 * Since the private member is an instance of a SINGULAR-internal ring and not 59 * a reference, the destructor for this SINGULAR-internal ring will be called. 60 * @see RingWrapper::RingWrapper () 61 * @see RingWrapper::RingWrapper (const char* ringName, const int characteristic, 62 const int varNumber, const char** varNames, const char* ringOrder) 63 */ 17 64 ~RingWrapper (); 65 66 /*! 67 * A method for printing a string representation of the given instance.<br> 68 * This method does not use std::cout but only SINGULAR-internal print routines. 69 * @see RingWrapper::printLn () const 70 * @see RingWrapper::toString () const 71 */ 18 72 void print () const; 73 74 /*! 75 * A method for printing a string representation of the given instance 76 * followed by a linefeed.<br> 77 * This method does not use std::cout but only SINGULAR-internal print routines. 78 * @see RingWrapper::print () const 79 * @see RingWrapper::toString () const 80 */ 19 81 void printLn () const; 82 83 /*! 84 * A method for obtaining a string representation of the given instance. 85 * @see RingWrapper::print () const 86 * @see RingWrapper::printLn () const 87 */ 20 88 char* toString () const; 89 90 /*! 91 * A method for checking whether two wrapped rings are compatible with 92 * respect to basic arithmetics such as PolyWrapper::operator+ (const PolyWrapper& p) 93 * @param r another RingWrapper 94 * @return true if the tow wrpaped rings are compatible 95 */ 21 96 bool isCompatible (const RingWrapper& r) const; 97 98 /*! 99 * A method for retrieving the wrapped SINGULAR-internal ring. 100 * @return the wrapped SINGULAR-internal ring 101 */ 22 102 const SingularRing& getSingularRing () const; 23 103 }; 24 104 25 #endif // HAVE_WRAPPERS 105 #endif 106 /* HAVE_WRAPPERS */ 26 107 27 108 #endif -
Singular/Wrappers.cc
rbb503c7 ra388ae 4 4 5 5 #include <iostream> 6 #include "febase.h" 7 #include "Wrappers.h" 6 8 #include "RingWrapper.h" 7 9 #include "PolyWrapper.h" 8 #include "Wrappers.h"9 #include "febase.h"10 10 11 void test0 (); 11 12 void test1 (); 12 13 void test2 (); 13 14 void test3 (); 15 void test4 (); 14 16 15 17 PrettyPrinter prpr("", "", false, false, -1, " "); 18 19 void wrapSINGULARPolys (const SingularPoly& sp1, const SingularPoly& sp2) 20 { 21 prpr.setConsole(-1); 22 PrintLn(); 23 RingWrapper r; /* wraps the current ring */ 24 PolyWrapper p1(sp1, r); 25 PolyWrapper p2(sp2, r); 26 PrintS("This is how the created instances of PolyWrapper look like:"); 27 PrintLn(); PrintS("p1 = "); p1.print(); 28 PrintLn(); PrintS("p2 = "); p2.print(); 29 PrintLn(); PrintS("And here comes their sum:"); 30 PolyWrapper q = p1 + p2; 31 PrintLn(); PrintS("p1 + p2 = "); q.print(); 32 PrintLn(); PrintLn(); 33 } 16 34 17 35 void testWrappers (bool detailedOutput) … … 20 38 prpr+1; 21 39 40 test0(); 22 41 test1(); 23 42 test2(); 24 43 test3(); 44 test4(); 25 45 26 46 prpr-1; … … 29 49 } 30 50 51 void test0 () 52 { 53 if (currRing != NULL) 54 { 55 PrintLn(); 56 PrintS("Test0: Creation of RingWrapper from current SINGULAR ring"); 57 58 RingWrapper r; 59 PrintLn(); PrintS("r = "); r.print(); 60 } 61 } 62 31 63 void test1 () 32 64 { 33 65 PrintLn(); 34 66 PrintS("Test1: Creation and destruction of instances of RingWrapper"); 67 35 68 const char* theVariables1[2] = {"x", "y"}; 36 69 RingWrapper r1("myRing1", 7, 2, theVariables1, "dp"); 37 70 PrintLn(); PrintS("r1 = "); r1.print(); 71 38 72 const char* theVariables2[3] = {"u", "v", "w"}; 39 73 RingWrapper r2("myRing2", 0, 3, theVariables2, "Ds"); … … 45 79 PrintLn(); 46 80 PrintS("Test2: Creation, copying, assignment, and destruction of instances of PolyWrapper"); 81 47 82 const char* theVariables[2] = {"x", "y"}; 48 83 RingWrapper r("myRing", 0, 2, theVariables, "lp"); 49 84 PrintLn(); PrintS("r = "); r.print(); 85 50 86 PolyWrapper p1(4, r); 51 87 PrintLn(); PrintS("p1 = "); p1.print(); … … 63 99 { 64 100 PrintLn(); 65 PrintS("Test3: Addition of instances of PolyWrapper"); 101 PrintS("Test3: Addition of compatible instances of PolyWrapper"); 102 66 103 const char* theVariables[2] = {"x", "y"}; 67 104 RingWrapper r("myRing", 0, 2, theVariables, "Ds"); 68 105 PrintLn(); PrintS("r = "); r.print(); 106 69 107 PolyWrapper p1(4, r); 70 108 PrintLn(); PrintS("p1 = "); p1.print(); … … 75 113 p3 = p1; 76 114 PrintLn(); PrintS("p3 = "); p3.print(); 77 p3 += p2; / / this should change p3 but NOT p2!115 p3 += p2; /* this should change p3 but NOT p2! */ 78 116 PrintLn(); PrintS("p3 = "); p3.print(); 79 117 PrintLn(); PrintS("p2 = "); p2.print(); 80 118 } 81 119 82 #endif // HAVE_WRAPPERS 120 void test4 () 121 { 122 PrintLn(); 123 PrintS("Test4: Addition of incompatible instances of PolyWrapper"); 124 125 const char* theVariables1[2] = {"x", "y"}; 126 RingWrapper r1("myRing", 0, 2, theVariables1, "dp"); 127 PrintLn(); PrintS("r1 = "); r1.print(); 128 129 const char* theVariables2[2] = {"x", "z"}; 130 RingWrapper r2("myRing", 0, 2, theVariables2, "dp"); 131 PrintLn(); PrintS("r2 = "); r2.print(); 132 133 PolyWrapper p1(4, r1); 134 PrintLn(); PrintS("p1 = "); p1.print(); 135 PolyWrapper p2(7, r2); 136 PrintLn(); PrintS("p2 = "); p2.print(); 137 PolyWrapper p3 = p1 + p2; /* this will not work */ 138 /* The last instruction will abnormally stop the system call, 139 due to an "assume(false)". Use detailed output to see more 140 details. */ 141 } 142 143 #endif 144 /* HAVE_WRAPPERS */ -
Singular/Wrappers.h
rbb503c7 ra388ae 8 8 #include "PrettyPrinter.h" 9 9 10 /*! \mainpage C++ wrappers for SINGULAR and related systems 11 * 12 * \section design Design Overview 13 * The following picture shows a UML-like design of the classes implemented so far, 14 * and their relationship. 15 * \image html "file:///C:/Work/C++Code/inside SINGULAR/C++Wrappers/Overview1.jpg" 16 * 17 * \section howto How to run this code inside SINGULAR 18 * The following steps need to be done to run the C++ wrapper code inside SINGULAR:<br><br> 19 * Re-build and run SINGULAR:<br> 20 * - checkout the latest code and compile SINGULAR,<br> 21 * - go to <c>/SINGULAR</c> and perform <c>make clean</c>,<br> 22 * - go to <c>/kernel</c> and perform <c>make clean</c>,<br> 23 * - open <c>/SINGULAR/mod2.h</c> and include the line <c>#define HAVE_WRAPPERS 1</c>,<br> 24 * - open <c>/kernel/mod2.h</c> and include the line <c>#define HAVE_WRAPPERS 1</c>,<br> 25 * - go to <c>/SINGULAR</c> and perform <c>make</c>,<br> 26 * - go to <c>/kernel</c> and perform <c>make</c> (Now you have a runnable SINGULAR version 27 * including the C++ wrapper code.),<br> 28 * - go to <c>/SINGULAR</c> and perform <c>./Singular</c> to run the newly built local 29 * executable<br> 30 * 31 * Call the new code:<br> 32 * - you may first declare a ring, e.g. by typing <c>ring r;</c>,<br> 33 * - type <c>system("c++wrappers", 0);</c> to perform <c>testWrappers</c> (see file Wrappers.h) without 34 * detailed printout to the console,<br> 35 * - type <c>system("c++wrappers", 1);</c> to perform <c>testWrappers</c> (see file Wrappers.h) with 36 * detailed printout to the console,<br> 37 * - declare a ring and two polynomials f and g; then type <c>system("c++wrappers", f, g);</c> 38 * to perform <c>wrapSINGULARPolys</c> (see file Wrappers.h). 39 */ 40 41 /*! type definition for the type of the instance counter inside the class ReferenceCounter */ 42 typedef unsigned long ReferenceCounterType; 43 44 /*! type definition for SINGULAR-internal polynomials */ 45 typedef poly SingularPoly; 46 47 /*! type definition for SINGULAR-internal rings */ 48 typedef ring SingularRing; 49 50 /*! 51 * A method for performing a series of tests with the wrapper code.<br> 52 * More concretely, the following tests will be performed:<br> 53 * - Test0: Creation of RingWrapper from current SINGULAR ring, if any,<br> 54 * - Test1: Creation and destruction of instances of RingWrapper,<br> 55 * - Test2: Creation, copying, assignment, and destruction of instances of PolyWrapper,<br> 56 * - Test3: Addition of compatible instances of PolyWrapper,<br> 57 * - Test4: Addition of incompatible instances of PolyWrapper.<br> 58 * 59 * After compiling SINGULAR and including the line<br> 60 * <c>#define HAVE_WRAPPERS 1</c><br> 61 * in <c>/SINGULAR/mod2.h</c> and in <c>/kernel/mod2.h</c>, the user may call this 62 * method by typing <c>system("c++wrappers", 0)</c> (without detailed console printout), 63 * or <c>system("c++wrappers", 1)</c> (with detailed console printout). 64 * @param detailedOutput if true this enforces a very detailed console output including internal method calls etc. 65 */ 10 66 void testWrappers (bool detailedOutput); 11 67 12 typedef poly SingularPoly; 13 typedef ring SingularRing; 68 /*! 69 * A method for wrapping SINGULAR-internal polynomials as instances of PolyWrapper 70 * and afterwards computing their sum as an instance of PolyWrapper.<br> 71 * After compiling SINGULAR and including the line<br> 72 * <c>#define HAVE_WRAPPERS 1</c><br> 73 * in <c>/SINGULAR/mod2.h</c> and in <c>/kernel/mod2.h</c>, the user may call this 74 * method by first declaring two polys f and g, and typing 75 * <c>system("c++wrappers", f, g)</c>. 76 * @param sp1 a SINGULAR-internal poly 77 * @param sp2 a SINGULAR-internal poly 78 */ 79 void wrapSINGULARPolys (const SingularPoly& sp1, const SingularPoly& sp2); 14 80 15 extern PrettyPrinter prpr; // for pretty printing 81 /*! PrettyPrinter used throughout all wrapper code 82 for pretty-printing detailed output to the console 83 if requested */ 84 extern PrettyPrinter prpr; 16 85 17 // some enums used for test prior 18 // to static casts; see code 19 #define UNSPECIFIED_POLY_TYPE 0 20 #define CANONICAL_POLY_TYPE 1 21 22 #endif // HAVE_WRAPPERS 86 #endif 87 /* HAVE_WRAPPERS */ 23 88 24 89 #endif -
Singular/extra.cc
rbb503c7 ra388ae 2 2 * Computer Algebra System SINGULAR * 3 3 *****************************************/ 4 /* $Id: extra.cc,v 1.32 6 2009-10-20 10:39:17 monerjanExp $ */4 /* $Id: extra.cc,v 1.327 2009-10-21 15:36:00 seelisch Exp $ */ 5 5 /* 6 6 * ABSTRACT: general interface to internals of Singular ("system" command) … … 2106 2106 if(strcmp(sys_cmd,"c++wrappers")==0) 2107 2107 { 2108 if (h == NULL) testWrappers(FALSE); / / wrapper tests, no detailed printout2108 if (h == NULL) testWrappers(FALSE); /* wrapper tests, without detailed printout */ 2109 2109 else if (h->Typ() == INT_CMD) 2110 2110 { 2111 2111 const int detailedOutput = (const int)(long)h->Data(); 2112 2112 testWrappers(detailedOutput == 0 ? FALSE : TRUE); 2113 // wrapper tests, with or without detailed printout 2113 /* wrapper tests, with or without detailed printout */ 2114 } 2115 else if ((h->Typ() == POLY_CMD) && 2116 (h->next->Typ() == POLY_CMD)) 2117 { 2118 const poly& p1 = (const poly)h->Data(); 2119 const poly& p2 = (const poly)h->next->Data(); 2120 wrapSINGULARPolys(p1, p2); 2121 /* wraps the given polys (as elements of the current ring) 2122 and displays the created instances of PolyWrapper, then 2123 their sum is computed as an instance of PolyWrapper and 2124 also displayed */ 2114 2125 } 2115 2126 return FALSE; 2116 2127 } 2117 2128 else 2118 #endif // HAVE_WRAPPERS 2129 #endif 2130 /* HAVE_WRAPPERS */ 2119 2131 /*==================== new minor code ========================*/ 2120 2132 #ifdef HAVE_MINOR 2121 2133 if(strcmp(sys_cmd,"minors")==0) 2122 2134 { 2123 if (h == NULL) minorUsageInfo(); / /writes some info to the console2124 // on how to use this experimental code2135 if (h == NULL) minorUsageInfo(); /* writes some info to the console 2136 on how to use this experimental code */ 2125 2137 else if (h->Typ() == INT_CMD) 2126 2138 { 2127 testIntMinors(0); / / effectivelyno arguments provided:2128 //this starts 5 default tests2129 //with a random matrix with2130 //integer entries;2131 //for that, no ring needs to be2132 // declared2139 testIntMinors(0); /* no arguments provided: 2140 this starts 5 default tests 2141 with a random matrix with 2142 integer entries; 2143 for that, no ring needs to be 2144 declared beforehand */ 2133 2145 } 2134 2146 else if ((h->Typ() == MATRIX_CMD) && … … 2145 2157 const int cacheWeight = (const int)(long)h->next->next->next->next->Data(); 2146 2158 ideal iii = testAllPolyMinorsAsIdeal(m, k, strategy, cacheEntries, cacheWeight); 2147 / / starts the computation of all k x kminors in the2148 //provided matrix m (which is assumed to have polynomial2149 //entries);2150 // when calling this method, a ring must bedeclared before;2151 // there will be one run using a cache with specified properties2159 /* starts the computation of all (k x k)-minors in the 2160 provided matrix m (which is assumed to have polynomial 2161 entries); 2162 when calling this method, a ring must have been declared before; 2163 there will be one run using a cache with specified properties */ 2152 2164 res->rtyp = IDEAL_CMD; 2153 2165 res->data = iii; … … 2168 2180 const int characteristic = (const int)(long)h->next->next->next->next->next->Data(); 2169 2181 ideal iii = testAllIntMinorsAsIdeal(m, k, strategy, cacheEntries, cacheWeight, characteristic); 2170 / / starts the computation of all k x kminors in the2171 //provided matrix m (which is assumed to have integer2172 //entries);2173 // when calling this method, a ring must bedeclared before;2174 //there will be one run using a cache with specified properties;2175 // the resulting minors will be computed modulo the given characteristic2182 /* starts the computation of all (k x k)-minors in the 2183 provided matrix m (which is assumed to have integer 2184 entries); 2185 when calling this method, a ring must have been declared before; 2186 there will be one run using a cache with specified properties; 2187 the resulting minors will be computed modulo the given characteristic */ 2176 2188 res->rtyp = IDEAL_CMD; 2177 2189 res->data = iii; … … 2197 2209 const int dumpConsole = (const int)(long)h->next->next->next->next->next->next->next->next->Data(); 2198 2210 testAllPolyMinors(m, k, strategies, cacheEntries, cacheWeight, dumpMinors, dumpResults, dumpComplete, dumpConsole); 2199 // starts the computation of all k x k minors in the 2200 // provided matrix m (which is assumed to have polynomial 2201 // entries) using a cache with a maximum number of 2202 // 'cacheEntries' entries and a maximum weight of 'cacheWeight'; 2203 // when calling this method, a ring must be declared before; 2204 // strategy = "310" means that the code is run first without a 2205 // cache ("0") and then afterwards with the caching strategies 2206 // "1" and "3" 2211 /* starts the computation of all (k x k)-minors in the 2212 provided matrix m (which is assumed to have polynomial 2213 entries) using a cache with a maximum number of 2214 'cacheEntries' entries and a maximum weight of 'cacheWeight' 2215 (The weight is the number of cached monomials, counted over 2216 all cached polynomials.); 2217 when calling this method, a ring must have been declared before; 2218 strategy = "310" means that the code is run first without a 2219 cache ("0") and then afterwards with the caching strategies 2220 "1" and "3" */ 2207 2221 } 2208 2222 else if (h->Typ() == POLY_CMD) 2209 { / / for quick tests with a single polynomial2223 { /* for quick tests with a single polynomial */ 2210 2224 const poly p = (const poly)h->Data(); 2211 2225 testStuff(p); … … 2222 2236 const int varN = (const int)(long)h->next->Data(); 2223 2237 { 2224 /* 2225 The following code creates and returns a ring with characteristic fc, 2226 order dp and varN variables with the names "x1", "x2", ..., "x4711" 2227 (in the case varN = 4711). 2228 The purpose of this rewriting is to eliminate indexed variables, 2229 as they may cause problems when generating scripts for Magma, 2230 Maple, or Macaulay2. 2231 */ 2238 /* The following code creates and returns a ring with characteristic fc, 2239 order dp and varN variables with the names "x1", "x2", ..., "x4711" 2240 (in the case varN = 4711). 2241 The purpose of this rewriting is to eliminate indexed variables, 2242 as they may cause problems when generating scripts for Magma, 2243 Maple, or Macaulay2. */ 2232 2244 ring newRing = (ring) omAlloc0Bin(sip_sring_bin); 2233 2245 newRing->ch = fc; … … 2257 2269 } 2258 2270 else 2259 #endif // HAVE_MINOR 2271 #endif 2272 /* HAVE_MINOR */ 2260 2273 /*==================== generic debug ==================================*/ 2261 2274 #ifdef PDEBUG … … 3450 3463 extern BOOLEAN Main(leftv res, leftv h); // FALSE = Ok, TRUE = Error! 3451 3464 return Main(res, h); 3452 } 3465 } 3453 3466 else 3454 3467 #endif // HAVE_SINGULAR_PLUS_PLUS … … 3467 3480 if (strcmp(sys_cmd,"gfan")==0) 3468 3481 { 3469 // if ((h==NULL) || (h!=NULL && h->Typ()!=IDEAL_CMD)) 3470 // { 3471 // Werror("system(\"gfan\"...) Ideal expected"); 3472 // return TRUE; //Ooooops 3473 // } 3474 // else if(h->next==NULL) 3475 // { 3476 // Werror("gfan expects an integer parameter"); 3477 // return TRUE; 3478 // } 3479 // else if(h->next!=NULL && h->next->Typ()!=INT_CMD) 3480 // { 3481 // Werror("1st parameter ist no integer"); 3482 // return TRUE; 3483 // } 3484 /* 3485 heuristic: 3486 0 = keep all Gröbner bases in memory 3487 1 = write all Gröbner bases to disk and read whenever necessary 3488 2 = use a mixed heuristic, based on length of Gröbner bases 3489 */ 3490 if( h!=NULL && h->Typ()==IDEAL_CMD && h->next!=NULL && h->next->Typ()==INT_CMD) 3491 { 3492 int heuristic; 3493 heuristic=(int)(long)h->next->Data(); 3494 ideal I=((ideal)h->Data()); 3495 res->rtyp=IDEAL_CMD; 3496 res->data=(ideal) gfan(I,heuristic); 3497 return FALSE; 3498 } 3499 else 3500 { 3501 WerrorS("Usage: system(\"gfan\",I,int)"); 3502 return TRUE; 3503 } 3482 if ((h==NULL) || (h!=NULL && h->Typ()!=IDEAL_CMD)) 3483 { 3484 Werror("system(\"gfan\"...) Ideal expected"); 3485 return TRUE; //Ooooops 3486 } 3487 ideal I=((ideal)h->Data()); 3488 res->rtyp=IDEAL_CMD; 3489 res->data=(ideal) gfan(I); 3504 3490 //res->rtyp=LIST_CMD; 3505 3491 //res->data= ??? 3506 3492 3507 //return FALSE; //Everything went fine3493 return FALSE; //Everything went fine 3508 3494 } 3509 3495 else
Note: See TracChangeset
for help on using the changeset viewer.