Drake
symbolic_expression.h File Reference
#include <algorithm>
#include <cstddef>
#include <functional>
#include <limits>
#include <map>
#include <memory>
#include <ostream>
#include <random>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <vector>
#include <Eigen/Core>
#include <Eigen/Sparse>
#include "drake/common/cond.h"
#include "drake/common/drake_assert.h"
#include "drake/common/drake_copyable.h"
#include "drake/common/drake_throw.h"
#include "drake/common/dummy_value.h"
#include "drake/common/eigen_types.h"
#include "drake/common/extract_double.h"
#include "drake/common/hash.h"
#include "drake/common/random.h"
#include "drake/common/symbolic.h"
Include dependency graph for symbolic_expression.h:
This graph shows which files directly or indirectly include this file:

Classes

class  Expression
 Represents a symbolic form of an expression. More...
 
struct  hash< drake::symbolic::Expression >
 
struct  less< drake::symbolic::Expression >
 
struct  equal_to< drake::symbolic::Expression >
 
struct  numeric_limits< drake::symbolic::Expression >
 
class  uniform_real_distribution< drake::symbolic::Expression >
 Provides std::uniform_real_distribution, U(a, b), for symbolic expressions. More...
 
class  normal_distribution< drake::symbolic::Expression >
 Provides std::normal_distribution, N(μ, σ), for symbolic expressions. More...
 
class  exponential_distribution< drake::symbolic::Expression >
 Provides std::exponential_distribution, Exp(λ), for symbolic expressions. More...
 
struct  dummy_value< symbolic::Expression >
 Specializes common/dummy_value.h. More...
 
struct  is_eigen_nonvector_expression_double_pair< DerivedV, DerivedB >
 
struct  is_eigen_vector_expression_double_pair< DerivedV, DerivedB >
 

Namespaces

 drake
 
 drake::symbolic
 

Typedefs

using Substitution = std::unordered_map< Variable, Expression >
 

Enumerations

enum  ExpressionKind {
  Constant, Var, Add, Mul,
  Div, Log, Abs, Exp,
  Sqrt, Pow, Sin, Cos,
  Tan, Asin, Acos, Atan,
  Atan2, Sinh, Cosh, Tanh,
  Min, Max, Ceil, Floor,
  IfThenElse, NaN, UninterpretedFunction
}
 Kinds of symbolic expressions. More...
 

Functions

bool operator< (ExpressionKind k1, ExpressionKind k2)
 Total ordering between ExpressionKinds. More...
 
Expression operator+ (Expression lhs, const Expression &rhs)
 
Expression & operator+= (Expression &lhs, const Expression &rhs)
 
Expression operator+ (const Expression &e)
 
Expression operator- (Expression lhs, const Expression &rhs)
 
Expression & operator-= (Expression &lhs, const Expression &rhs)
 
Expression operator- (const Expression &e)
 
Expression operator * (Expression lhs, const Expression &rhs)
 
Expression & operator *= (Expression &lhs, const Expression &rhs)
 
Expression operator/ (Expression lhs, const Expression &rhs)
 
Expression & operator/= (Expression &lhs, const Expression &rhs)
 
Expression log (const Expression &e)
 
Expression abs (const Expression &e)
 
Expression exp (const Expression &e)
 
Expression sqrt (const Expression &e)
 
Expression pow (const Expression &e1, const Expression &e2)
 
Expression sin (const Expression &e)
 
Expression cos (const Expression &e)
 
Expression tan (const Expression &e)
 
Expression asin (const Expression &e)
 
Expression acos (const Expression &e)
 
Expression atan (const Expression &e)
 
Expression atan2 (const Expression &e1, const Expression &e2)
 
Expression sinh (const Expression &e)
 
Expression cosh (const Expression &e)
 
Expression tanh (const Expression &e)
 
Expression min (const Expression &e1, const Expression &e2)
 
Expression max (const Expression &e1, const Expression &e2)
 
Expression ceil (const Expression &e)
 
Expression floor (const Expression &e)
 
Expression if_then_else (const Formula &f_cond, const Expression &e_then, const Expression &e_else)
 
Expression uninterpreted_function (std::string name, std::vector< Expression > arguments)
 Constructs an uninterpreted-function expression with name and arguments. More...
 
void swap (Expression &a, Expression &b)
 
std::ostream & operator<< (std::ostream &os, const Expression &e)
 
bool is_constant (const Expression &e)
 Checks if e is a constant expression. More...
 
bool is_constant (const Expression &e, double v)
 Checks if e is a constant expression representing v. More...
 
bool is_zero (const Expression &e)
 Checks if e is 0.0. More...
 
bool is_one (const Expression &e)
 Checks if e is 1.0. More...
 
