Drake
Drake C++ Documentation
Monomial Class Reference

Detailed Description

Represents a monomial, a product of powers of variables with non-negative integer exponents.

Note that it does not include the coefficient part of a monomial.

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

Public Member Functions

 Monomial ()=default
 Constructs a monomial equal to 1. More...
 
 Monomial (std::nullptr_t)
 Constructs a default value. More...
 
 Monomial (const std::map< Variable, int > &powers)
 Constructs a monomial from powers. More...
 
 Monomial (const Eigen::Ref< const VectorX< Variable >> &vars, const Eigen::Ref< const Eigen::VectorXi > &exponents)
 Constructs a monomial from a vector of variables vars and their corresponding integer exponents exponents. More...
 
 Monomial (const Expression &e)
 Converts an expression to a monomial if the expression is written as ∏ᵢpow(xᵢ, kᵢ), otherwise throws a runtime error. More...
 
 Monomial (const Variable &var)
 Constructs a monomial from var. More...
 
 Monomial (const Variable &var, int exponent)
 Constructs a monomial from var and exponent. More...
 
int degree (const Variable &v) const
 Returns the degree of this monomial in a variable v. More...
 
int total_degree () const
 Returns the total degree of this monomial. More...
 
Variables GetVariables () const
 Returns the set of variables in this monomial. More...
 
const std::map< Variable, int > & get_powers () const
 Returns the internal representation of Monomial, the map from a base (Variable) to its exponent (int). More...
 
double Evaluate (const Environment &env) const
 Evaluates under a given environment env. More...
 
Eigen::VectorXd Evaluate (const Eigen::Ref< const VectorX< symbolic::Variable >> &vars, const Eigen::Ref< const Eigen::MatrixXd > &vars_values) const
 Evaluates the monomial for a batch of data. More...
 
std::pair< double, MonomialEvaluatePartial (const Environment &env) const
 Partially evaluates using a given environment env. More...
 
Expression ToExpression () const
 Returns a symbolic expression representing this monomial. More...
 
bool operator== (const Monomial &m) const
 Checks if this monomial and m represent the same monomial. More...
 
bool operator!= (const Monomial &m) const
 Checks if this monomial and m do not represent the same monomial. More...
 
Monomialoperator *= (const Monomial &m)
 Returns this monomial multiplied by m. More...
 
Monomialpow_in_place (int p)
 Returns this monomial raised to p. More...
 
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
 Monomial (const Monomial &)=default
 
Monomialoperator= (const Monomial &)=default
 
 Monomial (Monomial &&)=default
 
Monomialoperator= (Monomial &&)=default
 

Friends

template<class HashAlgorithm >
void hash_append (HashAlgorithm &hasher, const Monomial &item) noexcept
 Implements the hash_append generic hashing concept. More...
 
std::ostream & operator<< (std::ostream &out, const Monomial &m)
 

Constructor & Destructor Documentation

◆ Monomial() [1/9]

Monomial ( const Monomial )
default

◆ Monomial() [2/9]

Monomial ( Monomial &&  )
default

◆ Monomial() [3/9]

Monomial ( )
default

Constructs a monomial equal to 1.

Namely the total degree is zero.

◆ Monomial() [4/9]

Monomial ( std::nullptr_t  )
explicit

Constructs a default value.

This overload is used by Eigen when EIGEN_INITIALIZE_MATRICES_BY_ZERO is enabled.

◆ Monomial() [5/9]

Monomial ( const std::map< Variable, int > &  powers)
explicit

Constructs a monomial from powers.

Exceptions
std::exceptionif powers includes a negative exponent.

◆ Monomial() [6/9]

Monomial ( const Eigen::Ref< const VectorX< Variable >> &  vars,
const Eigen::Ref< const Eigen::VectorXi > &  exponents 
)

Constructs a monomial from a vector of variables vars and their corresponding integer exponents exponents.

For example, Monomial([x, y, z], [2, 0, 1]) constructs a monomial x²z.

Precondition
The size of vars should be the same as the size of exponents.
Exceptions
std::exceptionif exponents includes a negative integer.

◆ Monomial() [7/9]

Monomial ( const Expression e)
explicit

Converts an expression to a monomial if the expression is written as ∏ᵢpow(xᵢ, kᵢ), otherwise throws a runtime error.

Precondition
is_polynomial(e) should be true.

◆ Monomial() [8/9]

Monomial ( const Variable var)
explicit

Constructs a monomial from var.

◆ Monomial() [9/9]

Monomial ( const Variable var,
int  exponent 
)

Constructs a monomial from var and exponent.

Member Function Documentation

◆ degree()

int degree ( const Variable v) const

Returns the degree of this monomial in a variable v.

◆ Evaluate() [1/2]

double Evaluate ( const Environment env) const

Evaluates under a given environment env.

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

◆ Evaluate() [2/2]

Eigen::VectorXd Evaluate ( const Eigen::Ref< const VectorX< symbolic::Variable >> &  vars,
const Eigen::Ref< const Eigen::MatrixXd > &  vars_values 
) const

Evaluates the monomial for a batch of data.

We return monomial_vals such that monomial_vals(j) is obtained by substituting vars(i) with vars_values(i, j), note that vars_values.rows() == vars.rows() and vars_values.cols() == monomial_vals.rows().

Parameters
varsThe variables whose value will be substituted. vars must contain all variables in this->GetVariables(). Also vars cannot contain any duplicate variables, namely vars(i) != vars(j) if i != j.
vars_valuesThe i'th column of vars_values is the i'th data for vars.
Exceptions
std::exceptionif vars doesn't contain all the variables in this->GetVariables().

◆ EvaluatePartial()

std::pair<double, Monomial> EvaluatePartial ( const Environment env) const

Partially evaluates using a given environment env.

The evaluation result is of type pair<double, Monomial>. The first component (a double) represents the coefficient part while the second component represents the remaining parts of the monomial which was not evaluated.

Example 1. Evaluate with a fully-specified environment (x³*y²).EvaluatePartial({{x, 2}, {y, 3}}) = (2³ * 3² = 8 * 9 = 72, Monomial{} = 1).

Example 2. Evaluate with a partial environment (x³*y²).EvaluatePartial({{x, 2}}) = (2³ = 8, y²).

◆ get_powers()

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

Returns the internal representation of Monomial, the map from a base (Variable) to its exponent (int).

◆ GetVariables()

Variables GetVariables ( ) const

Returns the set of variables in this monomial.

◆ operator *=()

Monomial& operator *= ( const Monomial m)

Returns this monomial multiplied by m.

◆ operator!=()

bool operator!= ( const Monomial m) const

Checks if this monomial and m do not represent the same monomial.

◆ operator=() [1/2]

Monomial& operator= ( const Monomial )
default

◆ operator=() [2/2]

Monomial& operator= ( Monomial &&  )
default

◆ operator==()

bool operator== ( const Monomial m) const

Checks if this monomial and m represent the same monomial.

Two monomials are equal iff they contain the same variable raised to the same exponent.

◆ pow_in_place()

Monomial& pow_in_place ( int  p)

Returns this monomial raised to p.

Exceptions
std::exceptionif p is negative.

◆ ToExpression()

Expression ToExpression ( ) const

Returns a symbolic expression representing this monomial.

◆ total_degree()

int total_degree ( ) const

Returns the total degree of this monomial.

Friends And Related Function Documentation

◆ hash_append

void hash_append ( HashAlgorithm &  hasher,
const Monomial item 
)
friend

Implements the hash_append generic hashing concept.

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const Monomial m 
)
friend

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