PolyBoRi
|
00001 00002 // -*- c++ -*- 00003 //***************************************************************************** 00015 //***************************************************************************** 00016 00017 #ifndef polybori_BooleExponent_h_ 00018 #define polybori_BooleExponent_h_ 00019 00020 // include basic definitions 00021 #include <polybori/pbori_defs.h> 00022 00023 // get definition of BoolePolynomial, BooleMonomial, and BooleVariable 00024 #include <polybori/BooleMonomial.h> 00025 #include <polybori/BooleVariable.h> 00026 00027 BEGIN_NAMESPACE_PBORI 00028 00034 class BooleExponent: 00035 public CAuxTypes { 00036 00037 public: 00038 00039 //------------------------------------------------------------------------- 00040 // types definitions 00041 //------------------------------------------------------------------------- 00042 00044 typedef std::vector<idx_type> data_type; 00045 00047 typedef data_type::value_type value_type; 00048 00050 00051 typedef data_type::iterator iterator; 00052 typedef data_type::const_iterator const_iterator; 00053 typedef data_type::reverse_iterator reverse_iterator; 00054 typedef data_type::const_reverse_iterator const_reverse_iterator; 00056 00058 typedef BooleExponent self; 00059 00061 typedef BoolePolynomial poly_type; 00062 00064 typedef poly_type::ring_type ring_type; 00065 00067 typedef poly_type::var_type var_type; 00068 00070 typedef poly_type::monom_type monom_type; 00071 00073 typedef poly_type::set_type set_type; 00074 00076 typedef generate_index_map<self>::type idx_map_type; 00077 00079 typedef invalid_tag easy_equality_property; 00080 00082 BooleExponent(); 00083 00085 BooleExponent(const self&); 00086 00087 // explicit BooleExponent(bool); 00088 00090 self& get(const monom_type&); 00091 explicit BooleExponent(const monom_type& rhs); 00092 00094 ~BooleExponent(); 00095 00097 const_iterator begin() const { return m_data.begin(); } 00098 00100 const_iterator end() const { return m_data.end(); } 00101 00103 const_reverse_iterator rbegin() const { return m_data.rbegin(); } 00104 00106 const_reverse_iterator rend() const { return m_data.rend(); } 00107 00109 size_type size() const { return m_data.size(); } 00110 00112 void reserve(size_type nsize) { m_data.reserve(nsize); } 00113 00115 void resize(size_type nsize) { m_data.resize(nsize); } 00116 00118 deg_type deg() const { return size(); } 00119 00121 set_type divisors(const ring_type&) const; 00122 00124 set_type multiples(const self&, const ring_type&) const; 00125 00127 set_type multiples(const monom_type&) const; 00128 00130 hash_type stableHash() const { 00131 return stable_term_hash(begin(), end()); 00132 } 00133 00135 hash_type hash() const { return stableHash(); } 00136 00138 self& changeAssign(idx_type); 00139 00141 self change(idx_type) const; 00142 00144 self& insert(idx_type); 00145 00147 self& push_back(idx_type idx); 00148 00150 self& remove(idx_type); 00151 00153 self insertConst(idx_type) const; 00154 00156 self removeConst(idx_type) const; 00157 00159 self divide(const self&) const; 00160 self divideByIndex(const idx_type& rhs) const { 00161 return (reducibleBy(rhs)? removeConst(rhs) : self() ); } 00162 00163 self divide(const var_type& rhs) const { return divideByIndex(rhs.index()); } 00164 self divide(const monom_type&) const; 00165 00167 self multiply(const self&) const; 00168 00169 self multiply(const idx_type& rhs) const { return insertConst(rhs); } 00170 self multiply(const var_type& rhs) const { return multiply(rhs.index()); } 00171 self multiply(const monom_type&) const; 00172 self multiplyFirst(const set_type&) const; 00173 00174 00175 // /// @name Arithmetical operations 00176 // //@{ 00177 // self& operator*=(const self&); 00178 // self& operator/=(const self&); 00179 // self& operator*=(const var_type&); 00180 // self& operator/=(const var_type&); 00181 // //@} 00182 00184 00185 bool_type operator==(const self& rhs) const { return m_data == rhs.m_data; } 00186 bool_type operator!=(const self& rhs) const { return m_data != rhs.m_data; } 00188 00190 self& operator=(const self& rhs) { m_data = rhs.m_data; return *this; } 00191 self& operator=(const monom_type& rhs) { 00192 m_data.resize(rhs.size()); 00193 std::copy(rhs.begin(), rhs.end(), internalBegin()); 00194 return *this; 00195 } 00196 00198 bool_type reducibleBy(const self& rhs) const; 00199 bool_type reducibleBy(const monom_type& rhs) const; 00200 bool_type reducibleBy(const idx_type& rhs) const; 00201 bool_type reducibleBy(const var_type& rhs) const { 00202 return reducibleBy(rhs.index()); } 00203 00204 00205 // /// Test for reducibility wrt. to a given variable 00206 // bool_type reducibleBy(const var_type& rhs) const; 00207 00209 deg_type LCMDeg(const self&) const; 00210 00213 00215 self LCM(const self&) const; 00216 00218 //self& GCDAssign(const self&); 00219 00221 self GCD(const self&) const; 00222 00224 self& popFirst() { 00225 if(!m_data.empty()) 00226 m_data.erase(m_data.begin()); 00227 return *this; 00228 } 00229 00231 ostream_type& print(ostream_type&) const; 00232 00233 protected: 00235 iterator internalBegin() { return m_data.begin(); } 00236 00238 iterator internalEnd() { return m_data.end(); } 00239 00241 reverse_iterator rInternalBegin() { return m_data.rbegin(); } 00242 00244 reverse_iterator rInternalEnd() { return m_data.rend(); } 00245 00247 data_type m_data; 00248 }; 00249 00250 00252 template <class RHSType> 00253 inline BooleExponent 00254 operator+(const BooleExponent& lhs, const RHSType& rhs) { 00255 return lhs.multiply(rhs); 00256 } 00257 00259 template <class RHSType> 00260 inline BooleExponent 00261 operator-(const BooleExponent& lhs, const RHSType& rhs) { 00262 return lhs.divide(rhs); 00263 } 00264 00266 inline BooleExponent 00267 GCD(const BooleExponent& lhs, const BooleExponent& rhs ){ 00268 00269 return lhs.GCD(rhs); 00270 } 00271 00273 inline BooleExponent 00274 LCM(const BooleExponent& lhs, const BooleExponent& rhs ){ 00275 00276 return lhs.LCM(rhs); 00277 } 00278 00279 00281 inline BooleExponent::ostream_type& 00282 operator<<(BooleExponent::ostream_type& os, const BooleExponent& rhs) { 00283 return rhs.print(os); 00284 } 00285 00286 END_NAMESPACE_PBORI 00287 00288 #endif // of polybori_BooleExponent_h_