Drake
Monomial Class Reference

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

#include <drake/common/symbolic_monomial.h>

Public Member Functions

 Monomial ()=default
 Constructs a monomial equal to 1. More...
 
 Monomial (const std::map< Variable, int > &powers)
 Constructs a Monomial from powers. 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 . 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...
 
size_t GetHash () const
 Returns hash value. 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...
 
std::pair< double, MonomialSubstitute (const Environment &env) const
 Substitutes 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

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

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.

Constructor & Destructor Documentation

Monomial ( const Monomial )
default
Monomial ( Monomial &&  )
default
Monomial ( )
default

Constructs a monomial equal to 1.

Namely the total degree is zero.

Here is the caller graph for this function:

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

Constructs a Monomial from powers.

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 ( const Variable var)
explicit

Constructs a Monomial from var.

Monomial ( const Variable var,
int  exponent 
)

Constructs a Monomial from var and .

Member Function Documentation

int degree ( const Variable v) const

Returns the degree of this Monomial in a variable v.

double Evaluate ( const Environment env) const

Evaluates under a given environment env.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

size_t GetHash ( ) const

Returns hash value.

Here is the caller graph for this function:

Variables GetVariables ( ) const

Returns the set of variables in this monomial.

Here is the caller graph for this function:

bool operator!= ( const Monomial m) const

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

Here is the caller graph for this function:

Monomial & operator*= ( const Monomial m)

Returns this monomial multiplied by m.

Here is the call graph for this function:

Here is the caller graph for this function:

Monomial& operator= ( const Monomial )
default
Monomial& operator= ( Monomial &&  )
default
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.

Here is the caller graph for this function:

Monomial & pow_in_place ( int  p)

Returns this monomial raised to p.

Exceptions
std::runtime_errorif p is negative.

Here is the caller graph for this function:

pair< double, Monomial > Substitute ( const Environment env) const

Substitutes using a given environment env.

The substitution result is of type pair<double, Monomial>. The first component (: double) represents the coefficient part while the second component represents the remaining parts of the Monomial which was not substituted. Note that users are allowed to provide a partial environment.

Example 1. Substitution with a fully-specified environment (x^3*y^2).Substitute({{x, 2}, {y, 3}}) = (2^3 * 3^2 = 8 * 9 = 72, Monomial{} = 1).

Example 1. Substitution with a partial environment (x^3*y^2).Substitute({{x, 2}}) = (2^3 = 8, y^2).

Here is the call graph for this function:

Here is the caller graph for this function:

Expression ToExpression ( ) const

Returns a symbolic expression representing this monomial.

Here is the caller graph for this function:

int total_degree ( ) const
inline

Returns the total degree of this Monomial.

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

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

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