PolyBoRi
BooleExponent.h
Go to the documentation of this file.
00001 // -*- c++ -*-
00002 //*****************************************************************************
00014 //*****************************************************************************
00015 
00016 #ifndef BooleExponent_h_
00017 #define BooleExponent_h_
00018 
00019 // include basic definitions
00020 #include "pbori_defs.h"
00021 
00022 // get definition of BoolePolynomial, BooleMonomial, and BooleVariable
00023 #include "BooleMonomial.h"
00024 #include "BooleVariable.h"
00025 
00026 BEGIN_NAMESPACE_PBORI
00027 
00033 class BooleExponent:
00034   public CAuxTypes {
00035 
00036  public:
00037 
00038   //-------------------------------------------------------------------------
00039   // types definitions
00040   //-------------------------------------------------------------------------
00041 
00043   typedef std::vector<idx_type> data_type;
00044 
00046   typedef data_type::value_type value_type;
00047 
00049 
00050   typedef data_type::iterator iterator;
00051   typedef data_type::const_iterator const_iterator;
00052   typedef data_type::reverse_iterator reverse_iterator;
00053   typedef data_type::const_reverse_iterator const_reverse_iterator;
00055 
00057   typedef BooleExponent self;
00058 
00060   typedef BoolePolynomial poly_type;
00061 
00063   typedef BooleVariable var_type;
00064 
00066   typedef BooleMonomial monom_type;
00067 
00069   typedef BooleSet set_type;
00070 
00072   typedef generate_index_map<self>::type idx_map_type;
00073 
00075   typedef invalid_tag easy_equality_property;
00076 
00078   BooleExponent();
00079 
00081   BooleExponent(const self&);
00082 
00083   //  explicit BooleExponent(bool);
00084 
00086   self& get(const monom_type&);
00087   explicit BooleExponent(const monom_type& rhs);
00088 
00089 //   /// Construct from Boolean constant
00090 //   BooleExponent(bool_type);
00091 
00093   ~BooleExponent();
00094 
00096   const_iterator begin() const { return m_data.begin(); }
00097 
00099   const_iterator end() const { return m_data.end(); }
00100 
00102   const_reverse_iterator rbegin() const { return m_data.rbegin(); }
00103 
00105   const_reverse_iterator rend() const { return m_data.rend(); }
00106 
00108   size_type size() const { return m_data.size(); }
00109 
00111   void reserve(size_type nsize) { m_data.reserve(nsize); }
00112 
00114   void resize(size_type nsize) { m_data.resize(nsize); }
00115 
00117   size_type deg() const { return size(); }
00118 
00120   set_type divisors() const;
00121 
00123   set_type multiples(const self&) const; 
00124 
00126   hash_type stableHash() const {
00127     return stable_term_hash(begin(), end());
00128   }
00129 
00131   hash_type hash() const { return stableHash(); }
00132 
00134   self& changeAssign(idx_type);
00135 
00137   self change(idx_type) const;
00138 
00140   self& insert(idx_type);
00141 
00143   self& push_back(idx_type idx);
00144 
00146   self& remove(idx_type);
00147 
00149   self insertConst(idx_type) const;
00150 
00152   self removeConst(idx_type) const;
00153 
00155   self divide(const self&) const;
00156   self divideByIndex(const idx_type& rhs) const { 
00157     return (reducibleBy(rhs)? removeConst(rhs) : self() ); }
00158 
00159   self divide(const var_type& rhs) const { return divideByIndex(rhs.index()); }
00160   self divide(const monom_type&) const;
00161 
00163   self multiply(const self&) const;
00164 
00165   self multiply(const idx_type& rhs) const { return insertConst(rhs); }
00166   self multiply(const var_type& rhs) const { return multiply(rhs.index()); }
00167   self multiply(const monom_type&) const;
00168   self multiplyFirst(const set_type&) const;
00169 
00170 
00171 //   /// @name Arithmetical operations
00172 //   //@{
00173 //   self& operator*=(const self&);
00174 //   self& operator/=(const self&);
00175 //   self& operator*=(const var_type&);
00176 //   self& operator/=(const var_type&);
00177 //   //@}
00178 
00180 
00181   bool_type operator==(const self& rhs) const { return m_data == rhs.m_data; }
00182   bool_type operator!=(const self& rhs) const { return m_data != rhs.m_data; }
00184 
00186   self& operator=(const self& rhs) { m_data = rhs.m_data; return *this; }
00187   self& operator=(const monom_type& rhs) {
00188     m_data.resize(rhs.size());
00189     std::copy(rhs.begin(), rhs.end(), internalBegin());
00190     return *this;
00191   }
00192 
00194   bool_type reducibleBy(const self& rhs) const;
00195   bool_type reducibleBy(const monom_type& rhs) const;
00196   bool_type reducibleBy(const idx_type& rhs) const;
00197   bool_type reducibleBy(const var_type& rhs) const { 
00198     return reducibleBy(rhs.index()); }
00199 
00200 
00201 //   /// Test for reducibility wrt. to a given variable
00202 //   bool_type reducibleBy(const var_type& rhs) const;
00203 
00205   comp_type compare(const self&) const;
00206 
00208   size_type LCMDeg(const self&) const;
00209 
00212 
00214   self LCM(const self&) const;
00215 
00217   //self& GCDAssign(const self&);
00218 
00220   self GCD(const self&) const;
00221 
00223   self& popFirst() {
00224     if(!m_data.empty())
00225       m_data.erase(m_data.begin());
00226     return *this; 
00227   }
00228 
00230   ostream_type& print(ostream_type&) const;
00231  
00232 protected:
00234   iterator internalBegin() { return m_data.begin(); }
00235 
00237   iterator internalEnd() { return m_data.end(); }
00238 
00240   reverse_iterator rInternalBegin() { return m_data.rbegin(); }
00241 
00243   reverse_iterator rInternalEnd() { return m_data.rend(); }
00244 
00246   data_type m_data;
00247 };
00248 
00249 
00251 template <class RHSType>
00252 inline BooleExponent
00253 operator+(const BooleExponent& lhs, const RHSType& rhs) {
00254   return lhs.multiply(rhs);
00255 }
00256 
00258 template <class RHSType>
00259 inline BooleExponent
00260 operator-(const BooleExponent& lhs, const RHSType& rhs) {
00261   return lhs.divide(rhs);
00262 }
00263 
00264 
00266 inline BooleExponent::bool_type
00267 operator<(const BooleExponent& lhs, const BooleExponent& rhs) {
00268 
00269   return (lhs.compare(rhs) == CTypes::less_than);
00270 }
00271 
00273 inline BooleExponent::bool_type
00274 operator>(const BooleExponent& lhs, const BooleExponent& rhs) {
00275 
00276   return (lhs.compare(rhs) == CTypes::greater_than);
00277 }
00278 
00280 inline BooleExponent::bool_type
00281 operator<=(const BooleExponent& lhs, const BooleExponent& rhs) {
00282 
00283   return (lhs.compare(rhs) <= CTypes::less_or_equal_max);
00284 }
00285 
00287 inline BooleExponent::bool_type
00288 operator>=(const BooleExponent& lhs, const BooleExponent& rhs) {
00289 
00290   return (lhs.compare(rhs) >= CTypes::greater_or_equal_min);
00291 }
00292 
00293 
00295 inline BooleExponent
00296 GCD(const BooleExponent& lhs, const BooleExponent& rhs ){
00297 
00298   return lhs.GCD(rhs);
00299 }
00300 
00302 inline BooleExponent
00303 LCM(const BooleExponent& lhs, const BooleExponent& rhs ){
00304 
00305   return lhs.LCM(rhs);
00306 }
00307 
00308 
00310 inline BooleExponent::ostream_type& 
00311 operator<<(BooleExponent::ostream_type& os, const BooleExponent& rhs) {
00312   return rhs.print(os);
00313 }
00314 
00315 END_NAMESPACE_PBORI
00316 
00317 #endif // of BooleExponent_h_