Drake
Drake C++ Documentation
PolynomialBasisElement Class Referenceabstract

Detailed Description

Each polynomial p(x) can be written as a linear combination of its basis elements p(x) = ∑ᵢ cᵢ * ϕᵢ(x), where ϕᵢ(x) is the i'th element in the basis, cᵢ is the coefficient of that element.

The most commonly used basis is monomials. For example in polynomial p(x) = 2x₀²x₁ + 3x₀x₁ + 2, x₀²x₁, x₀x₁ and 1 are all elements of monomial basis. Likewise, a polynomial can be written using other basis, such as Chebyshev polynomials, Legendre polynomials, etc. For a polynomial written with Chebyshev polynomial basis p(x) = 2T₂(x₀)T₁(x₁) + 3T₁(x₁) + 2T₂(x₀), T₂(x₀)T₁(x₁),T₁(x₁), and T₂(x₀) are all elements of Chebyshev basis. This PolynomialBasisElement class represents an element ϕᵢ(x) in the basis. We can think of an element of polynomial basis as a mapping from the variable to its degree. So for monomial basis element x₀²x₁, it can be thought of as a mapping {x₀ -> 2, x₁ -> 1}. For a Chebyshev basis element T₂(x₀)T₁(x₁), it can be thought of as a mapping {x₀ -> 2, x₁ -> 1}.

Each of the derived class, Derived, should implement the following functions

  • std::map<Derived, double> operator*(const Derived& A, const Derived&B)
  • std::map<Derived, double> Derived::Differentiate(const Variable& var) const;
  • std::map<Derived, double> Derived::Integrate(const Variable& var) const;
  • bool Derived::operator<(const Derived& other) const;
  • std::pair<double, Derived> EvaluatePartial(const Environment& e) const;
  • void MergeBasisElementInPlace(const Derived& other)

The function lexicographical_compare can be used when implementing operator<. The function DoEvaluatePartial can be used when implementing EvaluatePartial

#include <drake/common/symbolic/polynomial_basis_element.h>

Public Member Functions

 PolynomialBasisElement ()=default
 Constructs a polynomial basis with empty var_to_degree map. More...
 
 PolynomialBasisElement (const std::map< Variable, int > &var_to_degree_map)
 Constructs a polynomial basis given the variable and the degree of that variable. More...
 
 PolynomialBasisElement (const Eigen::Ref< const VectorX< Variable >> &vars, const Eigen::Ref< const Eigen::VectorXi > &degrees)
 Constructs a polynomial basis, such that it contains the variable-to-degree map vars(i)→degrees(i). More...
 
virtual ~PolynomialBasisElement ()=default
 
const std::map< Variable, int > & var_to_degree_map () const
 
const std::map< Variable, int > & get_powers () const
 Returns variable to degree map. More...
 
int total_degree () const
 Returns the total degree of a polynomial basis. More...
 
int degree (const Variable &v) const
 Returns the degree of this PolynomialBasisElement in a variable v. More...
 
Variables GetVariables () const
 
double Evaluate (const Environment &env) const
 Evaluates under a given environment env. More...
 
bool operator== (const PolynomialBasisElement &other) const
 
bool operator!= (const PolynomialBasisElement &other) const
 
Expression ToExpression () const
 
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
 PolynomialBasisElement (const PolynomialBasisElement &)=default
 
PolynomialBasisElementoperator= (const PolynomialBasisElement &)=default
 
 PolynomialBasisElement (PolynomialBasisElement &&)=default
 
PolynomialBasisElementoperator= (PolynomialBasisElement &&)=default
 

Protected Member Functions

bool lexicographical_compare (const PolynomialBasisElement &other) const
 Compares two PolynomialBasisElement using lexicographical order. More...
 
virtual bool EqualTo (const PolynomialBasisElement &other) const
 
void DoEvaluatePartial (const Environment &e, double *coeff, std::map< Variable, int > *new_basis_element) const
 