bool is_neg_one (const Expression &e)
 Checks if e is -1.0. More...
 
bool is_two (const Expression &e)
 Checks if e is 2.0. More...
 
bool is_nan (const Expression &e)
 Checks if e is NaN. More...
 
bool is_variable (const Expression &e)
 Checks if e is a variable expression. More...
 
bool is_addition (const Expression &e)
 Checks if e is an addition expression. More...
 
bool is_multiplication (const Expression &e)
 Checks if e is a multiplication expression. More...
 
bool is_division (const Expression &e)
 Checks if e is a division expression. More...
 
bool is_log (const Expression &e)
 Checks if e is a log expression. More...
 
bool is_abs (const Expression &e)
 Checks if e is an abs expression. More...
 
bool is_exp (const Expression &e)
 Checks if e is an exp expression. More...
 
bool is_sqrt (const Expression &e)
 Checks if e is a square-root expression. More...
 
bool is_pow (const Expression &e)
 Checks if e is a power-function expression. More...
 
bool is_sin (const Expression &e)
 Checks if e is a sine expression. More...
 
bool is_cos (const Expression &e)
 Checks if e is a cosine expression. More...
 
bool is_tan (const Expression &e)
 Checks if e is a tangent expression. More...
 
bool is_asin (const Expression &e)
 Checks if e is an arcsine expression. More...
 
bool is_acos (const Expression &e)
 Checks if e is an arccosine expression. More...
 
bool is_atan (const Expression &e)
 Checks if e is an arctangent expression. More...
 
bool is_atan2 (const Expression &e)
 Checks if e is an arctangent2 expression. More...
 
bool is_sinh (const Expression &e)
 Checks if e is a hyperbolic-sine expression. More...
 
bool is_cosh (const Expression &e)
 Checks if e is a hyperbolic-cosine expression. More...
 
bool is_tanh (const Expression &e)
 Checks if e is a hyperbolic-tangent expression. More...
 
bool is_min (const Expression &e)
 Checks if e is a min expression. More...
 
bool is_max (const Expression &e)
 Checks if e is a max expression. More...
 
bool is_ceil (const Expression &e)
 Checks if e is a ceil expression. More...
 
bool is_floor (const Expression &e)
 Checks if e is a floor expression. More...
 
bool is_if_then_else (const Expression &e)
 Checks if e is an if-then-else expression. More...
 
bool is_uninterpreted_function (const Expression &e)
 Checks if e is an uninterpreted-function expression. More...
 
double get_constant_value (const Expression &e)
 Returns the constant value of the constant expression e. More...
 
const Variable & get_variable (const Expression &e)
 Returns the embedded variable in the variable expression e. More...
 
const Expression & get_argument (const Expression &e)
 Returns the argument in the unary expression e. More...
 
const Expression & get_first_argument (const Expression &e)
 Returns the first argument of the binary expression e. More...
 
const Expression & get_second_argument (const Expression &e)
 Returns the second argument of the binary expression e. More...
 
double get_constant_in_addition (const Expression &e)
 Returns the constant part of the addition expression e. More...
 
const std::map< Expression, double > & get_expr_to_coeff_map_in_addition (const Expression &e)
 Returns the map from an expression to its coefficient in the addition expression e. More...
 
double get_constant_in_multiplication (const Expression &e)
 Returns the constant part of the multiplication expression e. More...
 
const std::map< Expression, Expression > & get_base_to_exponent_map_in_multiplication (const Expression &e)
 Returns the map from a base expression to its exponent expression in the multiplication expression e. More...
 
const std::string & get_uninterpreted_function_name (const Expression &e)
 Returns the name of an uninterpreted-function expression e. More...
 
const std::vector< Expression > & get_uninterpreted_function_arguments (const Expression &e)
 Returns the arguments of an uninterpreted-function expression e. More...
 
const Formula & get_conditional_formula (const Expression &e)
 Returns the conditional formula in the if-then-else expression e. More...
 
const Expression & get_then_expression (const Expression &e)
 Returns the 'then' expression in the if-then-else expression e. More...
 
const Expression & get_else_expression (const Expression &e)
 Returns the 'else' expression in the if-then-else expression e. More...
 
Expression operator+ (const Variable &var)
 
Expression operator- (const Variable &var)
 
Expression TaylorExpand (const Expression &f, const Environment &a, int order)
 Returns the Taylor series expansion of f around a of order order. More...
 
bool operator!= (const uniform_real_distribution< drake::symbolic::Expression > &lhs, const uniform_real_distribution< drake::symbolic::Expression > &rhs)
 
std::ostream & operator<< (std::ostream &os, const uniform_real_distribution< drake::symbolic::Expression > &d)
 
