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
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 > °rees) | |
Constructs a polynomial basis, such that it contains the variable-to-degree map vars(i)→degrees(i). More... | |
virtual | ~PolynomialBasisElement () |
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 | |
PolynomialBasisElement & | operator= (const PolynomialBasisElement &)=default |
PolynomialBasisElement (PolynomialBasisElement &&)=default | |
PolynomialBasisElement & | operator= (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 |
int * | get_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... | |
|
default |
|
default |
|
default |
Constructs a polynomial basis with empty var_to_degree map.
This element should be interpreted as 1.
|
explicit |
Constructs a polynomial basis given the variable and the degree of that variable.
std::exception | if any of the degree is negative. |
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).
std::exception | if vars contains repeated variables. |
std::exception | if any degree is negative. |
|
virtual |
Returns the degree of this PolynomialBasisElement in a variable v
.
If v
is not a variable in this PolynomialBasisElement, then returns 0.
|
protected |
|
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).
|
protectedvirtual |
double Evaluate | ( | const Environment & | env | ) | const |
Evaluates under a given environment env
.
std::exception | exception if there is a variable in this monomial whose assignment is not provided by env . |
|
protected |
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.
Variables GetVariables | ( | ) | 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.
bool operator!= | ( | const PolynomialBasisElement & | other | ) | const |
|
default |
|
default |
bool operator== | ( | const PolynomialBasisElement & | other | ) | const |
Expression ToExpression | ( | ) | const |
int total_degree | ( | ) | const |
Returns the total degree of a polynomial basis.
This is the summation of the degree for each variable.