00001
00002
00070
00071
00072 #ifndef BooleExponent_h_
00073 #define BooleExponent_h_
00074
00075
00076 #include "pbori_defs.h"
00077
00078
00079 #include "BooleMonomial.h"
00080 #include "BooleVariable.h"
00081
00082 BEGIN_NAMESPACE_PBORI
00083
00089 class BooleExponent {
00090
00091 public:
00092
00093
00094
00095
00096
00098
00099 typedef CTypes::dd_type dd_type;
00100 typedef CTypes::size_type size_type;
00101 typedef CTypes::idx_type idx_type;
00102 typedef CTypes::hash_type hash_type;
00103 typedef CTypes::bool_type bool_type;
00104 typedef CTypes::comp_type comp_type;
00105 typedef CTypes::integer_type integer_type;
00106 typedef CTypes::ostream_type ostream_type;
00108
00110 typedef std::vector<idx_type> data_type;
00111
00113 typedef data_type::value_type value_type;
00114
00116
00117 typedef data_type::iterator iterator;
00118 typedef data_type::const_iterator const_iterator;
00119 typedef data_type::reverse_iterator reverse_iterator;
00120 typedef data_type::const_reverse_iterator const_reverse_iterator;
00122
00124 typedef BooleExponent self;
00125
00127 typedef BoolePolynomial poly_type;
00128
00130 typedef BooleVariable var_type;
00131
00133 typedef BooleMonomial monom_type;
00134
00136 typedef BooleSet set_type;
00137
00139 typedef generate_index_map<self>::type idx_map_type;
00140
00142 typedef invalid_tag easy_equality_property;
00143
00145 BooleExponent();
00146
00148 BooleExponent(const self&);
00149
00150 explicit BooleExponent(bool);
00151
00153 self& get(const monom_type&);
00154
00155
00156
00157
00159 ~BooleExponent();
00160
00162 const_iterator begin() const { return m_data.begin(); }
00163
00165 const_iterator end() const { return m_data.end(); }
00166
00168 const_reverse_iterator rbegin() const { return m_data.rbegin(); }
00169
00171 const_reverse_iterator rend() const { return m_data.rend(); }
00172
00174 size_type size() const { return m_data.size(); }
00175
00177 void reserve(size_type nsize) { m_data.reserve(nsize); }
00178
00180 void resize(size_type nsize) { m_data.resize(nsize); }
00181
00183 size_type deg() const { return size(); }
00184
00186 set_type divisors() const;
00187
00189 set_type multiples(const self&) const;
00190
00192 hash_type stableHash() const {
00193 return stable_term_hash(begin(), end());
00194 }
00195
00197 hash_type hash() const { return stableHash(); }
00198
00200 self& changeAssign(idx_type);
00201
00203 self change(idx_type) const;
00204
00206 self& insert(idx_type);
00207
00209 self& push_back(idx_type idx);
00210
00212 self& remove(idx_type);
00213
00215 self insertConst(idx_type) const;
00216
00218 self removeConst(idx_type) const;
00219
00221 self divide(const self&) const;
00222 self divide(const idx_type& rhs) const {
00223 return (reducibleBy(rhs)? removeConst(rhs) : self() ); }
00224
00225 self divide(const var_type& rhs) const { return divide(rhs.index()); }
00226 self divide(const monom_type&) const;
00227
00229 self multiply(const self&) const;
00230
00231 self multiply(const idx_type& rhs) const { return insertConst(rhs); }
00232 self multiply(const var_type& rhs) const { return multiply(rhs.index()); }
00233 self multiply(const monom_type&) const;
00234 self multiplyFirst(const set_type&) const;
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00246
00247 bool_type operator==(const self& rhs) const { return m_data == rhs.m_data; }
00248 bool_type operator!=(const self& rhs) const { return m_data != rhs.m_data; }
00250
00252 self& operator=(const self& rhs) { m_data = rhs.m_data; return *this; }
00253 self& operator=(const monom_type& rhs) {
00254 m_data.resize(rhs.size());
00255 std::copy(rhs.begin(), rhs.end(), internalBegin());
00256 return *this;
00257 }
00258
00260 bool_type reducibleBy(const self& rhs) const;
00261 bool_type reducibleBy(const monom_type& rhs) const;
00262 bool_type reducibleBy(const idx_type& rhs) const;
00263 bool_type reducibleBy(const var_type& rhs) const {
00264 return reducibleBy(rhs.index()); }
00265
00266
00267
00268
00269
00271 comp_type compare(const self&) const;
00272
00274 size_type LCMDeg(const self&) const;
00275
00278
00280 self LCM(const self&) const;
00281
00283
00284
00286 self GCD(const self&) const;
00287
00289 self& popFirst() {
00290 assert(!m_data.empty());
00291 m_data.erase(m_data.begin());
00292 return *this;
00293 }
00294
00296 ostream_type& print(ostream_type&) const;
00297
00298 protected:
00300 iterator internalBegin() { return m_data.begin(); }
00301
00303 iterator internalEnd() { return m_data.end(); }
00304
00306 reverse_iterator rInternalBegin() { return m_data.rbegin(); }
00307
00309 reverse_iterator rInternalEnd() { return m_data.rend(); }
00310
00312 data_type m_data;
00313 };
00314
00315
00317 template <class RHSType>
00318 inline BooleExponent
00319 operator+(const BooleExponent& lhs, const RHSType& rhs) {
00320 return lhs.multiply(rhs);
00321 }
00322
00324 template <class RHSType>
00325 inline BooleExponent
00326 operator-(const BooleExponent& lhs, const RHSType& rhs) {
00327 return lhs.divide(rhs);
00328 }
00329
00330
00332 inline BooleExponent::bool_type
00333 operator<(const BooleExponent& lhs, const BooleExponent& rhs) {
00334
00335 return (lhs.compare(rhs) == CTypes::less_than);
00336 }
00337
00339 inline BooleExponent::bool_type
00340 operator>(const BooleExponent& lhs, const BooleExponent& rhs) {
00341
00342 return (lhs.compare(rhs) == CTypes::greater_than);
00343 }
00344
00346 inline BooleExponent::bool_type
00347 operator<=(const BooleExponent& lhs, const BooleExponent& rhs) {
00348
00349 return (lhs.compare(rhs) <= CTypes::less_or_equal_max);
00350 }
00351
00353 inline BooleExponent::bool_type
00354 operator>=(const BooleExponent& lhs, const BooleExponent& rhs) {
00355
00356 return (lhs.compare(rhs) >= CTypes::greater_or_equal_min);
00357 }
00358
00359
00361 inline BooleExponent
00362 GCD(const BooleExponent& lhs, const BooleExponent& rhs ){
00363
00364 return lhs.GCD(rhs);
00365 }
00366
00368 inline BooleExponent
00369 LCM(const BooleExponent& lhs, const BooleExponent& rhs ){
00370
00371 return lhs.LCM(rhs);
00372 }
00373
00374
00376 inline BooleExponent::ostream_type&
00377 operator<<(BooleExponent::ostream_type& os, const BooleExponent& rhs) {
00378 return rhs.print(os);
00379 }
00380
00381 END_NAMESPACE_PBORI
00382
00383 #endif // of BooleExponent_h_