PolyBoRi
BooleMonomial.h
Go to the documentation of this file.
00001 // -*- c++ -*-
00002 //*****************************************************************************
00016 //*****************************************************************************
00017 
00018 #ifndef polybori_BooleMonomial_h_
00019 #define polybori_BooleMonomial_h_
00020 
00021 // include basic definitions
00022 #include <polybori/pbori_defs.h>
00023 
00024 // get definition of BoolePolynomial and BooleVariable
00025 #include <polybori/BoolePolynomial.h>
00026 #include <polybori/BooleVariable.h>
00027 // get standard map functionality
00028 #include <map>
00029 
00030 // get variable iterator
00031 #include <polybori/iterators/CVariableIter.h>
00032 
00033 // get variable iterator
00034 #include <polybori/except/PBoRiError.h>
00035 
00036 BEGIN_NAMESPACE_PBORI
00037 
00038 class BooleVariable;
00039 class BooleExponent;
00040 template <class DDType, class MonomType> class CDDOperations;
00041 
00050 class BooleMonomial:
00051   public CAuxTypes {
00052 
00054   typedef BooleMonomial self;
00055 
00056 public:
00057   template <class, class> friend class CDDOperations;
00058   friend class COrderingBase;
00059   template <class> friend class CTermGeneratorBase;
00060   template <class, class> friend class CTermGeneratorBase__;
00061 
00063   typedef BoolePolynomial poly_type;
00064 
00066 
00067   typedef poly_type::dd_type dd_type;
00068   typedef poly_type::integer_type integer_type;
00069   typedef poly_type::ostream_type ostream_type;
00071 
00073   typedef poly_type::var_type var_type;
00074 
00076   typedef poly_type::constant_type constant_type;
00077 
00079   typedef poly_type::set_type set_type;
00080 
00082   typedef poly_type::exp_type exp_type;
00083 
00085   typedef poly_type::ring_type ring_type;
00086 
00088   typedef poly_type::first_iterator const_iterator;
00089 
00091   typedef CVariableIter<const_iterator, var_type> variable_iterator;
00092 
00094   //  typedef generate_index_map<self>::type idx_map_type;
00095 
00096   typedef std::map<self, idx_type, symmetric_composition<
00097     std::less<poly_type::navigator>, 
00098     navigates<poly_type> > > idx_map_type;
00099 
00101   typedef dd_type::easy_equality_property easy_equality_property;
00102 
00104   BooleMonomial(const self& rhs):  
00105     m_poly(rhs.m_poly) {}
00106 
00108   BooleMonomial(const var_type& rhs);  // not inlined to avoid dependency loop
00109                                        // (both depend on poly_type)
00110 
00112   BooleMonomial(const exp_type& rhs, const ring_type& ring): 
00113     m_poly(rhs, ring) { }
00114 
00116   BooleMonomial(const ring_type& ring): 
00117     m_poly(ring.one()) {}
00118 
00120   ~BooleMonomial() {}
00121 
00123   operator const BoolePolynomial&() const { return m_poly; }
00124 
00126   exp_type exp() const;
00127 
00128 
00130   const_iterator begin() const { return m_poly.firstBegin(); }
00131 
00133   const_iterator end() const { return m_poly.firstEnd(); }
00134 
00136   variable_iterator variableBegin() const { 
00137     return variable_iterator(begin(), ring()); 
00138   }
00139 
00141   variable_iterator variableEnd() const { 
00142     return variable_iterator(end(), ring()); 
00143   }
00144 
00146   deg_type deg() const {
00147     return std::distance(m_poly.firstBegin(),m_poly.firstEnd());
00148   }
00149 
00151   size_type size() const { return (size_type)deg(); }  // always nonnegative
00152 
00154   set_type divisors() const { return m_poly.leadDivisors(); }
00155 
00157   set_type multiples(const self&) const; 
00158 
00160   hash_type stableHash() const {
00161     return stable_first_hash_range(m_poly.navigation());
00162   }
00163 
00165   hash_type hash() const {  return m_poly.hash(); }
00166 
00168   self change(idx_type) const;
00169 
00170 
00172 
00173   self& operator*=(const self&);
00174   self& operator/=(const self&);
00175   self& operator*=(const var_type&);
00176   self& operator/=(const var_type&);
00178 
00180 
00181   bool_type operator==(const self& rhs) const { return m_poly == rhs.m_poly; }
00182   bool_type operator!=(const self& rhs) const { return m_poly != rhs.m_poly; }
00183   bool_type operator==(constant_type rhs) const { return m_poly == rhs; }
00184   bool_type operator!=(constant_type rhs) const { return m_poly != rhs; }
00185   bool_type isOne() const { return m_poly.isOne(); }
00186   bool_type isConstant() const { return m_poly.isConstant(); }
00188 
00190   bool_type reducibleBy(const self& rhs) const { 
00191     return m_poly.firstReducibleBy(rhs); }
00192   bool_type reducibleBy(const var_type& rhs) const;
00193 
00195   comp_type compare(const self&) const;
00196 
00198   deg_type LCMDeg(const self&) const;
00199 
00201   self& LCMAssign(const self&);
00202 
00204   self LCM(const self&) const;
00205 
00207   self& GCDAssign(const self&);
00208 
00210   self GCD(const self&) const;
00211  
00213   const dd_type& diagram() const { return m_poly.diagram(); }
00214 
00216   set_type set() const { return m_poly.set(); }
00217 
00219   self& popFirst() { 
00220     PBORI_ASSERT(!m_poly.isConstant());
00221     return *this = set_type( dd_type(m_poly.ring(),
00222                                      m_poly.navigation().thenBranch()) ); 
00223   }
00224 
00226   var_type firstVariable() const;
00227 
00229   idx_type firstIndex() const {
00230     PBORI_ASSERT(!m_poly.isConstant());
00231     return *begin();
00232   }
00233 
00235   const ring_type& ring() const { return m_poly.ring(); } 
00236 
00237 protected:
00239   dd_type& internalDiagram() { return m_poly.internalDiagram(); }
00240 
00242   BooleMonomial(const set_type& rhs): m_poly(rhs.diagram()) {
00243     PBORI_ASSERT(!m_poly.isZero());
00244   }
00245 
00246 private:
00247   BoolePolynomial m_poly;
00248 };
00249 
00251 inline BooleMonomial
00252 operator*(const BooleMonomial& lhs, const BooleMonomial& rhs) {
00253   return BooleMonomial(lhs) *= rhs;
00254 }
00256 inline BooleMonomial
00257 operator*(const BooleMonomial& lhs, const BooleVariable& rhs) {
00258   return BooleMonomial(lhs) *= rhs;
00259 }
00261 inline BoolePolynomial
00262 operator*(const BooleMonomial& lhs, BooleConstant rhs) {
00263   return BoolePolynomial(lhs) *= rhs;
00264 }
00265 
00267 inline BoolePolynomial
00268 operator*(BooleConstant lhs, const BooleMonomial& rhs) {
00269   return rhs * lhs;
00270 }
00271 
00273 inline BooleMonomial
00274 operator/(const BooleMonomial& lhs, const BooleMonomial& rhs) {
00275   return BooleMonomial(lhs) /= rhs;
00276 }
00277 
00279 inline BooleMonomial
00280 operator/(const BooleMonomial& lhs, const BooleVariable& rhs) {
00281   return  lhs / BooleMonomial(rhs);
00282 }
00283 
00285 inline BooleMonomial::bool_type
00286 operator<(const BooleMonomial& lhs, const BooleMonomial& rhs) {
00287 
00288   return (lhs.compare(rhs) == CTypes::less_than);
00289 }
00290 
00292 inline BooleMonomial::bool_type
00293 operator>(const BooleMonomial& lhs, const BooleMonomial& rhs) {
00294 
00295   return (lhs.compare(rhs) == CTypes::greater_than);
00296 }
00297 
00299 inline BooleMonomial::bool_type
00300 operator<=(const BooleMonomial& lhs, const BooleMonomial& rhs) {
00301 
00302   return (lhs.compare(rhs) <= CTypes::less_or_equal_max);
00303 }
00304 
00306 inline BooleMonomial::bool_type
00307 operator>=(const BooleMonomial& lhs, const BooleMonomial& rhs) {
00308 
00309   return (lhs.compare(rhs) >= CTypes::greater_or_equal_min);
00310 }
00311 
00312 
00314 inline BooleMonomial
00315 GCD(const BooleMonomial& lhs, const BooleMonomial& rhs ){
00316 
00317   return lhs.GCD(rhs);
00318 }
00319 
00321 inline BooleMonomial
00322 LCM(const BooleMonomial& lhs, const BooleMonomial& rhs ){
00323 
00324   return lhs.LCM(rhs);
00325 }
00326 
00327 // Anyone need this?
00330 // BooleMonomial::bool_type
00331 // greater_variable(BooleMonomial::idx_type lhs, BooleMonomial::idx_type rhs);
00332 
00333 
00335 inline BoolePolynomial
00336 operator*(const BooleVariable& lhs, const BooleConstant& rhs){
00337 
00338   return BooleMonomial(lhs) * rhs;
00339 }
00340 
00342 inline BoolePolynomial
00343 operator*(const BooleConstant& lhs, const BooleVariable& rhs){
00344 
00345   return rhs * lhs;
00346 }
00347 
00349 inline BoolePolynomial
00350 operator*(const BooleVariable& lhs, 
00351           const BoolePolynomial& rhs){
00352 
00353   return BoolePolynomial(rhs) *= BooleMonomial(lhs);
00354 }
00355 
00357 inline BooleMonomial
00358 operator*(const BooleVariable& lhs, 
00359           const BooleMonomial& rhs){
00360 
00361   return BooleMonomial(lhs) * rhs;
00362 }
00363 
00365 inline BoolePolynomial&
00366 operator*=(BoolePolynomial& lhs, 
00367            const BooleVariable& rhs){
00368 
00369   return lhs *= BooleMonomial(rhs);
00370 }
00371 
00373 inline BooleMonomial
00374 operator*(const BooleVariable& lhs, 
00375           const BooleVariable& rhs){
00376 
00377   return BooleMonomial(lhs) *= BooleMonomial(rhs);
00378 }
00379 
00381 inline BoolePolynomial
00382 operator*(const BoolePolynomial& lhs, 
00383           const BooleVariable& rhs){
00384 
00385   return BoolePolynomial(lhs) *= BooleMonomial(rhs);
00386 }
00387 
00389 inline BoolePolynomial
00390 operator/(const BoolePolynomial& lhs, 
00391           const BooleVariable& rhs){
00392 
00393   return lhs / BooleMonomial(rhs);
00394 }
00395 
00396 
00398 inline BoolePolynomial
00399 operator%(const BoolePolynomial& lhs, 
00400           const BooleVariable& rhs){
00401 
00402   return lhs % BooleMonomial(rhs);
00403 }
00404 
00405 
00406 END_NAMESPACE_PBORI
00407 
00408 
00409 #endif // of polybori_BooleMonomial_h_