82 throw std::invalid_argument(
83 "Monomial: exponent must be nonzero. Use the default "
84 "constructor for the constant monomial instead.");
86 m_exponents_[var] =
exp;
109 if(
exp != 0) { m_exponents_[var] =
exp; }
145 auto it = m_exponents_.find(var);
146 return it == m_exponents_.end() ?
exponent_t{0} : it->second;
160 for(
auto&& [var,
exp] : m_exponents_) { d +=
exp; }
175 bool empty() const noexcept {
return m_exponents_.empty(); }
200 for(
auto&& [var,
exp] : other.m_exponents_) {
201 m_exponents_[var] +=
exp;
238 return m_exponents_ == other.m_exponents_;
267 return m_exponents_ < other.m_exponents_;
282 if(
empty()) {
return "1"; }
283 std::stringstream ss;
285 for(
auto&& [var,
exp] : m_exponents_) {
286 if(!first) { ss <<
" * "; }
287 ss <<
"v" << var <<
"^" <<
exp;
296 static std::atomic<size_type> s_next_id{0};
297 return s_next_id.fetch_add(1);
339 std::size_t seed = 0;
340 for(
auto&& [var, exp] : m.exponents()) {
341 auto combine = [&seed](std::size_t value) {
343 seed ^= std::hash<std::size_t>{}(value) + 0x9e3779b9 +
344 (seed << 6) + (seed >> 2);
Represents a sparse multi-index exponent.
Definition monomial.hpp:33
exponent_t exponent(variable_t var) const
Returns the exponent of a single variable.
Definition monomial.hpp:144
bool operator==(const Monomial &other) const
Checks if *this and other represent the same monomial.
Definition monomial.hpp:237
Monomial(exponents_t exponents)
Constructs a monomial from a full map of exponents.
Definition monomial.hpp:107
Monomial()=default
Constructs the constant monomial.
size_type degree() const noexcept
Returns the total degree of the monomial.
Definition monomial.hpp:158
Monomial(const Monomial &other)=default
Makes a deep copy of other.
Monomial & operator=(const Monomial &other)=default
Assigns the value of other to this monomial.
std::map< variable_t, exponent_t > exponents_t
Type used to map variables to their exponents.
Definition monomial.hpp:45
Monomial & operator=(Monomial &&other) noexcept=default
Moves the value of other to this monomial.
Monomial(variable_t var, exponent_t exp=1)
Constructs a single-variable monomial.
Definition monomial.hpp:80
Monomial & operator*=(const Monomial &other)
Overwrites *this with the product of *this and other.
Definition monomial.hpp:199
Monomial(Monomial &&other) noexcept=default
Constructs a monomial by moving other.
size_type exponent_t
Type used to store the exponent of a single variable.
Definition monomial.hpp:42
std::ostream & operator<<(std::ostream &os, const Monomial &m)
Outputs a monomial to an output stream.
Definition monomial.hpp:322
bool operator<(const Monomial &other) const
Defines a strict weak ordering over monomials.
Definition monomial.hpp:266
bool empty() const noexcept
Checks if *this is the constant monomial.
Definition monomial.hpp:175
static variable_t make_variable()
Definition monomial.hpp:295
const exponents_t & exponents() const noexcept
Returns the exponents of the monomial.
Definition monomial.hpp:133
size_type variable_t
Opaque type used to identify an expansion variable.
Definition monomial.hpp:39
Monomial operator*(const Monomial &other) const
Returns the product of *this and other.
Definition monomial.hpp:219
std::string print() const
Creates a string representation of *this.
Definition monomial.hpp:281
bool operator!=(const Monomial &other) const
Checks if *this and other represent different monomials.
Definition monomial.hpp:250
std::size_t size_type
Type used for indexing, offsets, and total degree.
Definition monomial.hpp:36
The primary namespace for the sigma library.
Definition affine.hpp:12
Affine< T > exp(const Affine< T > &a)
Calculate the exponential of an affine form.
Definition exponents.ipp:31
std::size_t operator()(const sigma::Monomial &m) const noexcept
Does the hashing.
Definition monomial.hpp:338