bool operator!= (const normal_distribution< drake::symbolic::Expression > &lhs, const normal_distribution< drake::symbolic::Expression > &rhs)
 
std::ostream & operator<< (std::ostream &os, const normal_distribution< drake::symbolic::Expression > &d)
 
bool operator!= (const exponential_distribution< drake::symbolic::Expression > &lhs, const exponential_distribution< drake::symbolic::Expression > &rhs)
 
std::ostream & operator<< (std::ostream &os, const exponential_distribution< drake::symbolic::Expression > &d)
 
template<typename MatrixL , typename MatrixR >
std::enable_if< std::is_base_of< Eigen::MatrixBase< MatrixL >, MatrixL >::value &&std::is_base_of< Eigen::MatrixBase< MatrixR >, MatrixR >::value &&std::is_same< typename MatrixL::Scalar, Expression >::value &&std::is_same< typename MatrixR::Scalar, double >::value, Eigen::Matrix< Expression, MatrixL::RowsAtCompileTime, MatrixR::ColsAtCompileTime > >::type operator * (const MatrixL &lhs, const MatrixR &rhs)
 Provides the following seven operations: More...
 
template<typename MatrixL , typename MatrixR >
std::enable_if< std::is_base_of< Eigen::MatrixBase< MatrixL >, MatrixL >::value &&std::is_base_of< Eigen::MatrixBase< MatrixR >, MatrixR >::value &&std::is_same< typename MatrixL::Scalar, double >::value &&std::is_same< typename MatrixR::Scalar, Expression >::value, Eigen::Matrix< Expression, MatrixL::RowsAtCompileTime, MatrixR::ColsAtCompileTime > >::type operator * (const MatrixL &lhs, const MatrixR &rhs)
 Provides the following seven operations: More...
 
template<typename MatrixL , typename MatrixR >
std::enable_if< std::is_base_of< Eigen::MatrixBase< MatrixL >, MatrixL >::value &&std::is_base_of< Eigen::MatrixBase< MatrixR >, MatrixR >::value &&std::is_same< typename MatrixL::Scalar, Expression >::value &&std::is_same< typename MatrixR::Scalar, Variable >::value, Eigen::Matrix< Expression, MatrixL::RowsAtCompileTime, MatrixR::ColsAtCompileTime > >::type operator * (const MatrixL &lhs, const MatrixR &rhs)
 Provides the following seven operations: More...
 
template<typename MatrixL , typename MatrixR >
std::enable_if< std::is_base_of< Eigen::MatrixBase< MatrixL >, MatrixL >::value &&std::is_base_of< Eigen::MatrixBase< MatrixR >, MatrixR >::value &&std::is_same< typename MatrixL::Scalar, Variable >::value &&std::is_same< typename MatrixR::Scalar, Expression >::value, Eigen::Matrix< Expression, MatrixL::RowsAtCompileTime, MatrixR::ColsAtCompileTime > >::type operator * (const MatrixL &lhs, const MatrixR &rhs)
 Provides the following seven operations: More...
 
template<typename MatrixL , typename MatrixR >
std::enable_if< std::is_base_of< Eigen::MatrixBase< MatrixL >, MatrixL >::value &&std::is_base_of< Eigen::MatrixBase< MatrixR >, MatrixR >::value &&std::is_same< typename MatrixL::Scalar, Variable >::value &&std::is_same< typename MatrixR::Scalar, double >::value, Eigen::Matrix< Expression, MatrixL::RowsAtCompileTime, MatrixR::ColsAtCompileTime > >::type operator * (const MatrixL &lhs, const MatrixR &rhs)
 Provides the following seven operations: More...
 
template<typename MatrixL , typename MatrixR >
std::enable_if< std::is_base_of< Eigen::MatrixBase< MatrixL >, MatrixL >::value &&std::is_base_of< Eigen::MatrixBase< MatrixR >, MatrixR >::value &&std::is_same< typename MatrixL::Scalar, double >::value &&std::is_same< typename MatrixR::Scalar, Variable >::value, Eigen::Matrix< Expression, MatrixL::RowsAtCompileTime, MatrixR::ColsAtCompileTime > >::type operator * (const MatrixL &lhs, const MatrixR &rhs)
 Provides the following seven operations: More...
 
template<int Dim, int LhsMode, int RhsMode, int LhsOptions, int RhsOptions>
auto operator * (const Eigen::Transform< Expression, Dim, LhsMode, LhsOptions > &t1, const Eigen::Transform< double, Dim, RhsMode, RhsOptions > &t2)
 Transform<double> * Transform<Expression> => Transform<Expression> More...
 
