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::deg_type deg_type;
00102 typedef CTypes::idx_type idx_type;
00103 typedef CTypes::hash_type hash_type;
00104 typedef CTypes::bool_type bool_type;
00105 typedef CTypes::comp_type comp_type;
00106 typedef CTypes::integer_type integer_type;
00107 typedef CTypes::ostream_type ostream_type;
00109
00111 typedef std::vector<idx_type> data_type;
00112
00114 typedef data_type::value_type value_type;
00115
00117
00118 typedef data_type::iterator iterator;
00119 typedef data_type::const_iterator const_iterator;
00120 typedef data_type::reverse_iterator reverse_iterator;
00121 typedef data_type::const_reverse_iterator const_reverse_iterator;
00123
00125 typedef BooleExponent self;
00126
00128 typedef BoolePolynomial poly_type;
00129
00131 typedef BooleVariable var_type;
00132
00134 typedef BooleMonomial monom_type;
00135
00137 typedef BooleSet set_type;
00138
00140 typedef generate_index_map<self>::type idx_map_type;
00141
00143 typedef invalid_tag easy_equality_property;
00144
00146 BooleExponent();
00147
00149 BooleExponent(const self&);
00150
00151 explicit BooleExponent(bool);
00152
00154 self& get(const monom_type&);
00155
00156
00157
00158
00160 ~BooleExponent();
00161
00163 const_iterator begin() const { return m_data.begin(); }
00164
00166 const_iterator end() const { return m_data.end(); }
00167
00169 const_reverse_iterator rbegin() const { return m_data.rbegin(); }
00170
00172 const_reverse_iterator rend() const { return m_data.rend(); }
00173
00175 deg_type size() const { return (deg_type)m_data.size(); }
00176
00178 void reserve(size_type nsize) { m_data.reserve(nsize); }
00179
00181 void resize(size_type nsize) { m_data.resize(nsize); }
00182
00184 size_type deg() const { return size(); }
00185
00187 set_type divisors() const;
00188
00190 set_type multiples(const self&) const;
00191
00193 hash_type stableHash() const {
00194 return stable_term_hash(begin(), end());
00195 }
00196
00198 hash_type hash() const { return stableHash(); }
00199
00201 self& changeAssign(idx_type);
00202
00204 self change(idx_type) const;
00205
00207 self& insert(idx_type);
00208
00210 self& push_back(idx_type idx);
00211
00213 self& remove(idx_type);
00214
00216 self insertConst(idx_type) const;
00217
00219 self removeConst(idx_type) const;
00220
00222 self divide(const self&) const;
00223 self divide(const idx_type& rhs) const {
00224 return (reducibleBy(rhs)? removeConst(rhs) : self() ); }
00225
00226 self divide(const var_type& rhs) const { return divide(rhs.index()); }
00227 self divide(const monom_type&) const;
00228
00230 self multiply(const self&) const;
00231
00232 self multiply(const idx_type& rhs) const { return insertConst(rhs); }
00233 self multiply(const var_type& rhs) const { return multiply(rhs.index()); }
00234 self multiply(const monom_type&) const;
00235 self multiplyFirst(const set_type&) const;
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00247
00248 bool_type operator==(const self& rhs) const { return m_data == rhs.m_data; }
00249 bool_type operator!=(const self& rhs) const { return m_data != rhs.m_data; }
00251
00253 self& operator=(const self& rhs) { m_data = rhs.m_data; return *this; }
00254 self& operator=(const monom_type& rhs) {
00255 m_data.resize(rhs.size());
00256 std::copy(rhs.begin(), rhs.end(), internalBegin());
00257 return *this;
00258 }
00259
00261 bool_type reducibleBy(const self& rhs) const;
00262 bool_type reducibleBy(const monom_type& rhs) const;
00263 bool_type reducibleBy(const idx_type& rhs) const;
00264 bool_type reducibleBy(const var_type& rhs) const {
00265 return reducibleBy(rhs.index()); }
00266
00267
00268
00269
00270
00272 comp_type compare(const self&) const;
00273
00275 size_type LCMDeg(const self&) const;
00276
00279
00281 self LCM(const self&) const;
00282
00284
00285
00287 self GCD(const self&) const;
00288
00290 self& popFirst() {
00291 assert(!m_data.empty());
00292 m_data.erase(m_data.begin());
00293 return *this;
00294 }
00295
00297 ostream_type& print(ostream_type&) const;
00298
00299 protected:
00301 iterator internalBegin() { return m_data.begin(); }
00302
00304 iterator internalEnd() { return m_data.end(); }
00305
00307 reverse_iterator rInternalBegin() { return m_data.rbegin(); }
00308
00310 reverse_iterator rInternalEnd() { return m_data.rend(); }
00311
00313 data_type m_data;
00314 };
00315
00316
00318 template <class RHSType>
00319 inline BooleExponent
00320 operator+(const BooleExponent& lhs, const RHSType& rhs) {
00321 return lhs.multiply(rhs);
00322 }
00323
00325 template <class RHSType>
00326 inline BooleExponent
00327 operator-(const BooleExponent& lhs, const RHSType& rhs) {
00328 return lhs.divide(rhs);
00329 }
00330
00331
00333 inline BooleExponent::bool_type
00334 operator<(const BooleExponent& lhs, const BooleExponent& rhs) {
00335
00336 return (lhs.compare(rhs) == CTypes::less_than);
00337 }
00338
00340 inline BooleExponent::bool_type
00341 operator>(const BooleExponent& lhs, const BooleExponent& rhs) {
00342
00343 return (lhs.compare(rhs) == CTypes::greater_than);
00344 }
00345
00347 inline BooleExponent::bool_type
00348 operator<=(const BooleExponent& lhs, const BooleExponent& rhs) {
00349
00350 return (lhs.compare(rhs) <= CTypes::less_or_equal_max);
00351 }
00352
00354 inline BooleExponent::bool_type
00355 operator>=(const BooleExponent& lhs, const BooleExponent& rhs) {
00356
00357 return (lhs.compare(rhs) >= CTypes::greater_or_equal_min);
00358 }
00359
00360
00362 inline BooleExponent
00363 GCD(const BooleExponent& lhs, const BooleExponent& rhs ){
00364
00365 return lhs.GCD(rhs);
00366 }
00367
00369 inline BooleExponent
00370 LCM(const BooleExponent& lhs, const BooleExponent& rhs ){
00371
00372 return lhs.LCM(rhs);
00373 }
00374
00375
00377 inline BooleExponent::ostream_type&
00378 operator<<(BooleExponent::ostream_type& os, const BooleExponent& rhs) {
00379 return rhs.print(os);
00380 }
00381
00382 END_NAMESPACE_PBORI
00383
00384 #endif // of BooleExponent_h_