Drake
Drake C++ Documentation
Loading...
Searching...
No Matches
expression.h File Reference
#include <algorithm>
#include <cmath>
#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/dummy_value.h"
#include "drake/common/eigen_types.h"
#include "drake/common/extract_double.h"
#include "drake/common/fmt.h"
#include "drake/common/hash.h"
#include "drake/common/random.h"
Include dependency graph for 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

namespace  drake
namespace  drake::symbolic
namespace  std
 STL namespace.

Typedefs

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

Functions

Expression operator+ (Expression lhs, const Expression &rhs)
Expressionoperator+= (Expression &lhs, const Expression &rhs)
Expression operator+ (const Expression &e)
Expression operator- (Expression lhs, const Expression &rhs)
Expressionoperator-= (Expression &lhs, const Expression &rhs)
Expression operator- (const Expression &e)
Expression operator* (Expression lhs, const Expression &rhs)
Expressionoperator*= (Expression &lhs, const Expression &rhs)
Expression operator/ (Expression lhs, const Expression &rhs)
Expressionoperator/= (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 clamp (const Expression &v, const Expression &lo, const Expression &hi)
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.
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.
bool is_constant (const Expression &e, double v)
 Checks if e is a constant expression representing v.
bool is_zero (const Expression &e)
 Checks if e is 0.0.
bool is_one (const Expression &e)
 Checks if e is 1.0.
bool is_neg_one (const Expression &e)
 Checks if e is -1.0.
bool is_two (const Expression &e)
 Checks if e is 2.0.
bool is_nan (const Expression &e)
 Checks if e is NaN.
bool is_variable (const Expression &e)
 Checks if e is a variable expression.
bool is_addition (const Expression &e)
 Checks if e is an addition expression.
bool is_multiplication (const Expression &e)
 Checks if e is a multiplication expression.
bool is_division (const Expression &e)
 Checks if e is a division expression.
bool is_log (const Expression &e)
 Checks if e is a log expression.
bool is_abs (const Expression &e)
 Checks if e is an abs expression.
bool is_exp (const Expression &e)
 Checks if e is an exp expression.
bool is_sqrt (const Expression &e)
 Checks if e is a square-root expression.
bool is_pow (const Expression &e)
 Checks if e is a power-function expression.
bool is_sin (const Expression &e)
 Checks if e is a sine expression.
bool is_cos (const Expression &e)
 Checks if e is a cosine expression.
bool is_tan (const Expression &e)
 Checks if e is a tangent expression.
bool is_asin (const Expression &e)
 Checks if e is an arcsine expression.
bool is_acos (const Expression &e)
 Checks if e is an arccosine expression.
bool is_atan (const Expression &e)
 Checks if e is an arctangent expression.
bool is_atan2 (const Expression &e)
 Checks if e is an arctangent2 expression.
bool is_sinh (const Expression &e)
 Checks if e is a hyperbolic-sine expression.
bool is_cosh (const Expression &e)
 Checks if e is a hyperbolic-cosine expression.
bool is_tanh (const Expression &e)
 Checks if e is a hyperbolic-tangent expression.
bool is_min (const Expression &e)
 Checks if e is a min expression.
bool is_max (const Expression &e)
 Checks if e is a max expression.
bool is_ceil (const Expression &e)
 Checks if e is a ceil expression.
bool is_floor (const Expression &e)
 Checks if e is a floor expression.
bool is_if_then_else (const Expression &e)
 Checks if e is an if-then-else expression.
bool is_uninterpreted_function (const Expression &e)
 Checks if e is an uninterpreted-function expression.
double get_constant_value (const Expression &e)
 Returns the constant value of the constant expression e.
const Variableget_variable (const Expression &e)
 Returns the embedded variable in the variable expression e.
const Expressionget_argument (const Expression &e)
 Returns the argument in the unary expression e.
const Expressionget_first_argument (const Expression &e)
 Returns the first argument of the binary expression e.
const Expressionget_second_argument (const Expression &e)
 Returns the second argument of the binary expression e.
double get_constant_in_addition (const Expression &e)
 Returns the constant part of the addition expression e.
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.
double get_constant_in_multiplication (const Expression &e)
 Returns the constant part of the multiplication expression e.
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.
const std::string & get_uninterpreted_function_name (const Expression &e)
 Returns the name of an uninterpreted-function expression e.
const std::vector< Expression > & get_uninterpreted_function_arguments (const Expression &e)
 Returns the arguments of an uninterpreted-function expression e.
const Formulaget_conditional_formula (const Expression &e)
 Returns the conditional formula in the if-then-else expression e.
const Expressionget_then_expression (const Expression &e)
 Returns the 'then' expression in the if-then-else expression e.
const Expressionget_else_expression (const Expression &e)
 Returns the 'else' expression in the if-then-else expression e.
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.
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_t< std::is_base_of_v< Eigen::MatrixBase< MatrixL >, MatrixL > &&std::is_base_of_v< Eigen::MatrixBase< MatrixR >, MatrixR > &&std::is_same_v< typename MatrixL::Scalar, Expression > &&std::is_same_v< typename MatrixR::Scalar, double >, internal::ExpressionMatMulResult< MatrixL, MatrixR > > operator* (const MatrixL &lhs, const MatrixR &rhs)
 Provides the following matrix operations:
template<typename MatrixL, typename MatrixR>
std::enable_if_t< std::is_base_of_v< Eigen::MatrixBase< MatrixL >, MatrixL > &&std::is_base_of_v< Eigen::MatrixBase< MatrixR >, MatrixR > &&std::is_same_v< typename MatrixL::Scalar, double > &&std::is_same_v< typename MatrixR::Scalar, Expression >, internal::ExpressionMatMulResult< MatrixL, MatrixR > > operator* (const MatrixL &lhs, const MatrixR &rhs)
 Provides the following matrix operations:
template<typename MatrixL, typename MatrixR>
std::enable_if_t< std::is_base_of_v< Eigen::MatrixBase< MatrixL >, MatrixL > &&std::is_base_of_v< Eigen::MatrixBase< MatrixR >, MatrixR > &&std::is_same_v< typename MatrixL::Scalar, Expression > &&std::is_same_v< typename MatrixR::Scalar, Variable >, internal::ExpressionMatMulResult< MatrixL, MatrixR > > operator* (const MatrixL &lhs, const MatrixR &rhs)
 Provides the following matrix operations:
template<typename MatrixL, typename MatrixR>
std::enable_if_t< std::is_base_of_v< Eigen::MatrixBase< MatrixL >, MatrixL > &&std::is_base_of_v< Eigen::MatrixBase< MatrixR >, MatrixR > &&std::is_same_v< typename MatrixL::Scalar, Variable > &&std::is_same_v< typename MatrixR::Scalar, Expression >, internal::ExpressionMatMulResult< MatrixL, MatrixR > > operator* (const MatrixL &lhs, const MatrixR &rhs)
 Provides the following matrix operations:
template<typename MatrixL, typename MatrixR>
std::enable_if_t< std::is_base_of_v< Eigen::MatrixBase< MatrixL >, MatrixL > &&std::is_base_of_v< Eigen::MatrixBase< MatrixR >, MatrixR > &&std::is_same_v< typename MatrixL::Scalar, Variable > &&std::is_same_v< typename MatrixR::Scalar, double >, internal::ExpressionMatMulResult< MatrixL, MatrixR > > operator* (const MatrixL &lhs, const MatrixR &rhs)
 Provides the following matrix operations:
template<typename MatrixL, typename MatrixR>
std::enable_if_t< std::is_base_of_v< Eigen::MatrixBase< MatrixL >, MatrixL > &&std::is_base_of_v< Eigen::MatrixBase< MatrixR >, MatrixR > &&std::is_same_v< typename MatrixL::Scalar, double > &&std::is_same_v< typename MatrixR::Scalar, Variable >, internal::ExpressionMatMulResult< MatrixL, MatrixR > > operator* (const MatrixL &lhs, const MatrixR &rhs)
 Provides the following matrix operations:
template<typename MatrixL, typename MatrixR>
std::enable_if_t< std::is_base_of_v< Eigen::MatrixBase< MatrixL >, MatrixL > &&std::is_base_of_v< Eigen::MatrixBase< MatrixR >, MatrixR > &&std::is_same_v< typename MatrixL::Scalar, Variable > &&std::is_same_v< typename MatrixR::Scalar, Variable >, internal::ExpressionMatMulResult< MatrixL, MatrixR > > operator* (const MatrixL &lhs, const MatrixR &rhs)
 Provides the following matrix operations:
template<typename MatrixL, typename MatrixR>
std::enable_if_t< std::is_base_of_v< Eigen::MatrixBase< MatrixL >, MatrixL > &&std::is_base_of_v< Eigen::MatrixBase< MatrixR >, MatrixR > &&std::is_same_v< typename MatrixL::Scalar, Expression > &&std::is_same_v< typename MatrixR::Scalar, Expression >, internal::ExpressionMatMulResult< MatrixL, MatrixR > > operator* (const MatrixL &lhs, const MatrixR &rhs)
 Provides the following matrix operations:
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>
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>
template<typename Derived>
std::enable_if_t< std::is_same_v< typename Derived::Scalar, Expression >, MatrixLikewise< double, Derived > > Evaluate (const Eigen::MatrixBase< Derived > &m, const Environment &env=Environment{}, RandomGenerator *random_generator=nullptr)
 Evaluates a symbolic matrix m using env and random_generator.
Eigen::SparseMatrix< doubleEvaluate (const Eigen::Ref< const Eigen::SparseMatrix< Expression > > &m, const Environment &env=Environment{})
 Evaluates m using a given environment (by default, an empty environment).
template<typename Derived>
MatrixLikewise< Expression, Derived > Substitute (const Eigen::MatrixBase< Derived > &m, const Substitution &subst)
 Substitutes a symbolic matrix m using a given substitution subst.
template<typename Derived>
MatrixLikewise< Expression, Derived > Substitute (const Eigen::MatrixBase< Derived > &m, const Variable &var, const Expression &e)
 Substitutes var with e in a symbolic matrix m.
VectorX< VariableGetVariableVector (const Eigen::Ref< const VectorX< Expression > > &expressions)
 Constructs a vector of variables from the vector of variable expressions.
MatrixX< ExpressionJacobian (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.
MatrixX< ExpressionJacobian (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.
Variables GetDistinctVariables (const Eigen::Ref< const MatrixX< Expression > > &v)
 Returns the distinct variables in the matrix of expressions.
template<typename DerivedA, typename DerivedB>
std::enable_if_t< std::is_base_of_v< Eigen::MatrixBase< DerivedA >, DerivedA > &&std::is_base_of_v< Eigen::MatrixBase< DerivedB >, DerivedB > &&std::is_same_v< typename DerivedA::Scalar, Expression > &&std::is_same_v< typename DerivedB::Scalar, Expression >, bool > CheckStructuralEquality (const DerivedA &m1, const DerivedB &m2)
 Checks if two Eigen::Matrix<Expression> m1 and m2 are structurally equal.
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.
double ExtractDoubleOrThrow (const symbolic::Expression &e)
 Returns the symbolic expression's value() as a double.
template<typename Derived>
std::enable_if_t< std::is_same_v< typename Derived::Scalar, symbolic::Expression >, MatrixLikewise< double, Derived > > ExtractDoubleOrThrow (const Eigen::MatrixBase< Derived > &matrix)
 Returns matrix as an Eigen::Matrix<double, ...> with the same size allocation as matrix.