Drake

Represents symbolic polynomials. More...
#include <common/symbolic_polynomial.h>
Public Types  
using  MapType = std::unordered_map< Monomial, Expression > 
Public Member Functions  
Polynomial ()=default  
Constructs a zero polynomial. More...  
Polynomial (MapType init)  
Constructs a polynomial from a map, Monomial → Expression. More...  
Polynomial (const Monomial &m)  
Constructs a polynomial from a monomial m . More...  
Polynomial (const Expression &e)  
Constructs a polynomial from an expression e . More...  
Polynomial (const Expression &e, const Variables &indeterminates)  
Constructs a polynomial from an expression e by decomposing it with respect to indeterminates . More...  
Variables  indeterminates () const 
Returns the indeterminates of this polynomial. More...  
Variables  decision_variables () const 
Returns the decision variables of this polynomial. More...  
int  Degree (const Variable &v) const 
Returns the highest degree of this polynomial in a variable v . More...  
int  TotalDegree () const 
Returns the total degree of this polynomial. More...  
const MapType &  monomial_to_coefficient_map () const 
Returns the mapping from a Monomial to its corresponding coefficient of this polynomial. More...  
Expression  ToExpression () const 
Returns an equivalent symbolic expression of this polynomial. More...  
Polynomial  Differentiate (const Variable &x) const 
Differentiates this polynomial with respect to the variable x . More...  
template<typename Derived >  
Eigen::Matrix< Polynomial, 1, Derived::RowsAtCompileTime >  Jacobian (const Eigen::MatrixBase< Derived > &vars) const 
Computes the Jacobian matrix J of the polynomial with respect to vars . More...  
double  Evaluate (const Environment &env) const 
Evaluates this polynomial under a given environment env . More...  
Polynomial  EvaluatePartial (const Environment &env) const 
Partially evaluates this polynomial using an environment env . More...  
Polynomial  EvaluatePartial (const Variable &var, double c) const 
Partially evaluates this polynomial by substituting var with c . More...  
Polynomial &  AddProduct (const Expression &coeff, const Monomial &m) 
Adds coeff * m to this polynomial. More...  
Polynomial &  operator+= (const Polynomial &p) 
Polynomial &  operator+= (const Monomial &m) 
Polynomial &  operator+= (double c) 
Polynomial &  operator= (const Polynomial &p) 
Polynomial &  operator= (const Monomial &m) 
Polynomial &  operator= (double c) 
Polynomial &  operator*= (const Polynomial &p) 
Polynomial &  operator*= (const Monomial &m) 
Polynomial &  operator*= (double c) 
bool  EqualTo (const Polynomial &p) const 
Returns true if this polynomial and p are structurally equal. More...  
Formula  operator== (const Polynomial &p) const 
Returns a symbolic formula representing the condition where this polynomial and p are the same. More...  
Formula  operator!= (const Polynomial &p) const 
Returns a symbolic formula representing the condition where this polynomial and p are not the same. More...  
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable  
Polynomial (const Polynomial &)=default  
Polynomial &  operator= (const Polynomial &)=default 
Polynomial (Polynomial &&)=default  
Polynomial &  operator= (Polynomial &&)=default 
Friends  
template<class HashAlgorithm >  
void  hash_append (HashAlgorithm &hasher, const Polynomial &item) noexcept 
Implements the hash_append generic hashing concept. More...  
Represents symbolic polynomials.
A symbolic polynomial keeps a mapping from a monomial of indeterminates to its coefficient in a symbolic expression.
A polynomial p
has to satisfy an invariant such that p.decision_variables() ∩ p.indeterminates() = ∅
. We have CheckInvariant() method to check the invariant.
Note that arithmetic operations (+,,*) between a Polynomial and a Variable are not provided. The problem is that Variable class has no intrinsic information if a variable is a decision variable or an indeterminate while we need this information to perform arithmetic operations over Polynomials.
using MapType = std::unordered_map<Monomial, Expression> 

default 
Constructs a zero polynomial.

default 

default 

explicit 
Constructs a polynomial from a map, Monomial → Expression.
Polynomial  (  const Monomial &  m  ) 
Constructs a polynomial from a monomial m
.
Note that all variables in m
are considered as indeterminates.

explicit 
Constructs a polynomial from an expression e
.
Note that all variables in e
are considered as indeterminates.
std::runtime_error  if e is not a polynomial. 
Polynomial  (  const Expression &  e, 
const Variables &  indeterminates  
) 
Constructs a polynomial from an expression e
by decomposing it with respect to indeterminates
.
e
and the provided indeterminates
.std::runtime_error  if e is not a polynomial in indeterminates . 
Polynomial & AddProduct  (  const Expression &  coeff, 
const Monomial &  m  
) 
Adds coeff
* m
to this polynomial.
Variables decision_variables  (  )  const 
Returns the decision variables of this polynomial.
Returns the highest degree of this polynomial in a variable v
.
Polynomial Differentiate  (  const Variable &  x  )  const 
Differentiates this polynomial with respect to the variable x
.
Note that a variable x
can be either a decision variable or an indeterminate.
bool EqualTo  (  const Polynomial &  p  )  const 
Returns true if this polynomial and p
are structurally equal.
double Evaluate  (  const Environment &  env  )  const 
Evaluates this polynomial under a given environment env
.
std::out_of_range  if there is a variable in this polynomial whose assignment is not provided by env . 
Polynomial EvaluatePartial  (  const Environment &  env  )  const 
Partially evaluates this polynomial using an environment env
.
std::runtime_error  if NaN is detected during evaluation. 
Polynomial EvaluatePartial  (  const Variable &  var, 
double  c  
)  const 
Partially evaluates this polynomial by substituting var
with c
.
std::runtime_error  if NaN is detected at any point during evaluation. 
Variables indeterminates  (  )  const 
Returns the indeterminates of this polynomial.

inline 
Computes the Jacobian matrix J of the polynomial with respect to vars
.
J(0,i) contains ∂f/∂vars(i).
const Polynomial::MapType & monomial_to_coefficient_map  (  )  const 
Returns the mapping from a Monomial to its corresponding coefficient of this polynomial.
Formula operator!=  (  const Polynomial &  p  )  const 
Returns a symbolic formula representing the condition where this polynomial and p
are not the same.
Polynomial & operator*=  (  const Polynomial &  p  ) 
Polynomial & operator*=  (  const Monomial &  m  ) 
Polynomial & operator*=  (  double  c  ) 
Polynomial & operator+=  (  const Polynomial &  p  ) 
Polynomial & operator+=  (  const Monomial &  m  ) 
Polynomial & operator+=  (  double  c  ) 
Polynomial & operator=  (  const Polynomial &  p  ) 
Polynomial & operator=  (  const Monomial &  m  ) 
Polynomial & operator=  (  double  c  ) 

default 

default 
Formula operator==  (  const Polynomial &  p  )  const 
Returns a symbolic formula representing the condition where this polynomial and p
are the same.
Expression ToExpression  (  )  const 
Returns an equivalent symbolic expression of this polynomial.
int TotalDegree  (  )  const 
Returns the total degree of this polynomial.

friend 
Implements the hash_append generic hashing concept.