23 #include <boost/intrusive/unordered_set.hpp>
58 class Monomial final :
public boost::intrusive::unordered_set_base_hook<>
62 using Arg = std::shared_ptr<const Monomial>;
63 using Content = std::vector<std::pair<Variable, std::size_t>>;
78 mutable std::size_t
mId = 0;
85 mutable std::weak_ptr<const Monomial>
mWeakPtr;
99 [](std::size_t d,
const auto& p) { return d + p.second; }
115 [](
const auto& p1,
const auto& p2){ return p1.first < p2.first; }
177 std::size_t
id()
const {
205 auto res = std::find_if(
207 [](
const auto& e){ return e.first.type() != VariableType::VT_INT; }
234 auto res = std::find_if(
236 [](
const auto& e){ return e.second % 2 == 1; }
276 const std::pair<Variable, std::size_t>&
operator[](std::size_t index)
const {
331 auto itright = m->mExponents.begin();
334 if(itright == m->mExponents.end())
339 if(itleft.first == itright->first)
341 if(itright->second > itleft.second)
349 else if(itleft.first > itright->first)
355 assert(itright->first > itleft.first);
359 return itright == m->mExponents.end();
446 bool works =
lcm(lhs, rhs)->divide(rhs, res);
490 if (&lhs == &rhs)
return true;
491 if ((lhs.
id() != 0) && (rhs.
id() != 0))
return lhs.
id() == rhs.
id();
492 if (lhs.
hash() != rhs.
hash())
return false;
493 if (lhs.
tdeg() != rhs.
tdeg())
return false;
504 if (lhs.get() == rhs.get())
return true;
505 if (lhs ==
nullptr || rhs ==
nullptr)
return false;
506 if ((lhs->id() != 0) && (rhs->id() != 0))
return lhs->id() == rhs->id();
507 if (lhs->hash() != rhs->hash())
return false;
508 if (lhs->tdeg() != rhs->tdeg())
return false;
509 return lhs->exponents() == rhs->exponents();
513 if (lhs ==
nullptr)
return false;
514 if (lhs->tdeg() != 1)
return false;
515 return lhs->begin()->first == rhs;
523 return !(lhs == rhs);
527 return !(lhs == rhs);
531 return !(rhs == lhs);
535 if (lhs.get() == rhs.get())
return false;
536 if (lhs ==
nullptr)
return true;
537 if (rhs ==
nullptr)
return false;
538 if ((lhs->id() != 0) && (rhs->id() != 0)) {
539 if (lhs->id() == rhs->id())
return false;
543 if(lhs->tdeg() < rhs->tdeg())
return true;
544 if(lhs->tdeg() > rhs->tdeg())
return false;
550 if (lhs ==
nullptr)
return true;
551 if (lhs->tdeg() > 1)
return false;
552 return lhs->begin()->first < rhs;
556 if (rhs ==
nullptr)
return false;
557 if (rhs->tdeg() > 1)
return true;
558 return lhs < rhs->begin()->first;
624 if (rhs.
exponents().empty())
return os <<
"1";
626 for (
const auto& vp: rhs) {
627 if (first) first =
false;
630 if (vp.second > 1) os <<
"^" << vp.second;
641 if (rhs)
return os << *rhs;
649 for (
const auto& e : m) {
659 if (lhs == rhs)
return false;
660 if (lhs && rhs)
return (*
this)(*lhs, *rhs);
670 if (lhs == rhs)
return true;
671 if (lhs && rhs)
return (*
this)(*lhs, *rhs);
681 struct equal_to<
carl::Monomial::Arg> {
687 struct less<
carl::Monomial::Arg> {
689 if (lhs && rhs)
return lhs < rhs;
702 return monomial.
hash();
712 struct hash<
carl::Monomial::Arg>
716 if (!monomial)
return 0;
717 return monomial->hash();
carl is the main namespace for the library.
Coeff content(const UnivariatePolynomial< Coeff > &p)
The content of a polynomial is the gcd of the coefficients of the normal part of a polynomial.
bool operator>(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
bool operator<(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
std::size_t exponent
Type of an exponent.
std::ostream & operator<<(std::ostream &os, const BasicConstraint< Poly > &c)
Prints the given constraint on the given stream.
Interval< Number > exp(const Interval< Number > &i)
Interval< Number > operator*(const Interval< Number > &lhs, const Interval< Number > &rhs)
Operator for the multiplication of two intervals.
bool operator!=(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
bool operator<=(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
bool operator==(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
bool operator>=(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
std::size_t hash_all(Args &&... args)
Hashes an arbitrary number of values.
void variables(const BasicConstraint< Pol > &c, carlVariables &vars)
Interval< Number > pow(const Interval< Number > &i, Integer exp)
A Variable represents an algebraic variable that can be used throughout carl.
The general-purpose monomials.
static CompareResult compareLexical(const Monomial::Arg &lhs, const Monomial::Arg &rhs)
Monomial()=delete
Default constructor.
static CompareResult compareGradedLexical(const Monomial::Arg &lhs, const Monomial::Arg &rhs)
std::size_t mTotalDegree
Some applications performance depends on getting the degree of monomials very fast.
const std::pair< Variable, std::size_t > & operator[](std::size_t index) const
Retrieves the given VarExpPair.
exponents_cIt end() const
Returns past-the-end iterator.
exponent tdeg() const
Gives the total degree, i.e.
std::shared_ptr< const Monomial > Arg
bool is_linear() const
Checks whether the monomial has exactly degree one.
exponent exponent_of_variable(Variable v) const
Retrieves the exponent of the given variable.
exponents_cIt begin() const
Returns constant iterator on first pair of variable and exponent.
bool isAtMostLinear() const
Checks whether the monomial has at most degree one.
static Monomial::Arg lcm(const Monomial::Arg &lhs, const Monomial::Arg &rhs)
Calculates the least common multiple of two monomial pointers.
bool is_square() const
Checks whether the monomial is a square, i.e.
exponents_it end()
Returns past-the-end iterator.
bool is_consistent() const
Checks if the monomial is consistent.
std::weak_ptr< const Monomial > mWeakPtr
Monomial(Content &&content, std::size_t totalDegree=0)
Generate a monomial from a vector of variable-exponent pairs and a total degree.
Content mExponents
A vector of variable exponent pairs (v_i^e_i) with nonzero exponents.
bool integer_valued() const
Content::const_iterator exponents_cIt
std::size_t hash() const
Returns the hash of this monomial.
std::vector< std::pair< Variable, std::size_t > > Content
void calc_total_degree()
Calculates the total degree and stores it to mTotalDegree.
bool has_no_other_variable(Variable v) const
Checks that there is no other variable than the given one.
std::size_t id() const
Return the id of this monomial.
void calc_hash()
Calculates the hash and stores it to mHash.
exponents_it begin()
Returns iterator on first pair of variable and exponent.
static CompareResult compareLexical(const Monomial::Arg &lhs, Variable rhs)
Variable single_variable() const
Retrieves the single variable of the monomial.
static std::size_t hashContent(const Monomial::Content &c)
Calculate the hash of a monomial based on its content.
static Monomial::Arg calcLcmAndDivideBy(const Monomial::Arg &lhs, const Monomial::Arg &rhs)
Returns lcm(lhs, rhs) / rhs.
static CompareResult lexicalCompare(const Monomial &lhs, const Monomial &rhs)
This method performs a lexical comparison as defined in , page 47.
std::size_t mHash
Cached hash.
Content::iterator exponents_it
std::size_t num_variables() const
Returns the number of variables that occur in the monomial.
bool divide(Variable v, Monomial::Arg &res) const
Divides the monomial by a variable v.
Monomial(const Content &content, std::size_t totalDegree=0)
Generate a monomial from a vector of variable-exponent pairs and a total degree.
bool is_constant() const
Checks whether the monomial is a constant.
static CompareResult compareGradedLexical(const Monomial::Arg &lhs, Variable rhs)
const Content & exponents() const
Monomial(Monomial &&rhs)=delete
bool has(Variable v) const
TODO: write code if binary search is preferred.
bool divisible(const Monomial::Arg &m) const
Checks if this monomial is divisible by the given monomial m.
std::size_t mId
Monomial id.
Monomial(const Monomial &rhs)=delete
Monomial::Arg sqrt() const
Calculates and returns the square root of this monomial, iff the monomial is a square as checked by i...
Monomial::Arg drop_variable(Variable v) const
For a monomial m = Prod( x_i^{e_i} ) * v^e, divides m by v^e.
bool operator()(const Monomial &lhs, const Monomial &rhs) const
bool operator()(const Monomial::Arg &lhs, const Monomial::Arg &rhs) const
bool operator()(const Monomial &lhs, const Monomial &rhs) const
bool operator()(const Monomial::Arg &lhs, const Monomial::Arg &rhs) const
bool operator()(const carl::Monomial::Arg &lhs, const carl::Monomial::Arg &rhs) const
bool operator()(const carl::Monomial::Arg &lhs, const carl::Monomial::Arg &rhs) const
std::size_t operator()(const carl::Monomial &monomial) const
size_t operator()(const carl::Monomial::Arg &monomial) const