11#include "dlinear/libs/libgmp.h"
12#include "dlinear/symbolic/symbolic_environment.h"
13#include "dlinear/symbolic/symbolic_expression.h"
14#include "dlinear/symbolic/symbolic_formula.h"
15#include "dlinear/symbolic/symbolic_variable.h"
16#include "dlinear/symbolic/symbolic_variables.h"
18namespace dlinear::drake::symbolic {
29 ExpressionKind
get_kind()
const {
return kind_; }
65 virtual Expression Substitute(
const ExpressionSubstitution &expr_subst,
const FormulaSubstitution &formula_subst) = 0;
74 virtual std::ostream &
Display(std::ostream &os)
const = 0;
76 virtual std::string to_smt2_string()
const = 0;
79#ifdef DLINEAR_ENABLED_THREADS
80 unsigned use_count()
const {
return atomic_load_explicit(&rc_, std::memory_order_acquire); }
120 virtual void ComputeVariables(std::optional<Variables>& variables)
const;
121 virtual void ComputeHash(std::optional<size_t>& hash)
const;
122 virtual void ComputeIsPolynomial(std::optional<bool>&
is_polynomial)
const;
123 virtual void ComputeIncludeIte(std::optional<bool>&
include_ite)
const;
128 const ExpressionKind kind_{};
130 mutable std::optional<size_t> hash_{};
131 mutable std::optional<bool> is_polynomial_{
false};
132 mutable std::optional<bool> include_ite_{
false};
135#ifdef DLINEAR_ENABLED_THREADS
136 mutable std::atomic<unsigned> rc_{0};
137 void increase_rc()
const { atomic_fetch_add_explicit(&rc_, 1U, std::memory_order_relaxed); }
138 void decrease_rc()
const {
139 if (atomic_fetch_sub_explicit(&rc_, 1U, std::memory_order_acq_rel) == 1U) {
144 mutable unsigned rc_{0};
145 void increase_rc()
const { ++rc_; }
146 void decrease_rc()
const {
194 void ComputeHash(std::optional<size_t>& hash)
const override;
195 void ComputeVariables(std::optional<Variables>& variables)
const override;
196 void ComputeIncludeIte(std::optional<bool>&
include_ite)
const override;
235 virtual mpq_class
DoEvaluate(
const mpq_class &v1,
const mpq_class &v2)
const = 0;
241 void ComputeHash(std::optional<size_t>& hash)
const override;
242 void ComputeVariables(std::optional<Variables>& variables)
const override;
243 void ComputeIncludeIte(std::optional<bool>&
include_ite)
const override;
253 const Variable &get_variable()
const {
return var_; }
258 Expression Substitute(
const ExpressionSubstitution &expr_subst,
const FormulaSubstitution &formula_subst)
override;
260 std::ostream &
Display(std::ostream &os)
const override;
265 void ComputeHash(std::optional<size_t>& hash)
const override;
266 std::string to_smt2_string()
const override;
273 const mpq_class& get_value()
const {
return v_; }
278 Expression Substitute(
const ExpressionSubstitution &expr_subst,
const FormulaSubstitution &formula_subst)
override;
280 std::ostream &
Display(std::ostream &os)
const override;
281 std::string to_smt2_string()
const override;
285 const mpq_class v_{};
287 virtual void ComputeHash(std::optional<size_t>& hash)
const;
298 Expression Substitute(
const ExpressionSubstitution &expr_subst,
const FormulaSubstitution &formula_subst)
override;
300 std::ostream &
Display(std::ostream &os)
const override;
301 std::string to_smt2_string()
const override;
312 Expression Substitute(
const ExpressionSubstitution &expr_subst,
const FormulaSubstitution &formula_subst)
override;
314 std::ostream &
Display(std::ostream &os)
const override;
315 std::string to_smt2_string()
const override;
316 int GetSign()
const {
return sign_; }
339 ExpressionAdd(
const mpq_class &constant, std::map<Expression, mpq_class> expr_to_coeff_map);
344 Expression Substitute(
const ExpressionSubstitution &expr_subst,
const FormulaSubstitution &formula_subst)
override;
346 std::ostream &
Display(std::ostream &os)
const override;
347 std::string to_smt2_string()
const override;
355 mpq_class &get_mutable_constant() {
return constant_; }
362 void ComputeVariables(std::optional<Variables>& variables)
const override;
363 void ComputeHash(std::optional<size_t>& hash)
const override;
364 void ComputeIsPolynomial(std::optional<bool>&
is_polynomial)
const override;
365 void ComputeIncludeIte(std::optional<bool>&
include_ite)
const override;
366 std::ostream &DisplayTerm(std::ostream &os,
bool print_plus,
const mpq_class &coeff,
const Expression &term)
const;
368 mpq_class constant_{};
369 std::map<Expression, mpq_class> expr_to_coeff_map_;
394 ExpressionAddFactory(mpq_class&& constant, std::map<Expression, mpq_class>&& expr_to_coeff_map);
437 bool get_expression_is_called_{
false};
438 mpq_class constant_{0.0};
439 std::map<Expression, mpq_class> expr_to_coeff_map_;
458 ExpressionMul(
const mpq_class &constant, std::map<Expression, Expression> base_to_exponent_map);
463 Expression Substitute(
const ExpressionSubstitution &expr_subst,
const FormulaSubstitution &formula_subst)
override;
465 std::ostream &
Display(std::ostream &os)
const override;
466 std::string to_smt2_string()
const override;
474 mpq_class &get_mutable_constant() {
return constant_; }
479 void ComputeVariables(std::optional<Variables>& variables)
const override;
480 void ComputeHash(std::optional<size_t>& hash)
const override;
481 void ComputeIsPolynomial(std::optional<bool>&
is_polynomial)
const override;
482 void ComputeIncludeIte(std::optional<bool>&
include_ite)
const override;
484 std::ostream &DisplayTerm(std::ostream &os,
bool print_mul,
const Expression &base,
const Expression &exponent)
const;
486 mpq_class constant_{};
487 std::map<Expression, Expression> base_to_exponent_map_;
555 bool get_expression_is_called_{
false};
556 mpq_class constant_{1.0};
557 std::map<Expression, Expression> base_to_exponent_map_;
565 Expression Substitute(
const ExpressionSubstitution &expr_subst,
const FormulaSubstitution &formula_subst)
override;
567 std::ostream &
Display(std::ostream &os)
const override;
568 std::string to_smt2_string()
const override;
571 mpq_class
DoEvaluate(
const mpq_class &v1,
const mpq_class &v2)
const override;
579 Expression Substitute(
const ExpressionSubstitution &expr_subst,
const FormulaSubstitution &formula_subst)
override;
581 std::ostream &
Display(std::ostream &os)
const override;
582 std::string to_smt2_string()
const override;
588 static void check_domain(
const mpq_class &v);
597 Expression Substitute(
const ExpressionSubstitution &expr_subst,
const FormulaSubstitution &formula_subst)
override;
599 std::ostream &
Display(std::ostream &os)
const override;
600 std::string to_smt2_string()
const override;
614 Expression Substitute(
const ExpressionSubstitution &expr_subst,
const FormulaSubstitution &formula_subst)
override;
616 std::ostream &
Display(std::ostream &os)
const override;
617 std::string to_smt2_string()
const override;
628 Expression Substitute(
const ExpressionSubstitution &expr_subst,
const FormulaSubstitution &formula_subst)
override;
630 std::ostream &
Display(std::ostream &os)
const override;
631 std::string to_smt2_string()
const override;
637 static void check_domain(
const mpq_class &v);
646 Expression Substitute(
const ExpressionSubstitution &expr_subst,
const FormulaSubstitution &formula_subst)
override;
648 std::ostream &
Display(std::ostream &os)
const override;
649 std::string to_smt2_string()
const override;
656 static void check_domain(
const mpq_class &v1,
const mpq_class &v2);
657 mpq_class
DoEvaluate(
const mpq_class &v1,
const mpq_class &v2)
const override;
665 Expression Substitute(
const ExpressionSubstitution &expr_subst,
const FormulaSubstitution &formula_subst)
override;
667 std::ostream &
Display(std::ostream &os)
const override;
668 std::string to_smt2_string()
const override;
679 Expression Substitute(
const ExpressionSubstitution &expr_subst,
const FormulaSubstitution &formula_subst)
override;
681 std::ostream &
Display(std::ostream &os)
const override;
682 std::string to_smt2_string()
const override;
693 Expression Substitute(
const ExpressionSubstitution &expr_subst,
const FormulaSubstitution &formula_subst)
override;
695 std::ostream &
Display(std::ostream &os)
const override;
696 std::string to_smt2_string()
const override;
707 Expression Substitute(
const ExpressionSubstitution &expr_subst,
const FormulaSubstitution &formula_subst)
override;
709 std::ostream &
Display(std::ostream &os)
const override;
710 std::string to_smt2_string()
const override;
716 static void check_domain(
const mpq_class &v);
725 Expression Substitute(
const ExpressionSubstitution &expr_subst,
const FormulaSubstitution &formula_subst)
override;
727 std::ostream &
Display(std::ostream &os)
const override;
728 std::string to_smt2_string()
const override;
734 static void check_domain(
const mpq_class &v);
743 Expression Substitute(
const ExpressionSubstitution &expr_subst,
const FormulaSubstitution &formula_subst)
override;
745 std::ostream &
Display(std::ostream &os)
const override;
746 std::string to_smt2_string()
const override;
758 Expression Substitute(
const ExpressionSubstitution &expr_subst,
const FormulaSubstitution &formula_subst)
override;
760 std::ostream &
Display(std::ostream &os)
const override;
761 std::string to_smt2_string()
const override;
764 mpq_class
DoEvaluate(
const mpq_class &v1,
const mpq_class &v2)
const override;
772 Expression Substitute(
const ExpressionSubstitution &expr_subst,
const FormulaSubstitution &formula_subst)
override;
774 std::ostream &
Display(std::ostream &os)
const override;
775 std::string to_smt2_string()
const override;
786 Expression Substitute(
const ExpressionSubstitution &expr_subst,
const FormulaSubstitution &formula_subst)
override;
788 std::ostream &
Display(std::ostream &os)
const override;
789 std::string to_smt2_string()
const override;
800 Expression Substitute(
const ExpressionSubstitution &expr_subst,
const FormulaSubstitution &formula_subst)
override;
802 std::ostream &
Display(std::ostream &os)
const override;
803 std::string to_smt2_string()
const override;
814 Expression Substitute(
const ExpressionSubstitution &expr_subst,
const FormulaSubstitution &formula_subst)
override;
816 std::ostream &
Display(std::ostream &os)
const override;
817 std::string to_smt2_string()
const override;
820 mpq_class
DoEvaluate(
const mpq_class &v1,
const mpq_class &v2)
const override;
828 Expression Substitute(
const ExpressionSubstitution &expr_subst,
const FormulaSubstitution &formula_subst)
override;
830 std::ostream &
Display(std::ostream &os)
const override;
831 std::string to_smt2_string()
const override;
834 mpq_class
DoEvaluate(
const mpq_class &v1,
const mpq_class &v2)
const override;
847 Expression Substitute(
const ExpressionSubstitution &expr_subst,
const FormulaSubstitution &formula_subst)
override;
849 std::ostream &
Display(std::ostream &os)
const override;
850 std::string to_smt2_string()
const override;
860 void ComputeVariables(std::optional<Variables>& variables)
const override;
861 void ComputeHash(std::optional<size_t>& hash)
const override;
878 Expression Substitute(
const ExpressionSubstitution &expr_subst,
const FormulaSubstitution &formula_subst)
override;
880 std::ostream &
Display(std::ostream &os)
const override;
881 std::string to_smt2_string()
const override;
884 const std::string &
get_name()
const {
return name_; }
887 const std::string name_;
890 void ComputeHash(std::optional<size_t>& hash)
const override;
894bool is_constant(
const ExpressionCell &c);
896bool is_infinite(
const ExpressionCell &c);
898bool is_variable(
const ExpressionCell &c);
900bool is_addition(
const ExpressionCell &c);
902bool is_multiplication(
const ExpressionCell &c);
904bool is_division(
const ExpressionCell &c);
906bool is_log(
const ExpressionCell &c);
908bool is_abs(
const ExpressionCell &c);
910bool is_exp(
const ExpressionCell &c);
912bool is_sqrt(
const ExpressionCell &c);
914bool is_pow(
const ExpressionCell &c);
916bool is_sin(
const ExpressionCell &c);
918bool is_cos(
const ExpressionCell &c);
920bool is_tan(
const ExpressionCell &c);
922bool is_asin(
const ExpressionCell &c);
924bool is_acos(
const ExpressionCell &c);
926bool is_atan(
const ExpressionCell &c);
928bool is_atan2(
const ExpressionCell &c);
930bool is_sinh(
const ExpressionCell &c);
932bool is_cosh(
const ExpressionCell &c);
934bool is_tanh(
const ExpressionCell &c);
936bool is_min(
const ExpressionCell &c);
938bool is_max(
const ExpressionCell &c);
940bool is_if_then_else(
const ExpressionCell &c);
942bool is_uninterpreted_function(
const ExpressionCell &c);
948const ExpressionConstant *to_constant(
const ExpressionCell *expr_ptr);
952const ExpressionConstant *to_constant(
const Expression &e);
958const ExpressionInfty *to_infty(
const ExpressionCell *expr_ptr);
962const ExpressionInfty *to_infty(
const Expression &e);
968const ExpressionVar *to_variable(
const ExpressionCell *expr_ptr);
972const ExpressionVar *to_variable(
const Expression &e);
978const UnaryExpressionCell *to_unary(
const ExpressionCell *expr_ptr);
982const UnaryExpressionCell *to_unary(
const Expression &e);
988const BinaryExpressionCell *to_binary(
const ExpressionCell *expr_ptr);
992const BinaryExpressionCell *to_binary(
const Expression &e);
998const ExpressionAdd *to_addition(
const ExpressionCell *expr_ptr);
1002const ExpressionAdd *to_addition(
const Expression &e);
1006ExpressionAdd *to_addition(ExpressionCell *expr_ptr);
1016const ExpressionMul *to_multiplication(
const ExpressionCell *expr_ptr);
1020const ExpressionMul *to_multiplication(
const Expression &e);
1024ExpressionMul *to_multiplication(ExpressionCell *expr_ptr);
1028ExpressionMul *to_multiplication(
Expression &e);
1034const ExpressionDiv *to_division(
const ExpressionCell *expr_ptr);
1038const ExpressionDiv *to_division(
const Expression &e);
1044const ExpressionLog *to_log(
const ExpressionCell *expr_ptr);
1048const ExpressionLog *to_log(
const Expression &e);
1054const ExpressionExp *to_exp(
const ExpressionCell *expr_ptr);
1058const ExpressionExp *to_exp(
const Expression &e);
1064const ExpressionAbs *to_abs(
const ExpressionCell *expr_ptr);
1068const ExpressionAbs *to_abs(
const Expression &e);
1074const ExpressionExp *to_exp(
const ExpressionCell *expr_ptr);
1078const ExpressionExp *to_exp(
const Expression &e);
1084const ExpressionSqrt *to_sqrt(
const ExpressionCell *expr_ptr);
1088const ExpressionSqrt *to_sqrt(
const Expression &e);
1094const ExpressionPow *to_pow(
const ExpressionCell *expr_ptr);
1098const ExpressionPow *to_pow(
const Expression &e);
1104const ExpressionSin *to_sin(
const ExpressionCell *expr_ptr);
1108const ExpressionSin *to_sin(
const Expression &e);
1114const ExpressionCos *to_cos(
const ExpressionCell *expr_ptr);
1118const ExpressionCos *to_cos(
const Expression &e);
1124const ExpressionTan *to_tan(
const ExpressionCell *expr_ptr);
1128const ExpressionTan *to_tan(
const Expression &e);
1134const ExpressionAsin *to_asin(
const ExpressionCell *expr_ptr);
1138const ExpressionAsin *to_asin(
const Expression &e);
1144const ExpressionAcos *to_acos(
const ExpressionCell *expr_ptr);
1148const ExpressionAcos *to_acos(
const Expression &e);
1154const ExpressionAtan *to_atan(
const ExpressionCell *expr_ptr);
1158const ExpressionAtan *to_atan(
const Expression &e);
1164const ExpressionAtan2 *to_atan2(
const ExpressionCell *expr_ptr);
1168const ExpressionAtan2 *to_atan2(
const Expression &e);
1174const ExpressionSinh *to_sinh(
const ExpressionCell *expr_ptr);
1178const ExpressionSinh *to_sinh(
const Expression &e);
1184const ExpressionCosh *to_cosh(
const ExpressionCell *expr_ptr);
1188const ExpressionCosh *to_cosh(
const Expression &e);
1194const ExpressionTanh *to_tanh(
const ExpressionCell *expr_ptr);
1198const ExpressionTanh *to_tanh(
const Expression &e);
1204const ExpressionMin *to_min(
const ExpressionCell *expr_ptr);
1208const ExpressionMin *to_min(
const Expression &e);
1214const ExpressionMax *to_max(
const ExpressionCell *expr_ptr);
1218const ExpressionMax *to_max(
const Expression &e);
1224const ExpressionIfThenElse *to_if_then_else(
const ExpressionCell *expr_ptr);
1228const ExpressionIfThenElse *to_if_then_else(
const Expression &e);
1234const ExpressionUninterpretedFunction *to_uninterpreted_function(
const ExpressionCell *expr_ptr);
1238const ExpressionUninterpretedFunction *to_uninterpreted_function(
const Expression &e);
Represents the base class for binary expressions.
BinaryExpressionCell(BinaryExpressionCell &&e)=delete
Move-constructs from an rvalue.
bool Less(const ExpressionCell &e) const override
Provides lexicographical ordering between expressions.
BinaryExpressionCell & operator=(BinaryExpressionCell &&e)=delete
Move-assigns (DELETED).
const Expression & get_first_argument() const
Returns the first argument.
BinaryExpressionCell()=delete
Default constructor (DELETED).
bool EqualTo(const ExpressionCell &e) const override
Checks structural equality.
mpq_class Evaluate(const Environment &env) const override
Evaluates under a given environment (by default, an empty environment).
const Expression & get_second_argument() const
Returns the second argument.
BinaryExpressionCell(ExpressionKind k, const Expression &e1, const Expression &e2, bool is_poly)
Constructs BinaryExpressionCell of kind k with hash, e1, e2, is_poly.
BinaryExpressionCell & operator=(const BinaryExpressionCell &e)=delete
Copy-assigns (DELETED).
~BinaryExpressionCell() override=default
Default destructor.
BinaryExpressionCell(const BinaryExpressionCell &e)=delete
Copy-constructs from an lvalue.
virtual mpq_class DoEvaluate(const mpq_class &v1, const mpq_class &v2) const =0
Returns the evaluation result f(v1, v2 ).
Represents a symbolic environment (mapping from a variable to a value).
Symbolic expression representing absolute value function.
std::ostream & Display(std::ostream &os) const override
Outputs string representation of expression into output stream os.
Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override
Returns an Expression obtained by replacing all occurrences of the variables in s in the current expr...
mpq_class DoEvaluate(const mpq_class &v) const override
Returns the evaluation result f(v ).
Expression Differentiate(const Variable &x) const override
Differentiates this symbolic expression with respect to the variable var.
Expression Expand() override
Expands out products and positive integer powers in expression.
Symbolic expression representing arccosine function.
Expression Differentiate(const Variable &x) const override
Differentiates this symbolic expression with respect to the variable var.
Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override
Returns an Expression obtained by replacing all occurrences of the variables in s in the current expr...
mpq_class DoEvaluate(const mpq_class &v) const override
Returns the evaluation result f(v ).
std::ostream & Display(std::ostream &os) const override
Outputs string representation of expression into output stream os.
Expression Expand() override
Expands out products and positive integer powers in expression.
Factory class to help build ExpressionAdd expressions.
ExpressionAddFactory(const ExpressionAdd *ptr)
Constructs ExpressionAddFactory from ptr.
ExpressionAddFactory & Negate()
Negates the expressions in factory.
ExpressionAddFactory()=default
Default constructor.
Expression GetExpression()
Returns a symbolic expression.
ExpressionAddFactory(const mpq_class &constant, const std::map< Expression, mpq_class > &expr_to_coeff_map)
Constructs ExpressionAddFactory with constant and expr_to_coeff_map.
ExpressionAddFactory & Add(const ExpressionAdd *ptr)
Adds ExpressionAdd pointed by ptr to this factory.
ExpressionAddFactory & AddExpression(const Expression &e)
Adds e to this factory.
ExpressionAddFactory & operator=(const ExpressionAdd *ptr)
Assigns a factory from a pointer to ExpressionAdd.
~ExpressionAddFactory()=default
Default destructor.
Symbolic expression representing an addition which is a sum of products.
Expression Differentiate(const Variable &x) const override
Differentiates this symbolic expression with respect to the variable var.
bool EqualTo(const ExpressionCell &e) const override
Checks structural equality.
Expression Expand() override
Expands out products and positive integer powers in expression.
bool Less(const ExpressionCell &e) const override
Provides lexicographical ordering between expressions.
ExpressionAdd(const mpq_class &constant, std::map< Expression, mpq_class > expr_to_coeff_map)
Constructs ExpressionAdd from constant_term and term_to_coeff_map.
mpq_class Evaluate(const Environment &env) const override
Evaluates under a given environment (by default, an empty environment).
Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override
Returns an Expression obtained by replacing all occurrences of the variables in s in the current expr...
const std::map< Expression, mpq_class > & get_expr_to_coeff_map() const
Returns map from an expression to its coefficient.
std::map< Expression, mpq_class > & get_mutable_expr_to_coeff_map()
Returns map from an expression to its coefficient.
std::ostream & Display(std::ostream &os) const override
Outputs string representation of expression into output stream os.
void UpdateHash() override
Update the cached hash value.
const mpq_class & get_constant() const
Returns the constant.
Symbolic expression representing arcsine function.
std::ostream & Display(std::ostream &os) const override
Outputs string representation of expression into output stream os.
Expression Differentiate(const Variable &x) const override
Differentiates this symbolic expression with respect to the variable var.
Expression Expand() override
Expands out products and positive integer powers in expression.
Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override
Returns an Expression obtained by replacing all occurrences of the variables in s in the current expr...
mpq_class DoEvaluate(const mpq_class &v) const override
Returns the evaluation result f(v ).
Symbolic expression representing atan2 function (arctangent function with two arguments).
mpq_class DoEvaluate(const mpq_class &v1, const mpq_class &v2) const override
Returns the evaluation result f(v1, v2 ).
std::ostream & Display(std::ostream &os) const override
Outputs string representation of expression into output stream os.
Expression Differentiate(const Variable &x) const override
Differentiates this symbolic expression with respect to the variable var.
Expression Expand() override
Expands out products and positive integer powers in expression.
Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override
Returns an Expression obtained by replacing all occurrences of the variables in s in the current expr...
Symbolic expression representing arctangent function.
Expression Differentiate(const Variable &x) const override
Differentiates this symbolic expression with respect to the variable var.
mpq_class DoEvaluate(const mpq_class &v) const override
Returns the evaluation result f(v ).
Expression Expand() override
Expands out products and positive integer powers in expression.
std::ostream & Display(std::ostream &os) const override
Outputs string representation of expression into output stream os.
Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override
Returns an Expression obtained by replacing all occurrences of the variables in s in the current expr...
Represents an abstract class which is the base of concrete symbolic-expression classes.
virtual ~ExpressionCell()=default
Default destructor.
virtual void UpdateHash()
Update the cached hash value.
ExpressionCell(ExpressionKind k, bool is_poly, bool include_ite, Variables variables)
Constructs ExpressionCell of kind k with hash, is_poly, and include_ite.
virtual bool Less(const ExpressionCell &c) const =0
Provides lexicographical ordering between expressions.
ExpressionCell & operator=(ExpressionCell &&e)=delete
Move-assigns (DELETED).
ExpressionKind get_kind() const
Returns expression kind.
virtual Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst)=0
Returns an Expression obtained by replacing all occurrences of the variables in s in the current expr...
ExpressionCell(ExpressionCell &&e)=delete
Move-constructs an ExpressionCell from an rvalue.
virtual bool EqualTo(const ExpressionCell &c) const =0
Checks structural equality.
ExpressionCell(const ExpressionCell &e)=delete
Copy-constructs an ExpressionCell from an lvalue.
virtual mpq_class Evaluate(const Environment &env) const =0
Evaluates under a given environment (by default, an empty environment).
size_t get_hash() const
Returns hash value.
ExpressionCell & operator=(const ExpressionCell &e)=delete
Copy-assigns (DELETED).
ExpressionCell(ExpressionKind k, bool is_poly)
Constructs ExpressionCell of kind k with hash, is_poly, and include_ite.
virtual Expression Differentiate(const Variable &x) const =0
Differentiates this symbolic expression with respect to the variable var.
bool include_ite() const
Returns true if this symbolic expression includes an ITE (If-Then-Else) expression.
ExpressionCell(ExpressionKind k, bool is_poly, bool include_ite, Variables variables, size_t hash)
Constructs ExpressionCell of kind k with hash, is_poly, and include_ite.
unsigned use_count() const
Returns the reference count of this cell.
const Variables & GetVariables() const
Collects variables in expression.
ExpressionCell(ExpressionKind k, bool is_poly, bool include_ite)
Constructs ExpressionCell of kind k with hash, is_poly, and include_ite.
virtual Expression Expand()=0
Expands out products and positive integer powers in expression.
std::optional< Variables > variables_
Cached variables contained in the expression.
virtual std::ostream & Display(std::ostream &os) const =0
Outputs string representation of expression into output stream os.
bool is_polynomial() const
Checks if this symbolic expression is convertible to Polynomial.
Expression GetExpression()
Returns an expression pointing to this ExpressionCell.
ExpressionCell(ExpressionKind k)
Constructs ExpressionCell of kind k.
Symbolic expression representing a rational constant (mpq_class).
Expression Expand() override
Expands out products and positive integer powers in expression.
Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override
Returns an Expression obtained by replacing all occurrences of the variables in s in the current expr...
void UpdateHash() override
Update the cached hash value.
std::ostream & Display(std::ostream &os) const override
Outputs string representation of expression into output stream os.
mpq_class Evaluate(const Environment &env) const override
Evaluates under a given environment (by default, an empty environment).
bool EqualTo(const ExpressionCell &e) const override
Checks structural equality.
Expression Differentiate(const Variable &x) const override
Differentiates this symbolic expression with respect to the variable var.
bool Less(const ExpressionCell &e) const override
Provides lexicographical ordering between expressions.
Symbolic expression representing cosine function.
mpq_class DoEvaluate(const mpq_class &v) const override
Returns the evaluation result f(v ).
Expression Expand() override
Expands out products and positive integer powers in expression.
Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override
Returns an Expression obtained by replacing all occurrences of the variables in s in the current expr...
std::ostream & Display(std::ostream &os) const override
Outputs string representation of expression into output stream os.
Expression Differentiate(const Variable &x) const override
Differentiates this symbolic expression with respect to the variable var.
Symbolic expression representing hyperbolic cosine function.
mpq_class DoEvaluate(const mpq_class &v) const override
Returns the evaluation result f(v ).
std::ostream & Display(std::ostream &os) const override
Outputs string representation of expression into output stream os.
Expression Differentiate(const Variable &x) const override
Differentiates this symbolic expression with respect to the variable var.
Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override
Returns an Expression obtained by replacing all occurrences of the variables in s in the current expr...
Expression Expand() override
Expands out products and positive integer powers in expression.
Symbolic expression representing division.
Expression Expand() override
Expands out products and positive integer powers in expression.
Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override
Returns an Expression obtained by replacing all occurrences of the variables in s in the current expr...
mpq_class DoEvaluate(const mpq_class &v1, const mpq_class &v2) const override
Returns the evaluation result f(v1, v2 ).
std::ostream & Display(std::ostream &os) const override
Outputs string representation of expression into output stream os.
Expression Differentiate(const Variable &x) const override
Differentiates this symbolic expression with respect to the variable var.
Symbolic expression representing exponentiation using the base of natural logarithms.
mpq_class DoEvaluate(const mpq_class &v) const override
Returns the evaluation result f(v ).
Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override
Returns an Expression obtained by replacing all occurrences of the variables in s in the current expr...
std::ostream & Display(std::ostream &os) const override
Outputs string representation of expression into output stream os.
Expression Differentiate(const Variable &x) const override
Differentiates this symbolic expression with respect to the variable var.
Expression Expand() override
Expands out products and positive integer powers in expression.
Symbolic expression representing if-then-else expression.
mpq_class Evaluate(const Environment &env) const override
Evaluates under a given environment (by default, an empty environment).
bool Less(const ExpressionCell &e) const override
Provides lexicographical ordering between expressions.
std::ostream & Display(std::ostream &os) const override
Outputs string representation of expression into output stream os.
Expression Differentiate(const Variable &x) const override
Differentiates this symbolic expression with respect to the variable var.
const Expression & get_then_expression() const
Returns the 'then' expression.
Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override
Returns an Expression obtained by replacing all occurrences of the variables in s in the current expr...
const Expression & get_else_expression() const
Returns the 'else' expression.
Expression Expand() override
Expands out products and positive integer powers in expression.
bool EqualTo(const ExpressionCell &e) const override
Checks structural equality.
const Formula & get_conditional_formula() const
Returns the conditional formula.
ExpressionIfThenElse(const Formula &f_cond, const Expression &e_then, const Expression &e_else)
Constructs if-then-else expression from f_cond, e_then, and e_else.
Symbolic expression representing infinities.
bool Less(const ExpressionCell &e) const override
Provides lexicographical ordering between expressions.
Expression Differentiate(const Variable &x) const override
Differentiates this symbolic expression with respect to the variable var.
Expression Expand() override
Expands out products and positive integer powers in expression.
Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override
Returns an Expression obtained by replacing all occurrences of the variables in s in the current expr...
std::ostream & Display(std::ostream &os) const override
Outputs string representation of expression into output stream os.
bool EqualTo(const ExpressionCell &e) const override
Checks structural equality.
mpq_class Evaluate(const Environment &env) const override
Evaluates under a given environment (by default, an empty environment).
Symbolic expression representing logarithms.
friend Expression log(const Expression &e)
mpq_class DoEvaluate(const mpq_class &v) const override
Returns the evaluation result f(v ).
std::ostream & Display(std::ostream &os) const override
Outputs string representation of expression into output stream os.
Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override
Returns an Expression obtained by replacing all occurrences of the variables in s in the current expr...
Expression Differentiate(const Variable &x) const override
Differentiates this symbolic expression with respect to the variable var.
Expression Expand() override
Expands out products and positive integer powers in expression.
Symbolic expression representing max function.
std::ostream & Display(std::ostream &os) const override
Outputs string representation of expression into output stream os.
Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override
Returns an Expression obtained by replacing all occurrences of the variables in s in the current expr...
Expression Differentiate(const Variable &x) const override
Differentiates this symbolic expression with respect to the variable var.
Expression Expand() override
Expands out products and positive integer powers in expression.
mpq_class DoEvaluate(const mpq_class &v1, const mpq_class &v2) const override
Returns the evaluation result f(v1, v2 ).
Symbolic expression representing min function.
Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override
Returns an Expression obtained by replacing all occurrences of the variables in s in the current expr...
Expression Expand() override
Expands out products and positive integer powers in expression.
std::ostream & Display(std::ostream &os) const override
Outputs string representation of expression into output stream os.
Expression Differentiate(const Variable &x) const override
Differentiates this symbolic expression with respect to the variable var.
mpq_class DoEvaluate(const mpq_class &v1, const mpq_class &v2) const override
Returns the evaluation result f(v1, v2 ).
Factory class to help build ExpressionMul expressions.
Expression GetExpression()
Returns a symbolic expression.
ExpressionMulFactory(const mpq_class &constant, const std::map< Expression, Expression > &base_to_exponent_map)
Constructs ExpressionMulFactory with constant and base_to_exponent_map.
ExpressionMulFactory(const ExpressionMul *ptr)
Constructs ExpressionMulFactory from ptr.
~ExpressionMulFactory()=default
Default destructor.
ExpressionMulFactory & operator=(const ExpressionMul *ptr)
Assigns a factory from a pointer to ExpressionMul.
ExpressionMulFactory & Add(const ExpressionMul *ptr)
Adds ExpressionMul pointed by ptr to this factory.
ExpressionMulFactory()=default
Default constructor.
ExpressionMulFactory & Negate()
Negates the expressions in factory.
ExpressionMulFactory & AddExpression(const Expression &e)
Adds e to this factory.
ExpressionMulFactory(mpq_class &&constant, std::map< Expression, Expression > &&base_to_exponent_map)
Constructs ExpressionMulFactory with constant and base_to_exponent_map.
Symbolic expression representing a multiplication of powers.
ExpressionMul(const mpq_class &constant, std::map< Expression, Expression > base_to_exponent_map)
Constructs ExpressionMul from constant and base_to_exponent_map.
mpq_class Evaluate(const Environment &env) const override
Evaluates under a given environment (by default, an empty environment).
std::map< Expression, Expression > & get_mutable_base_to_exponent_map()
Returns map from a term to its exponent.
const mpq_class & get_constant() const
Returns constant term.
bool EqualTo(const ExpressionCell &e) const override
Checks structural equality.
const std::map< Expression, Expression > & get_base_to_exponent_map() const
Returns map from a term to its exponent.
Expression Expand() override
Expands out products and positive integer powers in expression.
Expression Differentiate(const Variable &x) const override
Differentiates this symbolic expression with respect to the variable var.
std::ostream & Display(std::ostream &os) const override
Outputs string representation of expression into output stream os.
bool Less(const ExpressionCell &e) const override
Provides lexicographical ordering between expressions.
Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override
Returns an Expression obtained by replacing all occurrences of the variables in s in the current expr...
Symbolic expression representing NaN (not-a-number).
mpq_class Evaluate(const Environment &env) const override
Evaluates under a given environment (by default, an empty environment).
Expression Expand() override
Expands out products and positive integer powers in expression.
Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override
Returns an Expression obtained by replacing all occurrences of the variables in s in the current expr...
Expression Differentiate(const Variable &x) const override
Differentiates this symbolic expression with respect to the variable var.
bool EqualTo(const ExpressionCell &e) const override
Checks structural equality.
std::ostream & Display(std::ostream &os) const override
Outputs string representation of expression into output stream os.
bool Less(const ExpressionCell &e) const override
Provides lexicographical ordering between expressions.
Symbolic expression representing power function.
mpq_class DoEvaluate(const mpq_class &v1, const mpq_class &v2) const override
Returns the evaluation result f(v1, v2 ).
Expression Differentiate(const Variable &x) const override
Differentiates this symbolic expression with respect to the variable var.
Expression Expand() override
Expands out products and positive integer powers in expression.
std::ostream & Display(std::ostream &os) const override
Outputs string representation of expression into output stream os.
Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override
Returns an Expression obtained by replacing all occurrences of the variables in s in the current expr...
Symbolic expression representing sine function.
std::ostream & Display(std::ostream &os) const override
Outputs string representation of expression into output stream os.
Expression Expand() override
Expands out products and positive integer powers in expression.
Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override
Returns an Expression obtained by replacing all occurrences of the variables in s in the current expr...
Expression Differentiate(const Variable &x) const override
Differentiates this symbolic expression with respect to the variable var.
mpq_class DoEvaluate(const mpq_class &v) const override
Returns the evaluation result f(v ).
Symbolic expression representing hyperbolic sine function.
mpq_class DoEvaluate(const mpq_class &v) const override
Returns the evaluation result f(v ).
Expression Differentiate(const Variable &x) const override
Differentiates this symbolic expression with respect to the variable var.
Expression Expand() override
Expands out products and positive integer powers in expression.
std::ostream & Display(std::ostream &os) const override
Outputs string representation of expression into output stream os.
Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override
Returns an Expression obtained by replacing all occurrences of the variables in s in the current expr...
Symbolic expression representing square-root.
std::ostream & Display(std::ostream &os) const override
Outputs string representation of expression into output stream os.
Expression Expand() override
Expands out products and positive integer powers in expression.
mpq_class DoEvaluate(const mpq_class &v) const override
Returns the evaluation result f(v ).
Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override
Returns an Expression obtained by replacing all occurrences of the variables in s in the current expr...
Expression Differentiate(const Variable &x) const override
Differentiates this symbolic expression with respect to the variable var.
Symbolic expression representing tangent function.
std::ostream & Display(std::ostream &os) const override
Outputs string representation of expression into output stream os.
Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override
Returns an Expression obtained by replacing all occurrences of the variables in s in the current expr...
Expression Differentiate(const Variable &x) const override
Differentiates this symbolic expression with respect to the variable var.
Expression Expand() override
Expands out products and positive integer powers in expression.
mpq_class DoEvaluate(const mpq_class &v) const override
Returns the evaluation result f(v ).
Symbolic expression representing hyperbolic tangent function.
Expression Differentiate(const Variable &x) const override
Differentiates this symbolic expression with respect to the variable var.
std::ostream & Display(std::ostream &os) const override
Outputs string representation of expression into output stream os.
Expression Expand() override
Expands out products and positive integer powers in expression.
Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override
Returns an Expression obtained by replacing all occurrences of the variables in s in the current expr...
mpq_class DoEvaluate(const mpq_class &v) const override
Returns the evaluation result f(v ).
Symbolic expression representing an uninterpreted function.
Expression Differentiate(const Variable &x) const override
Differentiates this symbolic expression with respect to the variable var.
Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override
Returns an Expression obtained by replacing all occurrences of the variables in s in the current expr...
mpq_class Evaluate(const Environment &env) const override
Evaluates under a given environment (by default, an empty environment).
Expression Expand() override
Expands out products and positive integer powers in expression.
ExpressionUninterpretedFunction(const std::string &name, const Variables &vars)
Constructs an uninterpreted-function expression from name and vars.
std::ostream & Display(std::ostream &os) const override
Outputs string representation of expression into output stream os.
bool EqualTo(const ExpressionCell &e) const override
Checks structural equality.
const std::string & get_name() const
Returns the name of this expression.
bool Less(const ExpressionCell &e) const override
Provides lexicographical ordering between expressions.
Symbolic expression representing a variable.
Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override
Returns an Expression obtained by replacing all occurrences of the variables in s in the current expr...
Expression Differentiate(const Variable &x) const override
Differentiates this symbolic expression with respect to the variable var.
ExpressionVar(const Variable &v)
Constructs an expression from var.
mpq_class Evaluate(const Environment &env) const override
Evaluates under a given environment (by default, an empty environment).
std::ostream & Display(std::ostream &os) const override
Outputs string representation of expression into output stream os.
bool EqualTo(const ExpressionCell &e) const override
Checks structural equality.
bool Less(const ExpressionCell &e) const override
Provides lexicographical ordering between expressions.
Expression Expand() override
Expands out products and positive integer powers in expression.
Represents a symbolic form of an expression.
Represents the base class for unary expressions.
bool EqualTo(const ExpressionCell &e) const override
Checks structural equality.
~UnaryExpressionCell() override=default
Default destructor.
UnaryExpressionCell(ExpressionKind k, const Expression &e, bool is_poly)
Constructs UnaryExpressionCell of kind k with hash, e, is_poly.
bool Less(const ExpressionCell &e) const override
Provides lexicographical ordering between expressions.
UnaryExpressionCell()=delete
Default constructor (DELETED).
const Expression & get_argument() const
Returns the argument.
mpq_class Evaluate(const Environment &env) const override
Evaluates under a given environment (by default, an empty environment).
virtual mpq_class DoEvaluate(const mpq_class &v) const =0
Returns the evaluation result f(v ).
UnaryExpressionCell & operator=(const UnaryExpressionCell &e)=delete
Copy-assigns (DELETED).
UnaryExpressionCell & operator=(UnaryExpressionCell &&e)=delete
Move-assigns (DELETED).
UnaryExpressionCell(UnaryExpressionCell &&e)=delete
Move-constructs from an rvalue.
UnaryExpressionCell(const UnaryExpressionCell &e)=delete
Copy-constructs from an lvalue.
Represents a symbolic variable.
Represents a set of variables.