3 #include "impl/Details.ipp"
5 #include <unordered_map>
27 template <
class exp_t>
29 typedef typename exp_t::deg_t deg_t;
60 template <
class _scl,
class _exp,
template<
class...>
class _cnt,
bool _ord,
class ... _arg>
63 typedef typename implementation_details::container_wrapper<_scl, _exp, _cnt, _ord, _arg...> data_t;
67 typedef typename _exp::deg_t
deg_t;
115 Iterator(
typename data_t::iterator);
124 void add(
const std::pair<
const std::pair<deg_t, exp_t>,
scl_t>& kvp);
133 void multiply_add(
const std::pair<
const std::pair<deg_t, exp_t>,
scl_t >& kvp1,
const std::pair<
const std::pair <deg_t, exp_t>,
scl_t >& kvp2);
135 void add(
const std::pair<deg_t, exp_t> key,
scl_t value);
147 template <
typename container_t>
151 typedef typename container_t::scl_t
scl_t;
152 typedef typename container_t::exp_t
exp_t;
153 typedef typename container_t::deg_t
deg_t;
227 template <
class T =
int>
231 const std::string* variable_names;
233 void print(
scl_t,
const exp_t&, std::ostream&,
const fun&)
const;
235 void print(std::ostream& os,
const fun&)
const;
245 template <
class container_t>
252 template <
class _scl,
class _exp,
bool _ord = 1>
256 #include "impl/Polynomials.ipp"
Contains general operations on vectors: hashing, computing degrees.
The base of all monomial containers.
Definition: Polynomials.hpp:28
BaseContainer(const deg_t *dimensions=nullptr)
Constructor given pointer to dimensions of the variables.
const deg_t * dimensions
The pointer to the dimensions of the variables.
Definition: Polynomials.hpp:41
deg_t compute_degree(const exp_t &exponent) const
Computes degree of given exponent.
Constant iterator traversing the monomials of a polynomial.
Definition: Polynomials.hpp:91
scl_t coeff() const
The coefficient of the monomial.
const exp_t & exponent() const
The exponent of the monomial.
deg_t degree() const
The degree of the monomial.
Non const iterator traversing the monomials of a polynomial.
Definition: Polynomials.hpp:111
scl_t & coeff()
Reference to the coefficient of the monomial.
The default ordered/unordered monomial container.
Definition: Polynomials.hpp:61
ConstIterator highest_term() const
ConstIterator to the highest term monomial.
void insert(const exp_t &exp, scl_t coeff)
Inserts monomial in polynomial.
Iterator begin()
Iterator to the first monomial.
void subtract(const std::pair< const std::pair< deg_t, exp_t >, scl_t > &kvp)
Subtracts given monomial from polynomial.
size_t number_of_monomials() const
Returns number of monomials in the polynomial.
_exp::deg_t deg_t
The degree type eg size_t.
Definition: Polynomials.hpp:67
ConstIterator end() const
ConstIterator to just after the final monomial.
void add(const std::pair< const std::pair< deg_t, exp_t >, scl_t > &kvp)
Adds given monomial to polynomial.
_scl scl_t
The scalar (coefficient) type eg int64_t.
Definition: Polynomials.hpp:65
bool operator!=(const DefaultContainer &b) const
Inequality of polynomials.
bool operator==(const DefaultContainer &) const
Equality of polynomials.
void multiply_add(const std::pair< const std::pair< deg_t, exp_t >, scl_t > &kvp1, const std::pair< const std::pair< deg_t, exp_t >, scl_t > &kvp2)
Multiplies the two given monomials and then adds the product to polynomial.
Iterator end()
Iterator to just after the final monomial.
ConstIterator begin() const
ConstIterator to the first monomial.
_exp exp_t
The exponent (variable) type eg StandardVariables or HalfIdempotentVariables.
Definition: Polynomials.hpp:66
void reserve(size_t n)
Reserve number of monomials in polynomial.
Class for polynomials in multiple variables with relations.
Definition: Polynomials.hpp:149
Polynomial(const deg_t *dim_var=nullptr, const std::string *name_var=nullptr)
Constructs zero polynomial.
Polynomial(const exp_t &exp, scl_t coeff, const deg_t *dim_var=nullptr, const std::string *name_var=nullptr)
Constructs polynomial with a single nonzero monomial term.
Polynomial & operator+=(const Polynomial &other)
Addition assignment.
Polynomial & operator*=(const Polynomial &other)
Multiplication assignment.
container_t::exp_t exp_t
The exponent (variable) type eg StandardVariables or HalfIdempotentVariables.
Definition: Polynomials.hpp:152
Polynomial & operator-=(const Polynomial &other)
Subtraction assignment.
size_t number_of_variables() const
Returns the number of variables of the polynomial.
Polynomial operator^(T p) const
Raises polynomial to integer power.
container_t::scl_t scl_t
The scalar (coefficient) type eg int64_t.
Definition: Polynomials.hpp:151
Polynomial & operator*=(scl_t scalar)
Scalar multiplication assignment.
friend std::ostream & operator<<(std::ostream &, const Polynomial< cont > &)
Befriending the print to ostream function.
Polynomial operator+(const Polynomial &other) const
Addition of polynomials.
Polynomial operator-(const Polynomial &other) const
Subtraction of polynomials.
Polynomial operator*(const Polynomial &other) const
Multiplication of polynomials.
Polynomial(int num_var, scl_t coeff, const deg_t *dim_var=nullptr, const std::string *name_var=nullptr)
Constructs constant nonzero polynomial.
container_t::deg_t deg_t
The degree type eg size_t.
Definition: Polynomials.hpp:153
The namespace which contains every method and class in the library.
Definition: General.hpp:16
std::ostream & operator<<(std::ostream &os, const Polynomial< container_t > &a)
Prints polynomial to output stream.