11#include <unordered_map>
15#include "dlinear/libs/libgmp.h"
16#include "dlinear/symbolic/hash.h"
17#include "dlinear/symbolic/symbolic_environment.h"
18#include "dlinear/symbolic/symbolic_variable.h"
19#include "dlinear/symbolic/symbolic_variables.h"
21namespace dlinear::drake {
25enum class ExpressionKind {
51 UninterpretedFunction,
56bool operator<(ExpressionKind k1, ExpressionKind k2);
59class ExpressionConstant;
62class UnaryExpressionCell;
63class BinaryExpressionCell;
84class ExpressionIfThenElse;
85class ExpressionUninterpretedFunction;
92using ExpressionSubstitution = std::unordered_map<Variable, Expression, hash_value<Variable>>;
97using FormulaSubstitution = std::unordered_map<Variable, Formula, hash_value<Variable>>;
278 const FormulaSubstitution &formula_subst)
const;
305 std::string to_smt2_string()
const;
429 friend std::ostream &operator<<(std::ostream &os,
const Expression &e);
537Expression Sum(
const std::vector<Expression> &expressions);
541Expression Prod(
const std::vector<Expression> &expressions);
575std::ostream &operator<<(std::ostream &os,
const Expression &e);
580bool is_constant(
const Expression &e,
const mpq_class &v);
596bool is_negative_infinity(
const Expression &e);
642bool is_uninterpreted_function(
const Expression &e);
647const mpq_class& get_constant_value(
const Expression &e);
668const mpq_class& get_constant_in_addition(
const Expression &e);
674const std::map<Expression, mpq_class> &get_expr_to_coeff_map_in_addition(
680const mpq_class& get_constant_in_multiplication(
const Expression &e);
686const std::map<Expression, Expression> &
687get_base_to_exponent_map_in_multiplication(
const Expression &e);
707const std::string &get_uninterpreted_function_name(
const Expression &e);
720struct less<
dlinear::drake::symbolic::Expression> {
723 return lhs.
Less(rhs);
729struct equal_to<
dlinear::drake::symbolic::Expression> {
737struct hash<
dlinear::drake::symbolic::Expression> {
745struct numeric_limits<
dlinear::drake::symbolic::Expression>
746 :
public numeric_limits<mpq_class> {
747 static const bool has_infinity =
true;
748 static mpq_class infinity();
Represents the base class for binary expressions.
Represents a symbolic environment (mapping from a variable to a value).
Symbolic expression representing absolute value function.
Symbolic expression representing arccosine function.
Factory class to help build ExpressionAdd expressions.
Symbolic expression representing an addition which is a sum of products.
Symbolic expression representing arcsine function.
Symbolic expression representing atan2 function (arctangent function with two arguments).
Symbolic expression representing arctangent function.
Represents an abstract class which is the base of concrete symbolic-expression classes.
Symbolic expression representing a rational constant (mpq_class).
Symbolic expression representing cosine function.
Symbolic expression representing hyperbolic cosine function.
Symbolic expression representing division.
Symbolic expression representing exponentiation using the base of natural logarithms.
Symbolic expression representing if-then-else expression.
Symbolic expression representing infinities.
Symbolic expression representing logarithms.
Symbolic expression representing max function.
Symbolic expression representing min function.
Factory class to help build ExpressionMul expressions.
Symbolic expression representing a multiplication of powers.
Symbolic expression representing power function.
Symbolic expression representing sine function.
Symbolic expression representing hyperbolic sine function.
Symbolic expression representing square-root.
Symbolic expression representing tangent function.
Symbolic expression representing hyperbolic tangent function.
Symbolic expression representing an uninterpreted function.
Symbolic expression representing a variable.
Represents a symbolic form of an expression.
size_t get_hash() const
Returns hash value.
friend const ExpressionSin * to_sin(const Expression &e)
Casts e of Expression to const ExpressionSin*.
friend const ExpressionSinh * to_sinh(const Expression &e)
Casts e of Expression to const ExpressionSinh*.
friend const ExpressionSqrt * to_sqrt(const Expression &e)
Casts e of Expression to const ExpressionSqrt*.
friend Expression operator+(const Expression &e)
Provides unary plus operator.
friend bool is_cos(const Expression &e)
Checks if e is a cosine expression.
friend bool is_sin(const Expression &e)
Checks if e is a sine expression.
Expression Substitute(const Variable &var, const Expression &e) const
Returns a copy of this expression replacing all occurrences of var with e.
friend Expression log(const Expression &e)
Creates an real-constant expression represented by [lb, ub].
friend const ExpressionCos * to_cos(const Expression &e)
Casts e of Expression to const ExpressionCos*.
friend const ExpressionUninterpretedFunction * to_uninterpreted_function(const Expression &e)
Casts e of Expression to const ExpressionUninterpretedFunction*.
bool include_ite() const
Returns true if this symbolic expression includes an ITE (If-Then-Else) expression.
friend const ExpressionIfThenElse * to_if_then_else(const Expression &e)
Casts e of Expression to const ExpressionIfThenElse*.
friend bool is_max(const Expression &e)
Checks if e is a max expression.
Expression & operator--()
Provides prefix decrement operator (i.e.
friend bool is_variable(const Expression &e)
Checks if e is a variable expression.
Expression Substitute(const FormulaSubstitution &formula_subst) const
Returns a copy of this expression replacing all occurrences of the variables in formula_subst with co...
friend const BinaryExpressionCell * to_binary(const Expression &e)
Casts e of Expression to const BinaryExpressionCell*.
friend const ExpressionPow * to_pow(const Expression &e)
Casts e of Expression to const ExpressionPow*.
friend const ExpressionAtan2 * to_atan2(const Expression &e)
Casts e of Expression to const ExpressionAtan2*.
friend bool is_acos(const Expression &e)
Checks if e is an arccosine expression.
friend const ExpressionVar * to_variable(const Expression &e)
Casts e of Expression to const ExpressionVar*.
friend const ExpressionMin * to_min(const Expression &e)
Casts e of Expression to const ExpressionMin*.
friend bool is_sinh(const Expression &e)
Checks if e is a hyperbolic-sine expression.
friend bool is_if_then_else(const Expression &e)
Checks if e is an if-then-else expression.
friend const ExpressionCosh * to_cosh(const Expression &e)
Casts e of Expression to const ExpressionCosh*.
friend bool is_asin(const Expression &e)
Checks if e is an arcsine expression.
static Expression Zero()
Returns zero.
Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) const
Returns a copy of this expression replacing all occurrences of the variables in expr_subst with corre...
friend const ExpressionAbs * to_abs(const Expression &e)
Casts e of Expression to const ExpressionAbs*.
friend bool is_addition(const Expression &e)
Checks if e is an addition expression.
bool Less(const Expression &e) const
Provides lexicographical ordering between expressions.
friend const ExpressionExp * to_exp(const Expression &e)
Casts e of Expression to const ExpressionExp*.
static Expression One()
Returns one.
friend bool is_atan2(const Expression &e)
Checks if e is an arctangent2 expression.
ExpressionKind get_kind() const
Returns expression kind.
friend const ExpressionTan * to_tan(const Expression &e)
Casts e of Expression to const ExpressionTan*.
friend const ExpressionDiv * to_division(const Expression &e)
Casts e of Expression to const ExpressionDiv*.
mpq_class Evaluate(const Environment &env=Environment{}) const
Evaluates under a given environment (by default, an empty environment).
static Expression NaN()
Returns NaN (Not-a-Number).
friend const UnaryExpressionCell * to_unary(const Expression &e)
Casts e of Expression to const UnaryExpressionCell*.
friend bool is_exp(const Expression &e)
Checks if e is an exp expression.
Expression operator++(int)
Provides postfix increment operator (i.e.
Expression(const Variable &var)
Constructs an expression from var.
friend bool is_atan(const Expression &e)
Checks if e is an arctangent expression.
friend const ExpressionMax * to_max(const Expression &e)
Casts e of Expression to const ExpressionMax*.
static Expression Infty()
Returns positive infinity.
const Variables & GetVariables() const
Collects variables in expression.
friend const ExpressionTanh * to_tanh(const Expression &e)
Casts e of Expression to const ExpressionTanh*.
friend const ExpressionAdd * to_addition(const Expression &e)
Casts e of Expression to const ExpressionAdd*.
Expression & operator++()
Provides prefix increment operator (i.e.
static Expression NInfty()
Returns negative infinity.
friend const ExpressionConstant * to_constant(const Expression &e)
Casts e of Expression to const ExpressionConstant*.
friend const ExpressionLog * to_log(const Expression &e)
Casts e of Expression to const ExpressionLog*.
friend bool is_uninterpreted_function(const Expression &e)
Checks if e is an uninterpreted-function expression.
Expression(const mpq_class &d)
Constructs a constant (rational).
Expression Expand() const
Expands out products and positive integer powers in expression.
Expression Substitute(const ExpressionSubstitution &expr_subst) const
Returns a copy of this expression replacing all occurrences of the variables in expr_subst with corre...
friend bool is_tan(const Expression &e)
Checks if e is a tangent expression.
static Expression Pi()
Returns Pi, the ratio of a circle’s circumference to its diameter.
friend bool is_pow(const Expression &e)
Checks if e is a power-function expression.
friend Expression uninterpreted_function(const std::string &name, const Variables &vars)
Constructs an uninterpreted-function expression with name and vars.
friend bool is_tanh(const Expression &e)
Checks if e is a hyperbolic-tangent expression.
Expression()
Default constructor.
static Expression E()
Return e, the base of natural logarithms.
friend bool is_log(const Expression &e)
Checks if e is a log expression.
friend bool is_division(const Expression &e)
Checks if e is a division expression.
friend bool is_cosh(const Expression &e)
Checks if e is a hyperbolic-cosine expression.
Expression EvaluatePartial(const Environment &env) const
Partially evaluates this expression using an environment env.
Expression Differentiate(const Variable &x) const
Differentiates this symbolic expression with respect to the variable var.
friend bool is_abs(const Expression &e)
Checks if e is an abs expression.
friend ExpressionAdd * to_addition(Expression &e)
Casts e of Expression to ExpressionAdd*.
friend const ExpressionMul * to_multiplication(const Expression &e)
Casts e of Expression to const ExpressionMul*.
friend ExpressionMul * to_multiplication(Expression &e)
Casts e of Expression to ExpressionMul*.
friend const ExpressionInfty * to_infty(const Expression &e)
Casts e of Expression to const ExpressionInfty*.
std::string to_string() const
Returns string representation of Expression.
Expression operator--(int)
Provides postfix decrement operator (i.e.
friend const ExpressionAcos * to_acos(const Expression &e)
Casts e of Expression to const ExpressionAcos*.
friend bool is_constant(const Expression &e)
Checks if e is a rational constant expression.
friend bool is_min(const Expression &e)
Checks if e is a min expression.
friend bool is_multiplication(const Expression &e)
Checks if e is a multiplication expression.
bool is_polynomial() const
Checks if this symbolic expression is convertible to Polynomial.
friend Expression operator-(const Expression &e)
Provides unary minus operator.
friend bool is_sqrt(const Expression &e)
Checks if e is a square-root expression.
bool EqualTo(const Expression &e) const
Checks structural equality.
friend Expression if_then_else(const Formula &f_cond, const Expression &e_then, const Expression &e_else)
Constructs if-then-else expression.
friend const ExpressionAsin * to_asin(const Expression &e)
Casts e of Expression to const ExpressionAsin*.
friend const ExpressionAtan * to_atan(const Expression &e)
Casts e of Expression to const ExpressionAtan*.
Represents the base class for unary expressions.
Represents a symbolic variable.
Represents a set of variables.
Global namespace for the dlinear library.
LpColBound operator-(LpColBound bound)
Invert the bound with delta > 0.