BooleMonomial.h
Go to the documentation of this file.
// -*- c++ -*-
//*****************************************************************************
//*****************************************************************************
#ifndef polybori_BooleMonomial_h_
#define polybori_BooleMonomial_h_
// include basic definitions
#include <polybori/pbori_defs.h>
// get definition of BoolePolynomial and BooleVariable
#include <polybori/BoolePolynomial.h>
#include <polybori/BooleVariable.h>
// get standard map functionality
#include <map>
// get variable iterator
#include <polybori/iterators/CVariableIter.h>
// get variable iterator
#include <polybori/except/PBoRiError.h>
BEGIN_NAMESPACE_PBORI
class BooleVariable;
class BooleExponent;
template <class DDType, class MonomType> class CDDOperations;
class BooleMonomial:
public CAuxTypes {
typedef BooleMonomial self;
public:
template <class, class> friend class CDDOperations;
friend class COrderingBase;
template <class> friend class CTermGeneratorBase;
template <class, class> friend class CTermGeneratorBase__;
typedef BoolePolynomial poly_type;
typedef poly_type::dd_type dd_type;
typedef poly_type::integer_type integer_type;
typedef poly_type::ostream_type ostream_type;
typedef poly_type::var_type var_type;
typedef poly_type::constant_type constant_type;
typedef poly_type::set_type set_type;
typedef poly_type::exp_type exp_type;
typedef poly_type::ring_type ring_type;
typedef poly_type::first_iterator const_iterator;
typedef CVariableIter<const_iterator, var_type> variable_iterator;
// typedef generate_index_map<self>::type idx_map_type;
typedef std::map<self, idx_type, symmetric_composition<
std::less<poly_type::navigator>,
navigates<poly_type> > > idx_map_type;
typedef dd_type::easy_equality_property easy_equality_property;
BooleMonomial(const self& rhs):
m_poly(rhs.m_poly) {}
BooleMonomial(const var_type& rhs); // not inlined to avoid dependency loop
// (both depend on poly_type)
BooleMonomial(const exp_type& rhs, const ring_type& ring):
m_poly(rhs, ring) { }
BooleMonomial(const ring_type& ring):
m_poly(ring.one()) {}
~BooleMonomial() {}
operator const BoolePolynomial&() const { return m_poly; }
exp_type exp() const;
const_iterator begin() const { return m_poly.firstBegin(); }
const_iterator end() const { return m_poly.firstEnd(); }
variable_iterator variableBegin() const {
return variable_iterator(begin(), ring());
}
variable_iterator variableEnd() const {
return variable_iterator(end(), ring());
}
deg_type deg() const {
return std::distance(m_poly.firstBegin(),m_poly.firstEnd());
}
size_type size() const { return (size_type)deg(); } // always nonnegative
set_type divisors() const { return m_poly.leadDivisors(); }
set_type multiples(const self&) const;
hash_type stableHash() const {
return stable_first_hash_range(m_poly.navigation());
}
hash_type hash() const { return m_poly.hash(); }
self change(idx_type) const;
self& operator*=(const self&);
self& operator/=(const self&);
self& operator*=(const var_type&);
self& operator/=(const var_type&);
bool_type operator==(const self& rhs) const { return m_poly == rhs.m_poly; }
bool_type operator!=(const self& rhs) const { return m_poly != rhs.m_poly; }
bool_type operator==(constant_type rhs) const { return m_poly == rhs; }
bool_type operator!=(constant_type rhs) const { return m_poly != rhs; }
bool_type isOne() const { return m_poly.isOne(); }
bool_type isConstant() const { return m_poly.isConstant(); }
bool_type reducibleBy(const self& rhs) const {
return m_poly.firstReducibleBy(rhs); }
bool_type reducibleBy(const var_type& rhs) const;
comp_type compare(const self&) const;
deg_type LCMDeg(const self&) const;
self& LCMAssign(const self&);
self LCM(const self&) const;
self& GCDAssign(const self&);
self GCD(const self&) const;
const dd_type& diagram() const { return m_poly.diagram(); }
set_type set() const { return m_poly.set(); }
self& popFirst() {
PBORI_ASSERT(!m_poly.isConstant());
return *this = set_type( dd_type(m_poly.ring(),
m_poly.navigation().thenBranch()) );
}
var_type firstVariable() const;
idx_type firstIndex() const {
return *m_poly.navigation();
}
const ring_type& ring() const { return m_poly.ring(); }
protected:
dd_type& internalDiagram() { return m_poly.internalDiagram(); }
BooleMonomial(const set_type& rhs): m_poly(rhs.diagram()) {
PBORI_ASSERT(!m_poly.isZero());
}
private:
BoolePolynomial m_poly;
};
inline BooleMonomial
operator*(const BooleMonomial& lhs, const BooleMonomial& rhs) {
return BooleMonomial(lhs) *= rhs;
}
inline BooleMonomial
operator*(const BooleMonomial& lhs, const BooleVariable& rhs) {
return BooleMonomial(lhs) *= rhs;
}
inline BoolePolynomial
operator*(const BooleMonomial& lhs, BooleConstant rhs) {
return BoolePolynomial(lhs) *= rhs;
}
inline BoolePolynomial
operator*(BooleConstant lhs, const BooleMonomial& rhs) {
return rhs * lhs;
}
inline BooleMonomial
operator/(const BooleMonomial& lhs, const BooleMonomial& rhs) {
return BooleMonomial(lhs) /= rhs;
}
inline BooleMonomial
operator/(const BooleMonomial& lhs, const BooleVariable& rhs) {
return lhs / BooleMonomial(rhs);
}
inline BooleMonomial::bool_type
operator<(const BooleMonomial& lhs, const BooleMonomial& rhs) {
return (lhs.compare(rhs) == CTypes::less_than);
}
inline BooleMonomial::bool_type
operator>(const BooleMonomial& lhs, const BooleMonomial& rhs) {
return (lhs.compare(rhs) == CTypes::greater_than);
}
inline BooleMonomial::bool_type
operator<=(const BooleMonomial& lhs, const BooleMonomial& rhs) {
return (lhs.compare(rhs) <= CTypes::less_or_equal_max);
}
inline BooleMonomial::bool_type
operator>=(const BooleMonomial& lhs, const BooleMonomial& rhs) {
return (lhs.compare(rhs) >= CTypes::greater_or_equal_min);
}
inline BooleMonomial
GCD(const BooleMonomial& lhs, const BooleMonomial& rhs ){
return lhs.GCD(rhs);
}
inline BooleMonomial
LCM(const BooleMonomial& lhs, const BooleMonomial& rhs ){
return lhs.LCM(rhs);
}
// Anyone need this?
// BooleMonomial::bool_type
// greater_variable(BooleMonomial::idx_type lhs, BooleMonomial::idx_type rhs);
inline BoolePolynomial
operator*(const BooleVariable& lhs, const BooleConstant& rhs){
return BooleMonomial(lhs) * rhs;
}
inline BoolePolynomial
operator*(const BooleConstant& lhs, const BooleVariable& rhs){
return rhs * lhs;
}
inline BoolePolynomial
operator*(const BooleVariable& lhs,
const BoolePolynomial& rhs){
return BoolePolynomial(rhs) *= BooleMonomial(lhs);
}
inline BooleMonomial
operator*(const BooleVariable& lhs,
const BooleMonomial& rhs){
return BooleMonomial(lhs) * rhs;
}
inline BoolePolynomial&
operator*=(BoolePolynomial& lhs,
const BooleVariable& rhs){
return lhs *= BooleMonomial(rhs);
}
inline BooleMonomial
operator*(const BooleVariable& lhs,
const BooleVariable& rhs){
return BooleMonomial(lhs) *= BooleMonomial(rhs);
}
inline BoolePolynomial
operator*(const BoolePolynomial& lhs,
const BooleVariable& rhs){
return BoolePolynomial(lhs) *= BooleMonomial(rhs);
}
inline BoolePolynomial
operator/(const BoolePolynomial& lhs,
const BooleVariable& rhs){
return lhs / BooleMonomial(rhs);
}
inline BoolePolynomial
operator%(const BoolePolynomial& lhs,
const BooleVariable& rhs){
return lhs % BooleMonomial(rhs);
}
END_NAMESPACE_PBORI
#endif // of polybori_BooleMonomial_h_