PolyBoRi
BooleExponent.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //*****************************************************************************
70 //*****************************************************************************
71 
72 #ifndef BooleExponent_h_
73 #define BooleExponent_h_
74 
75 // include basic definitions
76 #include "pbori_defs.h"
77 
78 // get definition of BoolePolynomial, BooleMonomial, and BooleVariable
79 #include "BooleMonomial.h"
80 #include "BooleVariable.h"
81 
83 
90 
91  public:
92 
93  //-------------------------------------------------------------------------
94  // types definitions
95  //-------------------------------------------------------------------------
96 
98 
108 
110  typedef std::vector<idx_type> data_type;
111 
113  typedef data_type::value_type value_type;
114 
116 
117  typedef data_type::iterator iterator;
118  typedef data_type::const_iterator const_iterator;
119  typedef data_type::reverse_iterator reverse_iterator;
120  typedef data_type::const_reverse_iterator const_reverse_iterator;
122 
124  typedef BooleExponent self;
125 
128 
131 
134 
137 
140 
143 
145  BooleExponent();
146 
148  BooleExponent(const self&);
149 
150  explicit BooleExponent(bool);
151 
153  self& get(const monom_type&);
154 
155 // /// Construct from Boolean constant
156 // BooleExponent(bool_type);
157 
159  ~BooleExponent();
160 
162  const_iterator begin() const { return m_data.begin(); }
163 
165  const_iterator end() const { return m_data.end(); }
166 
168  const_reverse_iterator rbegin() const { return m_data.rbegin(); }
169 
171  const_reverse_iterator rend() const { return m_data.rend(); }
172 
174  size_type size() const { return m_data.size(); }
175 
177  void reserve(size_type nsize) { m_data.reserve(nsize); }
178 
180  void resize(size_type nsize) { m_data.resize(nsize); }
181 
183  size_type deg() const { return size(); }
184 
186  set_type divisors() const;
187 
189  set_type multiples(const self&) const;
190 
193  return stable_term_hash(begin(), end());
194  }
195 
197  hash_type hash() const { return stableHash(); }
198 
200  self& changeAssign(idx_type);
201 
203  self change(idx_type) const;
204 
206  self& insert(idx_type);
207 
209  self& push_back(idx_type idx);
210 
212  self& remove(idx_type);
213 
215  self insertConst(idx_type) const;
216 
218  self removeConst(idx_type) const;
219 
221  self divide(const self&) const;
222  self divide(const idx_type& rhs) const {
223  return (reducibleBy(rhs)? removeConst(rhs) : self() ); }
224 
225  self divide(const var_type& rhs) const { return divide(rhs.index()); }
226  self divide(const monom_type&) const;
227 
229  self multiply(const self&) const;
230 
231  self multiply(const idx_type& rhs) const { return insertConst(rhs); }
232  self multiply(const var_type& rhs) const { return multiply(rhs.index()); }
233  self multiply(const monom_type&) const;
234  self multiplyFirst(const set_type&) const;
235 
236 
237 // /// @name Arithmetical operations
238 // //@{
239 // self& operator*=(const self&);
240 // self& operator/=(const self&);
241 // self& operator*=(const var_type&);
242 // self& operator/=(const var_type&);
243 // //@}
244 
246 
247  bool_type operator==(const self& rhs) const { return m_data == rhs.m_data; }
248  bool_type operator!=(const self& rhs) const { return m_data != rhs.m_data; }
250 
252  self& operator=(const self& rhs) { m_data = rhs.m_data; return *this; }
253  self& operator=(const monom_type& rhs) {
254  m_data.resize(rhs.size());
255  std::copy(rhs.begin(), rhs.end(), internalBegin());
256  return *this;
257  }
258 
260  bool_type reducibleBy(const self& rhs) const;
261  bool_type reducibleBy(const monom_type& rhs) const;
262  bool_type reducibleBy(const idx_type& rhs) const;
263  bool_type reducibleBy(const var_type& rhs) const {
264  return reducibleBy(rhs.index()); }
265 
266 
267 // /// Test for reducibility wrt. to a given variable
268 // bool_type reducibleBy(const var_type& rhs) const;
269 
271  comp_type compare(const self&) const;
272 
274  size_type LCMDeg(const self&) const;
275 
278 
280  self LCM(const self&) const;
281 
283  //self& GCDAssign(const self&);
284 
286  self GCD(const self&) const;
287 
289  self& popFirst() {
290  assert(!m_data.empty());
291  m_data.erase(m_data.begin());
292  return *this;
293  }
294 
296  ostream_type& print(ostream_type&) const;
297 
298 protected:
300  iterator internalBegin() { return m_data.begin(); }
301 
303  iterator internalEnd() { return m_data.end(); }
304 
306  reverse_iterator rInternalBegin() { return m_data.rbegin(); }
307 
309  reverse_iterator rInternalEnd() { return m_data.rend(); }
310 
313 };
314 
315 
317 template <class RHSType>
318 inline BooleExponent
319 operator+(const BooleExponent& lhs, const RHSType& rhs) {
320  return lhs.multiply(rhs);
321 }
322 
324 template <class RHSType>
325 inline BooleExponent
326 operator-(const BooleExponent& lhs, const RHSType& rhs) {
327  return lhs.divide(rhs);
328 }
329 
330 
332 inline BooleExponent::bool_type
333 operator<(const BooleExponent& lhs, const BooleExponent& rhs) {
334 
335  return (lhs.compare(rhs) == CTypes::less_than);
336 }
337 
339 inline BooleExponent::bool_type
340 operator>(const BooleExponent& lhs, const BooleExponent& rhs) {
341 
342  return (lhs.compare(rhs) == CTypes::greater_than);
343 }
344 
346 inline BooleExponent::bool_type
347 operator<=(const BooleExponent& lhs, const BooleExponent& rhs) {
348 
349  return (lhs.compare(rhs) <= CTypes::less_or_equal_max);
350 }
351 
353 inline BooleExponent::bool_type
354 operator>=(const BooleExponent& lhs, const BooleExponent& rhs) {
355 
356  return (lhs.compare(rhs) >= CTypes::greater_or_equal_min);
357 }
358 
359 
361 inline BooleExponent
362 GCD(const BooleExponent& lhs, const BooleExponent& rhs ){
363 
364  return lhs.GCD(rhs);
365 }
366 
368 inline BooleExponent
369 LCM(const BooleExponent& lhs, const BooleExponent& rhs ){
370 
371  return lhs.LCM(rhs);
372 }
373 
374 
376 inline BooleExponent::ostream_type&
378  return rhs.print(os);
379 }
380 
382 
383 #endif // of BooleExponent_h_