intget_mutable_total_degree ()
 
std::map< Variable, int > * get_mutable_var_to_degree_map ()
 
void DoMergeBasisElementInPlace (const PolynomialBasisElement &other)
 Merge this basis element with another basis element by merging their var_to_degree_map. More...
 

Constructor & Destructor Documentation

◆ PolynomialBasisElement() [1/5]

◆ PolynomialBasisElement() [2/5]

◆ PolynomialBasisElement() [3/5]

Constructs a polynomial basis with empty var_to_degree map.

This element should be interpreted as 1.

◆ PolynomialBasisElement() [4/5]

PolynomialBasisElement ( const std::map< Variable, int > &  var_to_degree_map)
explicit

Constructs a polynomial basis given the variable and the degree of that variable.

Exceptions
std::exceptionif any of the degree is negative.
Note
we will ignore the variable with degree 0.

◆ PolynomialBasisElement() [5/5]

PolynomialBasisElement ( const Eigen::Ref< const VectorX< Variable >> &  vars,
const Eigen::Ref< const Eigen::VectorXi > &  degrees 
)

Constructs a polynomial basis, such that it contains the variable-to-degree map vars(i)→degrees(i).

Exceptions
std::exceptionif vars contains repeated variables.
std::exceptionif any degree is negative.

◆ ~PolynomialBasisElement()

virtual ~PolynomialBasisElement ( )
virtualdefault

Member Function Documentation

◆ degree()

int degree ( const Variable v) const

Returns the degree of this PolynomialBasisElement in a variable v.

If v is not a variable in this PolynomialBasisElement, then returns 0.

◆ DoEvaluatePartial()

void DoEvaluatePartial ( const Environment e,
double coeff,
std::map< Variable, int > *  new_basis_element 
) const
protected

◆ DoMergeBasisElementInPlace()

void DoMergeBasisElementInPlace ( const PolynomialBasisElement other)
protected

Merge this basis element with another basis element by merging their var_to_degree_map.

After merging, the degree of each variable is raised to the sum of the degree in each basis element (if a variable does not show up in either one of the basis element, we regard its degree to be 0).

◆ EqualTo()

virtual bool EqualTo ( const PolynomialBasisElement other) const
protectedvirtual

◆ Evaluate()

double Evaluate ( const Environment env) const

Evaluates under a given environment env.

Exceptions
std::exceptionexception if there is a variable in this monomial whose assignment is not provided by env.

◆ get_mutable_total_degree()

int* get_mutable_total_degree ( )
protected

◆ get_mutable_var_to_degree_map()

std::map<Variable, int>* get_mutable_var_to_degree_map ( )
protected

◆ get_powers()

const std::map<Variable, int>& get_powers ( ) const

Returns variable to degree map.

TODO(hongkai.dai): this function is added because Monomial class has get_powers() function. We will remove this get_powers() function when Monomial class is deprecated.

◆ GetVariables()

Variables GetVariables ( ) const

◆ lexicographical_compare()

bool lexicographical_compare ( const PolynomialBasisElement other) const
protected

Compares two PolynomialBasisElement using lexicographical order.

This function is meant to be called by the derived class, to compare two polynomial basis of the same derived class.

◆ operator!=()

bool operator!= ( const PolynomialBasisElement other) const

◆ operator=() [1/2]

PolynomialBasisElement& operator= ( PolynomialBasisElement &&  )
default

◆ operator=() [2/2]

PolynomialBasisElement& operator= ( const PolynomialBasisElement )
default

◆ operator==()

bool operator== ( const PolynomialBasisElement other) const

◆ ToExpression()

Expression ToExpression ( ) const

◆ total_degree()

int total_degree ( ) const

Returns the total degree of a polynomial basis.

This is the summation of the degree for each variable.

◆ var_to_degree_map()

const std::map<Variable, int>& var_to_degree_map ( ) const

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