template<int Dim, int LhsMode, int RhsMode, int LhsOptions, int RhsOptions>
auto operator * (const Eigen::Transform< double, Dim, LhsMode, LhsOptions > &t1, const Eigen::Transform< Expression, Dim, RhsMode, RhsOptions > &t2)
 Transform<Expression> * Transform<double> => Transform<Expression> More...
 
template<typename Derived >
std::enable_if_t< std::is_same< typename Derived::Scalar, Expression >::value, Eigen::Matrix< double, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime, 0, Derived::MaxRowsAtCompileTime, Derived::MaxColsAtCompileTime > > Evaluate (const Eigen::MatrixBase< Derived > &m, const Environment &env=Environment{}, RandomGenerator *random_generator=nullptr)
 Evaluates a symbolic matrix m using env and random_generator. More...
 
Eigen::SparseMatrix< double > Evaluate (const Eigen::Ref< const Eigen::SparseMatrix< Expression >> &m, const Environment &env=Environment{})
 Evaluates m using a given environment (by default, an empty environment). More...
 
template<typename Derived >
Eigen::Matrix< Expression, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime, 0, Derived::MaxRowsAtCompileTime, Derived::MaxColsAtCompileTime > Substitute (const Eigen::MatrixBase< Derived > &m, const Substitution &subst)
 Substitutes a symbolic matrix m using a given substitution subst. More...
 
template<typename Derived >
Eigen::Matrix< Expression, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime, 0, Derived::MaxRowsAtCompileTime, Derived::MaxColsAtCompileTime > Substitute (const Eigen::MatrixBase< Derived > &m, const Variable &var, const Expression &e)
 Substitutes var with e in a symbolic matrix m. More...
 
VectorX< Variable > GetVariableVector (const Eigen::Ref< const VectorX< Expression >> &expressions)
 Constructs a vector of variables from the vector of variable expressions. More...
 
MatrixX< Expression > Jacobian (const Eigen::Ref< const VectorX< Expression >> &f, const std::vector< Variable > &vars)
 Computes the Jacobian matrix J of the vector function f with respect to vars. More...
 
MatrixX< Expression > Jacobian (const Eigen::Ref< const VectorX< Expression >> &f, const Eigen::Ref< const VectorX< Variable >> &vars)
 Computes the Jacobian matrix J of the vector function f with respect to vars. More...
 
bool IsAffine (const Eigen::Ref< const MatrixX< Expression >> &m, const Variables &vars)
 Checks if every element in m is affine in vars. More...
 
bool IsAffine (const Eigen::Ref< const MatrixX< Expression >> &m)
 Checks if every element in m is affine. More...
 
Variables GetDistinctVariables (const Eigen::Ref< const MatrixX< Expression >> &v)
 Returns the distinct variables in the matrix of expressions. More...
 
template<typename DerivedA , typename DerivedB >
std::enable_if< std::is_base_of< Eigen::MatrixBase< DerivedA >, DerivedA >::value &&std::is_base_of< Eigen::MatrixBase< DerivedB >, DerivedB >::value &&std::is_same< typename DerivedA::Scalar, Expression >::value &&std::is_same< typename DerivedB::Scalar, Expression >::value, bool >::type CheckStructuralEquality (const DerivedA &m1, const DerivedB &m2)
 Checks if two Eigen::Matrix<Expression> m1 and m2 are structurally equal. More...
 
template<typename... Rest>
symbolic::Expression cond (const symbolic::Formula &f_cond, double v_then, Rest... rest)
 Provides specialization of cond function defined in drake/common/cond.h file. More...
 
double ExtractDoubleOrThrow (const symbolic::Expression &e)
 Returns the symbolic expression's value() as a double. More...
 

Function Documentation

◆ operator!=() [1/3]

bool std::operator!= ( const uniform_real_distribution< drake::symbolic::Expression > &  lhs,
const uniform_real_distribution< drake::symbolic::Expression > &  rhs 
)

◆ operator!=() [2/3]

bool std::operator!= ( const normal_distribution< drake::symbolic::Expression > &  lhs,
const normal_distribution< drake::symbolic::Expression > &  rhs 
)

◆ operator!=() [3/3]

bool std::operator!= ( const exponential_distribution< drake::symbolic::Expression > &  lhs,
const exponential_distribution< drake::symbolic::Expression > &  rhs 
)

◆ operator<<() [1/3]

std::ostream& std::operator<< ( std::ostream &  os,
const uniform_real_distribution< drake::symbolic::Expression > &  d 
)

◆ operator<<() [2/3]

std::ostream& std::operator<< ( std::ostream &  os,
const normal_distribution< drake::symbolic::Expression > &  d 
)

◆ operator<<() [3/3]

std::ostream& std::operator<< ( std::ostream &  os,
const exponential_distribution< drake::symbolic::Expression > &  d 
)