PolyBoRi
BooleMonomial.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //*****************************************************************************
151 //*****************************************************************************
152 
153 #ifndef BooleMonomial_h_
154 #define BooleMonomial_h_
155 
156 // include basic definitions
157 #include "pbori_defs.h"
158 
159 // get definition of BoolePolynomial and BooleVariable
160 #include "BoolePolynomial.h"
161 #include "BooleVariable.h"
162 // get standard map functionality
163 #include <map>
164 
165 // get variable iterator
166 #include "CVariableIter.h"
167 
168 // get variable iterator
169 #include "PBoRiError.h"
170 
172 
173 class BooleVariable;
174 class BooleExponent;
175 template <class DDType, class MonomType> class CDDOperations;
176 
186 
187  public:
188  template <class, class> friend class CDDOperations;
189  friend class COrderBase;
190  template <class, class> friend class CTermGeneratorBase;
191 
192  //-------------------------------------------------------------------------
193  // types definitions
194  //-------------------------------------------------------------------------
195 
197 
202  typedef CTypes::bool_type bool_type;
207 
209  typedef BooleMonomial self;
210 
213 
216 
219 
222 
225 
228 
231 
234 
236  // typedef generate_index_map<self>::type idx_map_type;
237 
238  typedef std::map<self, idx_type, symmetric_composition<
239  std::less<poly_type::navigator>,
241 
244 
247  m_poly( BooleEnv::one() ) { }
248 
250  BooleMonomial(const self& rhs):
251  m_poly(rhs.m_poly) {}
252 
254  BooleMonomial(const var_type& rhs); // not inlined to avoid dependency loop
255  // (both depend on poly_type)
256 
258  BooleMonomial(const exp_type& rhs, const ring_type& ring):
259  m_poly(rhs, ring) { }
260 
262  BooleMonomial(const ring_type& ring):
263  m_poly(ring.one()) {}
264 
267 
269  operator const BoolePolynomial&() const { return m_poly; }
270 
272  exp_type exp() const;
273 
274 
276  const_iterator begin() const { return m_poly.firstBegin(); }
277 
279  const_iterator end() const { return m_poly.firstEnd(); }
280 
283  return variable_iterator(begin(), ring());
284  }
285 
288  return variable_iterator(end(), ring());
289  }
290 
292  size_type deg() const {
294  #if 0
295  return m_poly.nNodes();
296  #else
297  return std::distance(m_poly.firstBegin(),m_poly.firstEnd());
298  #endif
299  }
300 
302  size_type size() const { return deg(); }
303 
305  set_type divisors() const { return m_poly.lmDivisors(); }
306 
308  set_type multiples(const self&) const;
309 
312  return stable_first_hash_range(m_poly.navigation());
313  }
314 
316  hash_type hash() const { return m_poly.hash(); }
317 
319  self& changeAssign(idx_type);
320 
322  self change(idx_type) const;
323 
324 
326 
327  self& operator*=(const self&);
328  self& operator/=(const self&);
329  self& operator*=(const var_type&);
330  self& operator/=(const var_type&);
332 
334 
335  bool_type operator==(const self& rhs) const { return m_poly == rhs.m_poly; }
336  bool_type operator!=(const self& rhs) const { return m_poly != rhs.m_poly; }
337  bool_type operator==(constant_type rhs) const { return m_poly == rhs; }
338  bool_type operator!=(constant_type rhs) const { return m_poly != rhs; }
339  bool_type isOne() const { return m_poly.isOne(); }
340  bool_type isConstant() const { return m_poly.isConstant(); }
342 
344  bool_type reducibleBy(const self& rhs) const {
345  return m_poly.reducibleBy(rhs); }
346  bool_type reducibleBy(const var_type& rhs) const;
347 
349  comp_type compare(const self&) const;
350 
352  size_type LCMDeg(const self&) const;
353 
355  self& LCMAssign(const self&);
356 
358  self LCM(const self&) const;
359 
361  self& GCDAssign(const self&);
362 
364  self GCD(const self&) const;
365 
367  const dd_type& diagram() const { return m_poly.diagram(); }
368 
370  set_type set() const { return m_poly.set(); }
371 
373  self& popFirst() {
374  assert(!m_poly.isConstant());
375  return *this = set_type( dd_type(m_poly.diagram().manager(),
376  m_poly.navigation().thenBranch()) );
377  }
378 
380  var_type firstVariable() const;
381 
384  assert(!m_poly.isConstant());
385  return *begin();
386  }
387 
389  ring_type ring() const { return m_poly.ring(); }
390 
391 protected:
393  dd_type& internalDiagram() { return m_poly.internalDiagram(); }
394 
396  // BooleMonomial(const dd_type& rhs): m_poly(rhs) {}
398  BooleMonomial(const set_type& rhs): m_poly(rhs.diagram()) {
399  assert(!m_poly.isZero());
400  }
401 
402 private:
403  BoolePolynomial m_poly;
404 };
405 
407 inline BooleMonomial
408 operator*(const BooleMonomial& lhs, const BooleMonomial& rhs) {
409  return BooleMonomial(lhs) *= rhs;
410 }
412 inline BooleMonomial
413 operator*(const BooleMonomial& lhs, const BooleVariable& rhs) {
414  return BooleMonomial(lhs) *= rhs;
415 }
417 inline BoolePolynomial
419  return BoolePolynomial(lhs) *= rhs;
420 }
421 
423 inline BoolePolynomial
425  return rhs * lhs;
426 }
427 
429 inline BooleMonomial
430 operator/(const BooleMonomial& lhs, const BooleMonomial& rhs) {
431  return BooleMonomial(lhs) /= rhs;
432 }
433 
435 inline BooleMonomial
436 operator/(const BooleMonomial& lhs, const BooleVariable& rhs) {
437  return lhs / BooleMonomial(rhs);
438 }
439 
441 inline BooleMonomial::bool_type
442 operator<(const BooleMonomial& lhs, const BooleMonomial& rhs) {
443 
444  return (lhs.compare(rhs) == CTypes::less_than);
445 }
446 
448 inline BooleMonomial::bool_type
449 operator>(const BooleMonomial& lhs, const BooleMonomial& rhs) {
450 
451  return (lhs.compare(rhs) == CTypes::greater_than);
452 }
453 
455 inline BooleMonomial::bool_type
456 operator<=(const BooleMonomial& lhs, const BooleMonomial& rhs) {
457 
458  return (lhs.compare(rhs) <= CTypes::less_or_equal_max);
459 }
460 
462 inline BooleMonomial::bool_type
463 operator>=(const BooleMonomial& lhs, const BooleMonomial& rhs) {
464 
465  return (lhs.compare(rhs) >= CTypes::greater_or_equal_min);
466 }
467 
468 
470 inline BooleMonomial
471 GCD(const BooleMonomial& lhs, const BooleMonomial& rhs ){
472 
473  return lhs.GCD(rhs);
474 }
475 
477 inline BooleMonomial
478 LCM(const BooleMonomial& lhs, const BooleMonomial& rhs ){
479 
480  return lhs.LCM(rhs);
481 }
482 
485 BooleMonomial::bool_type
487 
488 
490 inline BoolePolynomial
491 operator*(const BooleVariable& lhs, const BooleConstant& rhs){
492 
493  return BooleMonomial(lhs) * rhs;
494 }
495 
497 inline BoolePolynomial
498 operator*(const BooleConstant& lhs, const BooleVariable& rhs){
499 
500  return rhs * lhs;
501 }
502 
504 inline BoolePolynomial
506  const BoolePolynomial& rhs){
507 
508  return BoolePolynomial(rhs) *= BooleMonomial(lhs);
509 }
510 
512 inline BooleMonomial
514  const BooleMonomial& rhs){
515 
516  return BooleMonomial(lhs) * rhs;
517 }
518 
520 inline BoolePolynomial&
522  const BooleVariable& rhs){
523 
524  return lhs *= BooleMonomial(rhs);
525 }
526 
528 inline BooleMonomial
530  const BooleVariable& rhs){
531 
532  return BooleMonomial(lhs) *= BooleMonomial(rhs);
533 }
534 
536 inline BoolePolynomial
538  const BooleVariable& rhs){
539 
540  return BoolePolynomial(lhs) *= BooleMonomial(rhs);
541 }
542 
544 inline BoolePolynomial&
546 
547  return lhs /= BooleMonomial(rhs);
548 }
549 
551 inline BoolePolynomial
553  const BooleVariable& rhs){
554 
555  return lhs / BooleMonomial(rhs);
556 }
557 
558 
560 inline BoolePolynomial
562  const BooleVariable& rhs){
563 
564  return lhs % BooleMonomial(rhs);
565 }
566 
568 inline BoolePolynomial&
570  const BooleVariable& rhs){
571 
572  return lhs %= BooleMonomial(rhs);
573 }
574 
576 
577 
578 #endif // of BooleMonomial_h_