Symmetric Polynomials  V3.1
A C++ library for generating symmetric polynomials with relations
DefaultContainer< _scl, _exp, _cnt, _ord, _arg > Class Template Reference

The default ordered/unordered monomial container. More...

#include <Polynomials.hpp>

Inheritance diagram for DefaultContainer< _scl, _exp, _cnt, _ord, _arg >:
[legend]
Collaboration diagram for DefaultContainer< _scl, _exp, _cnt, _ord, _arg >:
[legend]

Classes

class  ConstIterator
 Constant iterator traversing the monomials of a polynomial. More...
 
class  Iterator
 Non const iterator traversing the monomials of a polynomial. More...
 

Public Member Functions

size_t number_of_monomials () const
 Returns number of monomials in the polynomial. More...
 
bool operator== (const DefaultContainer &) const
 Equality of polynomials. More...
 
bool operator!= (const DefaultContainer &b) const
 Inequality of polynomials. More...
 
void reserve (size_t n)
 Reserve number of monomials in polynomial. More...
 
void insert (const exp_t &exp, scl_t coeff)
 Inserts monomial in polynomial. More...
 
ConstIterator begin () const
 ConstIterator to the first monomial. More...
 
ConstIterator end () const
 ConstIterator to just after the final monomial. More...
 
ConstIterator highest_term () const
 ConstIterator to the highest term monomial. More...
 

Protected Types

typedef _scl scl_t
 The scalar (coefficient) type eg int64_t. More...
 
typedef _exp exp_t
 The exponent (variable) type eg StandardVariables or HalfIdempotentVariables. More...
 
typedef _exp::deg_t deg_t
 The degree type eg size_t. More...
 

Protected Member Functions

Iterator begin ()
 Iterator to the first monomial. More...
 
Iterator end ()
 Iterator to just after the final monomial. More...
 
void add (const std::pair< const std::pair< deg_t, exp_t >, scl_t > &kvp)
 Adds given monomial to polynomial. More...
 
void subtract (const std::pair< const std::pair< deg_t, exp_t >, scl_t > &kvp)
 Subtracts given monomial from polynomial. More...
 
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. More...
 
- Protected Member Functions inherited from BaseContainer< _exp >
 BaseContainer (const deg_t *dimensions=nullptr)
 Constructor given pointer to dimensions of the variables. More...
 
deg_t compute_degree (const _exp &exponent) const
 Computes degree of given exponent. More...
 

Additional Inherited Members

- Protected Attributes inherited from BaseContainer< _exp >
const deg_t * dimensions
 The pointer to the dimensions of the variables. More...
 

Detailed Description

template<class _scl, class _exp, template< class... > class _cnt, bool _ord, class ... _arg>
class symmp::DefaultContainer< _scl, _exp, _cnt, _ord, _arg >

The default ordered/unordered monomial container.

Monomials are stored as key-value pairs where each key consists of degree+exponent and the value is the coefficient of the monomial.

Note
We store the degree for improved performance.
Template Parameters
_sclThe scalar/coefficient type of the monomials eg float or int64_t
_expThe variable/exponent type of the monomials eg StandardVariables or HalfIdempotentVariables
_cntThe underlying container: this should be equivalent to std::map if _ord==1 and std::unordered_map otherwise
_ordThis should be 1 if _cnt is equivalent to std::map and 0 if it's equivalent to std::unordered_map
_argAny extra optional arguments to pass to _cnt apart from key,value, comparator/hash (the latter two are provided in _exp) eg an allocator
Attention
In addition to the requirements from BaseContainer, if _ord==1 then exp_t needs to have a comparator bool operator<(const _exp&) const and otherwise exp_t needs to have a hash function size_t operator()() const
Todo:
Use concepts (C++20) to express the requirements from exp_t

Member Typedef Documentation

◆ scl_t

typedef _scl scl_t
protected

The scalar (coefficient) type eg int64_t.

◆ exp_t

typedef _exp exp_t
protected

The exponent (variable) type eg StandardVariables or HalfIdempotentVariables.

◆ deg_t

typedef _exp::deg_t deg_t
protected

The degree type eg size_t.

Member Function Documentation

◆ number_of_monomials()

size_t number_of_monomials ( ) const

Returns number of monomials in the polynomial.

◆ operator==()

bool operator== ( const DefaultContainer< _scl, _exp, _cnt, _ord, _arg > &  ) const

Equality of polynomials.

◆ operator!=()

bool operator!= ( const DefaultContainer< _scl, _exp, _cnt, _ord, _arg > &  b) const

Inequality of polynomials.

◆ reserve()

void reserve ( size_t  n)

Reserve number of monomials in polynomial.

Parameters
nNumber to reserve
Attention
Does nothing if _ord==1

◆ insert()

void insert ( const exp_t exp,
scl_t  coeff 
)

Inserts monomial in polynomial.

Parameters
expThe exponent of the monomial.
coeffThe coefficient of the monomial.
Warning
It is the user's responsibility to make sure that all exponents have the same length(number of variables), the exponent being inserted is not already there and that coeff is not 0

◆ begin() [1/2]

ConstIterator begin ( ) const

ConstIterator to the first monomial.

◆ end() [1/2]

ConstIterator end ( ) const

ConstIterator to just after the final monomial.

◆ highest_term()

ConstIterator highest_term ( ) const

ConstIterator to the highest term monomial.

Note
If the container is ordered then this just returns the last term in \(O(1)\) time.
Otherwise it finds the highest degree by linear search through the entire polynomial in \(O(n)\) time.

◆ begin() [2/2]

Iterator begin ( )
protected

Iterator to the first monomial.

◆ end() [2/2]

Iterator end ( )
protected

Iterator to just after the final monomial.

◆ add()

void add ( const std::pair< const std::pair< deg_t, exp_t >, scl_t > &  kvp)
protected

Adds given monomial to polynomial.

Parameters
kvpThe key-value pair representing the monomial

◆ subtract()

void subtract ( const std::pair< const std::pair< deg_t, exp_t >, scl_t > &  kvp)
protected

Subtracts given monomial from polynomial.

Parameters
kvpThe key-value pair representing the monomial

◆ multiply_add()

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 
)
protected

Multiplies the two given monomials and then adds the product to polynomial.

Parameters
kvp1The key-value pair representing the first monomial
kvp2The key-value pair representing the second monomial

The documentation for this class was generated from the following file: