dReal4
symbolic_expression_cell.h
1 #pragma once
2 
3 #include <algorithm> // for cpplint only
4 #include <atomic>
5 #include <cstddef>
6 #include <map>
7 #include <ostream>
8 #include <string>
9 
10 #include "dreal/symbolic/symbolic_environment.h"
11 #include "dreal/symbolic/symbolic_expression.h"
12 #include "dreal/symbolic/symbolic_formula.h"
13 #include "dreal/symbolic/symbolic_variable.h"
14 #include "dreal/symbolic/symbolic_variables.h"
15 
16 namespace dreal {
17 namespace drake {
18 namespace symbolic {
19 
20 /** Represents an abstract class which is the base of concrete
21  * symbolic-expression classes.
22  *
23  * @note It provides virtual function, ExpressionCell::Display, because
24  * operator<< is not allowed to be a virtual function.
25  */
27  public:
28  /** Returns expression kind. */
29  ExpressionKind get_kind() const { return kind_; }
30 
31  /** Returns hash value. */
32  size_t get_hash() const { return hash_; }
33 
34  /** Collects variables in expression. */
35  const Variables& GetVariables() const;
36 
37  /** Checks structural equality. */
38  virtual bool EqualTo(const ExpressionCell& c) const = 0;
39 
40  /** Provides lexicographical ordering between expressions. */
41  virtual bool Less(const ExpressionCell& c) const = 0;
42 
43  /** Checks if this symbolic expression is convertible to Polynomial. */
44  bool is_polynomial() const { return is_polynomial_; }
45 
46  /// Returns true if this symbolic expression includes an ITE (If-Then-Else)
47  /// expression.
48  bool include_ite() const { return include_ite_; }
49 
50  /** Evaluates under a given environment (by default, an empty environment).
51  * @throws std::runtime_error if NaN is detected during evaluation.
52  */
53  virtual double Evaluate(const Environment& env) const = 0;
54 
55  /** Expands out products and positive integer powers in expression.
56  * @throws std::runtime_error if NaN is detected during expansion.
57  */
58  virtual Expression Expand() = 0;
59 
60  /** Returns an Expression obtained by replacing all occurrences of the
61  * variables in @p s in the current expression cell with the corresponding
62  * expressions in @p s.
63  * @throws std::runtime_error if NaN is detected during substitution.
64  */
65  virtual Expression Substitute(const ExpressionSubstitution& expr_subst,
66  const FormulaSubstitution& formula_subst) = 0;
67 
68  /** Differentiates this symbolic expression with respect to the variable @p
69  * var.
70  * @throws std::runtime_error if it is not differentiable.
71  */
72  virtual Expression Differentiate(const Variable& x) const = 0;
73 
74  /** Outputs string representation of expression into output stream @p os. */
75  virtual std::ostream& Display(std::ostream& os) const = 0;
76 
77  /** Returns the reference count of this cell. */
78  unsigned use_count() const {
79  return atomic_load_explicit(&rc_, std::memory_order_acquire);
80  }
81 
82  /** Copy-constructs an ExpressionCell from an lvalue. (DELETED) */
83  ExpressionCell(const ExpressionCell& e) = delete;
84 
85  /** Move-constructs an ExpressionCell from an rvalue. (DELETED) */
86  ExpressionCell(ExpressionCell&& e) = delete;
87 
88  /** Default constructor (DELETED). */
89  ExpressionCell() = delete;
90 
91  /** Move-assigns (DELETED). */
93 
94  /** Copy-assigns (DELETED). */
95  ExpressionCell& operator=(const ExpressionCell& e) = delete;
96 
97  protected:
98  /** Constructs ExpressionCell of kind @p k with @p hash, @p is_poly, and @p
99  * include_ite. */
100  ExpressionCell(ExpressionKind k, size_t hash, bool is_poly, bool include_ite,
101  Variables variables);
102  /** Default destructor. */
103  virtual ~ExpressionCell() = default;
104  /** Returns an expression pointing to this ExpressionCell. */
106 
107  private:
108  const ExpressionKind kind_{};
109  const size_t hash_{};
110  const bool is_polynomial_{false};
111  const bool include_ite_{false};
112  const Variables variables_;
113 
114  // Reference counter.
115  mutable std::atomic<unsigned> rc_{0};
116  void increase_rc() const {
117  atomic_fetch_add_explicit(&rc_, 1U, std::memory_order_relaxed);
118  }
119  void decrease_rc() const {
120  if (atomic_fetch_sub_explicit(&rc_, 1U, std::memory_order_acq_rel) == 1U) {
121  delete this;
122  }
123  }
124 
125  // So that Expression can call {increase,decrease}_rc.
126  friend Expression;
127 };
128 
129 /** Represents the base class for unary expressions. */
131  public:
132  bool EqualTo(const ExpressionCell& e) const override;
133  bool Less(const ExpressionCell& e) const override;
134  double Evaluate(const Environment& env) const override;
135  /** Returns the argument. */
136  const Expression& get_argument() const { return e_; }
137 
138  /** Copy-constructs from an lvalue. (DELETED) */
139  UnaryExpressionCell(const UnaryExpressionCell& e) = delete;
140 
141  /** Default constructor (DELETED). */
142  UnaryExpressionCell() = delete;
143 
144  /** Move-assigns (DELETED). */
146 
147  /** Copy-assigns (DELETED). */
149 
150  /** Move-constructs from an rvalue. (DELETED) */
152 
153  /** Default destructor. */
154  ~UnaryExpressionCell() override = default;
155 
156  protected:
157  /** Constructs UnaryExpressionCell of kind @p k with @p hash, @p e, @p
158  * is_poly. */
159  UnaryExpressionCell(ExpressionKind k, const Expression& e, bool is_poly);
160  /** Returns the evaluation result f(@p v ). */
161  virtual double DoEvaluate(double v) const = 0;
162 
163  private:
164  const Expression e_;
165 };
166 
167 /** Represents the base class for binary expressions.
168  */
170  public:
171  bool EqualTo(const ExpressionCell& e) const override;
172  bool Less(const ExpressionCell& e) const override;
173  double Evaluate(const Environment& env) const override;
174  /** Returns the first argument. */
175  const Expression& get_first_argument() const { return e1_; }
176  /** Returns the second argument. */
177  const Expression& get_second_argument() const { return e2_; }
178 
179  /** Copy-constructs from an lvalue. (DELETED) */
180  BinaryExpressionCell(const BinaryExpressionCell& e) = delete;
181 
182  /** Move-constructs from an rvalue. (DELETED) */
184 
185  /** Default constructor (DELETED). */
186  BinaryExpressionCell() = delete;
187 
188  /** Move-assigns (DELETED). */
190 
191  /** Copy-assigns (DELETED). */
193 
194  /** Default destructor. */
195  ~BinaryExpressionCell() override = default;
196 
197  protected:
198  /** Constructs BinaryExpressionCell of kind @p k with @p hash, @p e1, @p e2,
199  * @p is_poly.
200  */
201  BinaryExpressionCell(ExpressionKind k, const Expression& e1,
202  const Expression& e2, bool is_poly);
203  /** Returns the evaluation result f(@p v1, @p v2 ). */
204  virtual double DoEvaluate(double v1, double v2) const = 0;
205 
206  private:
207  const Expression e1_;
208  const Expression e2_;
209 };
210 
211 /** Symbolic expression representing a variable. */
213  public:
214  /** Constructs an expression from @p var.
215  * @pre @p var is neither a dummy nor a BOOLEAN variable.
216  */
217  explicit ExpressionVar(const Variable& v);
218  const Variable& get_variable() const { return var_; }
219  bool EqualTo(const ExpressionCell& e) const override;
220  bool Less(const ExpressionCell& e) const override;
221  double Evaluate(const Environment& env) const override;
222  Expression Expand() override;
223  Expression Substitute(const ExpressionSubstitution& expr_subst,
224  const FormulaSubstitution& formula_subst) override;
225  Expression Differentiate(const Variable& x) const override;
226  std::ostream& Display(std::ostream& os) const override;
227 
228  private:
229  const Variable var_;
230 };
231 
232 /** Symbolic expression representing a floating-point constant (double). */
234  public:
235  explicit ExpressionConstant(double v);
236  double get_value() const { return v_; }
237  bool EqualTo(const ExpressionCell& e) const override;
238  bool Less(const ExpressionCell& e) const override;
239  double Evaluate(const Environment& env) const override;
240  Expression Expand() override;
241  Expression Substitute(const ExpressionSubstitution& expr_subst,
242  const FormulaSubstitution& formula_subst) override;
243  Expression Differentiate(const Variable& x) const override;
244  std::ostream& Display(std::ostream& os) const override;
245 
246  private:
247  const double v_{};
248 };
249 
250 /** Symbolic expression representing a real constant represented by a
251  * double interval [lb, ub].
252  *
253  * Note that the gap between lb and ub should be minimal, that is, the
254  * next machine-representable number of `lb` should be `ub`.
255  */
257  public:
258  ExpressionRealConstant(double lb, double ub, bool use_lb_as_representative);
259  double get_lb() const { return lb_; }
260  double get_ub() const { return ub_; }
261  double get_value() const { return use_lb_as_representative_ ? lb_ : ub_; }
262  bool EqualTo(const ExpressionCell& e) const override;
263  bool Less(const ExpressionCell& e) const override;
264  double Evaluate(const Environment& env) const override;
265  Expression Expand() override;
266  Expression Substitute(const ExpressionSubstitution& expr_subst,
267  const FormulaSubstitution& formula_subst) override;
268  Expression Differentiate(const Variable& x) const override;
269  std::ostream& Display(std::ostream& os) const override;
270 
271  private:
272  const double lb_{};
273  const double ub_{};
274  const bool use_lb_as_representative_{};
275 };
276 
277 /** Symbolic expression representing NaN (not-a-number). */
279  public:
280  ExpressionNaN();
281  bool EqualTo(const ExpressionCell& e) const override;
282  bool Less(const ExpressionCell& e) const override;
283  double Evaluate(const Environment& env) const override;
284  Expression Expand() override;
285  Expression Substitute(const ExpressionSubstitution& expr_subst,
286  const FormulaSubstitution& formula_subst) override;
287  Expression Differentiate(const Variable& x) const override;
288  std::ostream& Display(std::ostream& os) const override;
289 };
290 
291 /** Symbolic expression representing an addition which is a sum of products.
292  *
293  * @f[
294  * c_0 + \sum c_i * e_i
295  * @f]
296  *
297  * where @f$ c_i @f$ is a constant and @f$ e_i @f$ is a symbolic expression.
298  *
299  * Internally this class maintains a member variable @c constant_ to represent
300  * @f$ c_0 @f$ and another member variable @c expr_to_coeff_map_ to represent a
301  * mapping from an expression @f$ e_i @f$ to its coefficient @f$ c_i @f$ of
302  * double.
303  */
305  public:
306  /** Constructs ExpressionAdd from @p constant_term and @p term_to_coeff_map.
307  */
308  ExpressionAdd(double constant,
309  std::map<Expression, double> expr_to_coeff_map);
310  bool EqualTo(const ExpressionCell& e) const override;
311  bool Less(const ExpressionCell& e) const override;
312  double Evaluate(const Environment& env) const override;
313  Expression Expand() override;
314  Expression Substitute(const ExpressionSubstitution& expr_subst,
315  const FormulaSubstitution& formula_subst) override;
316  Expression Differentiate(const Variable& x) const override;
317  std::ostream& Display(std::ostream& os) const override;
318  /** Returns the constant. */
319  double get_constant() const { return constant_; }
320  /** Returns map from an expression to its coefficient. */
321  const std::map<Expression, double>& get_expr_to_coeff_map() const {
322  return expr_to_coeff_map_;
323  }
324 
325  // TODO(soonho): Make the following private and allow
326  // only selected functions/method to use them.
327  /** Returns map from an expression to its coefficient. */
328  std::map<Expression, double>& get_mutable_expr_to_coeff_map() {
329  return expr_to_coeff_map_;
330  }
331 
332  private:
333  static Variables ExtractVariables(
334  const std::map<Expression, double>& expr_to_coeff_map);
335  std::ostream& DisplayTerm(std::ostream& os, bool print_plus, double coeff,
336  const Expression& term) const;
337 
338  double constant_{};
339  std::map<Expression, double> expr_to_coeff_map_;
340 };
341 
342 /** Factory class to help build ExpressionAdd expressions.
343  *
344  * @note Once `GetExpression()` is called and an expression is
345  * generated, this class should not be used again. If another
346  * `GetExpression()` is called, it will throws an exception.
347  */
349  public:
350  ExpressionAddFactory(const ExpressionAddFactory&) = default;
354 
355  /** Default constructor. */
356  ExpressionAddFactory() = default;
357 
358  /** Default destructor. */
359  ~ExpressionAddFactory() = default;
360 
361  /** Constructs ExpressionAddFactory with @p constant and @p
362  * expr_to_coeff_map. */
363  ExpressionAddFactory(double constant,
364  std::map<Expression, double> expr_to_coeff_map);
365 
366  /** Constructs ExpressionAddFactory from @p ptr. */
367  explicit ExpressionAddFactory(const ExpressionAdd* ptr);
368 
369  /** Adds @p e to this factory. */
370  ExpressionAddFactory& AddExpression(const Expression& e);
371  /** Adds ExpressionAdd pointed by @p ptr to this factory. */
372  ExpressionAddFactory& Add(const ExpressionAdd* ptr);
373  /** Assigns a factory from a pointer to ExpressionAdd. */
375 
376  /** Negates the expressions in factory.
377  * If it represents c0 + c1 * t1 + ... + * cn * tn,
378  * this method flips it into -c0 - c1 * t1 - ... - cn * tn.
379  * @returns *this.
380  */
381  ExpressionAddFactory& Negate();
382  /** Returns a symbolic expression. */
384 
385  private:
386  /* Adds constant to this factory.
387  * Adding constant constant into an add factory representing
388  *
389  * c0 + c1 * t1 + ... + cn * tn
390  *
391  * results in (c0 + constant) + c1 * t1 + ... + cn * tn. */
392  ExpressionAddFactory& AddConstant(double constant);
393  /* Adds coeff * term to this factory.
394  *
395  * Adding (coeff * term) into an add factory representing
396  *
397  * c0 + c1 * t1 + ... + cn * tn
398  *
399  * results in c0 + c1 * t1 + ... + (coeff * term) + ... + cn * tn. Note that
400  * it also performs simplifications to merge the coefficients of common terms.
401  */
402  ExpressionAddFactory& AddTerm(double coeff, const Expression& term);
403  /* Adds expr_to_coeff_map to this factory. It calls AddConstant and AddTerm
404  * methods. */
405  ExpressionAddFactory& AddMap(
406  const std::map<Expression, double>& expr_to_coeff_map);
407 
408  bool get_expression_is_called_{false};
409  double constant_{0.0};
410  std::map<Expression, double> expr_to_coeff_map_;
411 };
412 
413 /** Symbolic expression representing a multiplication of powers.
414  *
415  * @f[
416  * c_0 \cdot \prod b_i^{e_i}
417  * @f]
418  *
419  * where @f$ c_0 @f$ is a constant and @f$ b_i @f$ and @f$ e_i @f$ are symbolic
420  * expressions.
421  *
422  * Internally this class maintains a member variable @c constant_ representing
423  * @f$ c_0 @f$ and another member variable @c base_to_exponent_map_ representing
424  * a mapping from a base, @f$ b_i @f$ to its exponentiation @f$ e_i @f$.
425  */
427  public:
428  /** Constructs ExpressionMul from @p constant and @p base_to_exponent_map. */
429  ExpressionMul(double constant,
430  std::map<Expression, Expression> base_to_exponent_map);
431  bool EqualTo(const ExpressionCell& e) const override;
432  bool Less(const ExpressionCell& e) const override;
433  double Evaluate(const Environment& env) const override;
434  Expression Expand() override;
435  Expression Substitute(const ExpressionSubstitution& expr_subst,
436  const FormulaSubstitution& formula_subst) override;
437  Expression Differentiate(const Variable& x) const override;
438  std::ostream& Display(std::ostream& os) const override;
439  /** Returns constant term. */
440  double get_constant() const { return constant_; }
441  /** Returns map from a term to its exponent. */
442  const std::map<Expression, Expression>& get_base_to_exponent_map() const {
443  return base_to_exponent_map_;
444  }
445 
446  // TODO(soonho): Make the following private and allow
447  // only selected functions/method to use them.
448  /** Returns map from a term to its exponent. */
449  std::map<Expression, Expression>& get_mutable_base_to_exponent_map() {
450  return base_to_exponent_map_;
451  }
452 
453  private:
454  static Variables ExtractVariables(
455  const std::map<Expression, Expression>& base_to_exponent_map);
456  std::ostream& DisplayTerm(std::ostream& os, bool print_mul,
457  const Expression& base,
458  const Expression& exponent) const;
459 
460  double constant_{};
461  std::map<Expression, Expression> base_to_exponent_map_;
462 };
463 
464 /** Factory class to help build ExpressionMul expressions.
465  *
466  * @note Once `GetExpression()` is called and an expression is
467  * generated, this class should not be used again. If another
468  * `GetExpression()` is called, it will throws an exception.
469  */
471  public:
472  ExpressionMulFactory(const ExpressionMulFactory&) = default;
476 
477  /** Default constructor. It constructs. */
478  ExpressionMulFactory() = default;
479 
480  /** Default destructor. */
481  ~ExpressionMulFactory() = default;
482 
483  /** Constructs ExpressionMulFactory with @p constant and @p
484  * base_to_exponent_map. */
485  ExpressionMulFactory(double constant,
486  std::map<Expression, Expression> base_to_exponent_map);
487 
488  /** Constructs ExpressionMulFactory from @p ptr. */
489  explicit ExpressionMulFactory(const ExpressionMul* ptr);
490 
491  /** Adds @p e to this factory. */
492  ExpressionMulFactory& AddExpression(const Expression& e);
493  /** Adds ExpressionMul pointed by @p ptr to this factory. */
494  ExpressionMulFactory& Add(const ExpressionMul* ptr);
495  /** Assigns a factory from a pointer to ExpressionMul. */
497  /** Negates the expressions in factory.
498  * If it represents c0 * p1 * ... * pn,
499  * this method flips it into -c0 * p1 * ... * pn.
500  * @returns *this.
501  */
502  ExpressionMulFactory& Negate();
503  /** Returns a symbolic expression. */
505 
506  private:
507  /* Adds constant to this factory.
508  Adding constant into an mul factory representing
509 
510  c * b1 ^ e1 * ... * bn ^ en
511 
512  results in (constant * c) * b1 ^ e1 * ... * bn ^ en. */
513  ExpressionMulFactory& AddConstant(double constant);
514  /* Adds pow(base, exponent) to this factory.
515  Adding pow(base, exponent) into an mul factory representing
516 
517  c * b1 ^ e1 * ... * bn ^ en
518 
519  results in c * b1 ^ e1 * ... * base^exponent * ... * bn ^ en. Note that
520  it also performs simplifications to merge the exponents of common bases.
521  */
522  ExpressionMulFactory& AddTerm(const Expression& base,
523  const Expression& exponent);
524  /* Adds base_to_exponent_map to this factory. It calls AddConstant and AddTerm
525  * methods. */
526  ExpressionMulFactory& AddMap(
527  const std::map<Expression, Expression>& base_to_exponent_map);
528 
529  bool get_expression_is_called_{false};
530  double constant_{1.0};
531  std::map<Expression, Expression> base_to_exponent_map_;
532 };
533 
534 /** Symbolic expression representing division. */
536  public:
537  ExpressionDiv(const Expression& e1, const Expression& e2);
538  Expression Expand() override;
539  Expression Substitute(const ExpressionSubstitution& expr_subst,
540  const FormulaSubstitution& formula_subst) override;
541  Expression Differentiate(const Variable& x) const override;
542  std::ostream& Display(std::ostream& os) const override;
543 
544  private:
545  double DoEvaluate(double v1, double v2) const override;
546 };
547 
548 /** Symbolic expression representing logarithms. */
550  public:
551  explicit ExpressionLog(const Expression& e);
552  Expression Expand() override;
553  Expression Substitute(const ExpressionSubstitution& expr_subst,
554  const FormulaSubstitution& formula_subst) override;
555  Expression Differentiate(const Variable& x) const override;
556  std::ostream& Display(std::ostream& os) const override;
557 
558  friend Expression log(const Expression& e);
559 
560  private:
561  /* Throws std::domain_error if v ∉ [0, +oo). */
562  static void check_domain(double v);
563  double DoEvaluate(double v) const override;
564 };
565 
566 /** Symbolic expression representing absolute value function. */
568  public:
569  explicit ExpressionAbs(const Expression& e);
570  Expression Expand() override;
571  Expression Substitute(const ExpressionSubstitution& expr_subst,
572  const FormulaSubstitution& formula_subst) override;
573  Expression Differentiate(const Variable& x) const override;
574  std::ostream& Display(std::ostream& os) const override;
575 
576  friend Expression abs(const Expression& e);
577 
578  private:
579  double DoEvaluate(double v) const override;
580 };
581 
582 /** Symbolic expression representing exponentiation using the base of
583  * natural logarithms. */
585  public:
586  explicit ExpressionExp(const Expression& e);
587  Expression Expand() override;
588  Expression Substitute(const ExpressionSubstitution& expr_subst,
589  const FormulaSubstitution& formula_subst) override;
590  Expression Differentiate(const Variable& x) const override;
591  std::ostream& Display(std::ostream& os) const override;
592 
593  private:
594  double DoEvaluate(double v) const override;
595 };
596 
597 /** Symbolic expression representing square-root. */
599  public:
600  explicit ExpressionSqrt(const Expression& e);
601  Expression Expand() override;
602  Expression Substitute(const ExpressionSubstitution& expr_subst,
603  const FormulaSubstitution& formula_subst) override;
604  Expression Differentiate(const Variable& x) const override;
605  std::ostream& Display(std::ostream& os) const override;
606 
607  friend Expression sqrt(const Expression& e);
608 
609  private:
610  /* Throws std::domain_error if v ∉ [0, +oo). */
611  static void check_domain(double v);
612  double DoEvaluate(double v) const override;
613 };
614 
615 /** Symbolic expression representing power function. */
617  public:
618  ExpressionPow(const Expression& e1, const Expression& e2);
619  Expression Expand() override;
620  Expression Substitute(const ExpressionSubstitution& expr_subst,
621  const FormulaSubstitution& formula_subst) override;
622  Expression Differentiate(const Variable& x) const override;
623  std::ostream& Display(std::ostream& os) const override;
624 
625  friend Expression pow(const Expression& e1, const Expression& e2);
626 
627  private:
628  /* Throws std::domain_error if v1 is finite negative and v2 is finite
629  non-integer. */
630  static void check_domain(double v1, double v2);
631  double DoEvaluate(double v1, double v2) const override;
632 };
633 
634 /** Symbolic expression representing sine function. */
636  public:
637  explicit ExpressionSin(const Expression& e);
638  Expression Expand() override;
639  Expression Substitute(const ExpressionSubstitution& expr_subst,
640  const FormulaSubstitution& formula_subst) override;
641  Expression Differentiate(const Variable& x) const override;
642  std::ostream& Display(std::ostream& os) const override;
643 
644  private:
645  double DoEvaluate(double v) const override;
646 };
647 
648 /** Symbolic expression representing cosine function. */
650  public:
651  explicit ExpressionCos(const Expression& e);
652  Expression Expand() override;
653  Expression Substitute(const ExpressionSubstitution& expr_subst,
654  const FormulaSubstitution& formula_subst) override;
655  Expression Differentiate(const Variable& x) const override;
656  std::ostream& Display(std::ostream& os) const override;
657 
658  private:
659  double DoEvaluate(double v) const override;
660 };
661 
662 /** Symbolic expression representing tangent function. */
664  public:
665  explicit ExpressionTan(const Expression& e);
666  Expression Expand() override;
667  Expression Substitute(const ExpressionSubstitution& expr_subst,
668  const FormulaSubstitution& formula_subst) override;
669  Expression Differentiate(const Variable& x) const override;
670  std::ostream& Display(std::ostream& os) const override;
671 
672  private:
673  double DoEvaluate(double v) const override;
674 };
675 
676 /** Symbolic expression representing arcsine function. */
678  public:
679  explicit ExpressionAsin(const Expression& e);
680  Expression Expand() override;
681  Expression Substitute(const ExpressionSubstitution& expr_subst,
682  const FormulaSubstitution& formula_subst) override;
683  Expression Differentiate(const Variable& x) const override;
684  std::ostream& Display(std::ostream& os) const override;
685 
686  friend Expression asin(const Expression& e);
687 
688  private:
689  /* Throws std::domain_error if v ∉ [-1.0, +1.0]. */
690  static void check_domain(double v);
691  double DoEvaluate(double v) const override;
692 };
693 
694 /** Symbolic expression representing arccosine function. */
696  public:
697  explicit ExpressionAcos(const Expression& e);
698  Expression Expand() override;
699  Expression Substitute(const ExpressionSubstitution& expr_subst,
700  const FormulaSubstitution& formula_subst) override;
701  Expression Differentiate(const Variable& x) const override;
702  std::ostream& Display(std::ostream& os) const override;
703 
704  friend Expression acos(const Expression& e);
705 
706  private:
707  /* Throws std::domain_error if v ∉ [-1.0, +1.0]. */
708  static void check_domain(double v);
709  double DoEvaluate(double v) const override;
710 };
711 
712 /** Symbolic expression representing arctangent function. */
714  public:
715  explicit ExpressionAtan(const Expression& e);
716  Expression Expand() override;
717  Expression Substitute(const ExpressionSubstitution& expr_subst,
718  const FormulaSubstitution& formula_subst) override;
719  Expression Differentiate(const Variable& x) const override;
720  std::ostream& Display(std::ostream& os) const override;
721 
722  private:
723  double DoEvaluate(double v) const override;
724 };
725 
726 /** Symbolic expression representing atan2 function (arctangent function with
727  * two arguments). atan2(y, x) is defined as atan(y/x). */
729  public:
730  ExpressionAtan2(const Expression& e1, const Expression& e2);
731  Expression Expand() override;
732  Expression Substitute(const ExpressionSubstitution& expr_subst,
733  const FormulaSubstitution& formula_subst) override;
734  Expression Differentiate(const Variable& x) const override;
735  std::ostream& Display(std::ostream& os) const override;
736 
737  private:
738  double DoEvaluate(double v1, double v2) const override;
739 };
740 
741 /** Symbolic expression representing hyperbolic sine function. */
743  public:
744  explicit ExpressionSinh(const Expression& e);
745  Expression Expand() override;
746  Expression Substitute(const ExpressionSubstitution& expr_subst,
747  const FormulaSubstitution& formula_subst) override;
748  Expression Differentiate(const Variable& x) const override;
749  std::ostream& Display(std::ostream& os) const override;
750 
751  private:
752  double DoEvaluate(double v) const override;
753 };
754 
755 /** Symbolic expression representing hyperbolic cosine function. */
757  public:
758  explicit ExpressionCosh(const Expression& e);
759  Expression Expand() override;
760  Expression Substitute(const ExpressionSubstitution& expr_subst,
761  const FormulaSubstitution& formula_subst) override;
762  Expression Differentiate(const Variable& x) const override;
763  std::ostream& Display(std::ostream& os) const override;
764 
765  private:
766  double DoEvaluate(double v) const override;
767 };
768 
769 /** Symbolic expression representing hyperbolic tangent function. */
771  public:
772  explicit ExpressionTanh(const Expression& e);
773  Expression Expand() override;
774  Expression Substitute(const ExpressionSubstitution& expr_subst,
775  const FormulaSubstitution& formula_subst) override;
776  Expression Differentiate(const Variable& x) const override;
777  std::ostream& Display(std::ostream& os) const override;
778 
779  private:
780  double DoEvaluate(double v) const override;
781 };
782 
783 /** Symbolic expression representing min function. */
785  public:
786  ExpressionMin(const Expression& e1, const Expression& e2);
787  Expression Expand() override;
788  Expression Substitute(const ExpressionSubstitution& expr_subst,
789  const FormulaSubstitution& formula_subst) override;
790  Expression Differentiate(const Variable& x) const override;
791  std::ostream& Display(std::ostream& os) const override;
792 
793  private:
794  double DoEvaluate(double v1, double v2) const override;
795 };
796 
797 /** Symbolic expression representing max function. */
799  public:
800  ExpressionMax(const Expression& e1, const Expression& e2);
801  Expression Expand() override;
802  Expression Substitute(const ExpressionSubstitution& expr_subst,
803  const FormulaSubstitution& formula_subst) override;
804  Expression Differentiate(const Variable& x) const override;
805  std::ostream& Display(std::ostream& os) const override;
806 
807  private:
808  double DoEvaluate(double v1, double v2) const override;
809 };
810 
811 /** Symbolic expression representing if-then-else expression. */
813  public:
814  /** Constructs if-then-else expression from @p f_cond, @p e_then, and @p
815  * e_else. */
816  ExpressionIfThenElse(const Formula& f_cond, const Expression& e_then,
817  const Expression& e_else);
818  bool EqualTo(const ExpressionCell& e) const override;
819  bool Less(const ExpressionCell& e) const override;
820  double Evaluate(const Environment& env) const override;
821  Expression Expand() override;
822  Expression Substitute(const ExpressionSubstitution& expr_subst,
823  const FormulaSubstitution& formula_subst) override;
824  Expression Differentiate(const Variable& x) const override;
825  std::ostream& Display(std::ostream& os) const override;
826 
827  /** Returns the conditional formula. */
828  const Formula& get_conditional_formula() const { return f_cond_; }
829  /** Returns the 'then' expression. */
830  const Expression& get_then_expression() const { return e_then_; }
831  /** Returns the 'else' expression. */
832  const Expression& get_else_expression() const { return e_else_; }
833 
834  private:
835  static Variables ExtractVariables(const Formula& f_cond,
836  const Expression& e_then,
837  const Expression& e_else);
838 
839  const Formula f_cond_;
840  const Expression e_then_;
841  const Expression e_else_;
842 };
843 
844 /** Symbolic expression representing an uninterpreted function. */
846  public:
847  /** Constructs an uninterpreted-function expression from @p name and @p vars.
848  */
849  ExpressionUninterpretedFunction(const std::string& name,
850  const Variables& vars);
851  bool EqualTo(const ExpressionCell& e) const override;
852  bool Less(const ExpressionCell& e) const override;
853  double Evaluate(const Environment& env) const override;
854  Expression Expand() override;
855  Expression Substitute(const ExpressionSubstitution& expr_subst,
856  const FormulaSubstitution& formula_subst) override;
857  Expression Differentiate(const Variable& x) const override;
858  std::ostream& Display(std::ostream& os) const override;
859 
860  /** Returns the name of this expression. */
861  const std::string& get_name() const { return name_; }
862 
863  private:
864  const std::string name_;
865  const Variables variables_;
866 };
867 
868 /** Checks if @p c is a floating-point constant expression. */
869 bool is_constant(const ExpressionCell& c);
870 /** Checks if @p c is a real constant expression. */
871 bool is_real_constant(const ExpressionCell& c);
872 /** Checks if @p c is a variable expression. */
873 bool is_variable(const ExpressionCell& c);
874 /** Checks if @p c is an addition expression. */
875 bool is_addition(const ExpressionCell& c);
876 /** Checks if @p c is an multiplication expression. */
877 bool is_multiplication(const ExpressionCell& c);
878 /** Checks if @p c is a division expression. */
879 bool is_division(const ExpressionCell& c);
880 /** Checks if @p c is a log expression. */
881 bool is_log(const ExpressionCell& c);
882 /** Checks if @p c is an absolute-value-function expression. */
883 bool is_abs(const ExpressionCell& c);
884 /** Checks if @p c is an exp expression. */
885 bool is_exp(const ExpressionCell& c);
886 /** Checks if @p c is a square-root expression. */
887 bool is_sqrt(const ExpressionCell& c);
888 /** Checks if @p c is a power-function expression. */
889 bool is_pow(const ExpressionCell& c);
890 /** Checks if @p c is a sine expression. */
891 bool is_sin(const ExpressionCell& c);
892 /** Checks if @p c is a cosine expression. */
893 bool is_cos(const ExpressionCell& c);
894 /** Checks if @p c is a tangent expression. */
895 bool is_tan(const ExpressionCell& c);
896 /** Checks if @p c is an arcsine expression. */
897 bool is_asin(const ExpressionCell& c);
898 /** Checks if @p c is an arccosine expression. */
899 bool is_acos(const ExpressionCell& c);
900 /** Checks if @p c is an arctangent expression. */
901 bool is_atan(const ExpressionCell& c);
902 /** Checks if @p c is a arctangent2 expression. */
903 bool is_atan2(const ExpressionCell& c);
904 /** Checks if @p c is a hyperbolic-sine expression. */
905 bool is_sinh(const ExpressionCell& c);
906 /** Checks if @p c is a hyperbolic-cosine expression. */
907 bool is_cosh(const ExpressionCell& c);
908 /** Checks if @p c is a hyperbolic-tangent expression. */
909 bool is_tanh(const ExpressionCell& c);
910 /** Checks if @p c is a min expression. */
911 bool is_min(const ExpressionCell& c);
912 /** Checks if @p c is a max expression. */
913 bool is_max(const ExpressionCell& c);
914 /** Checks if @p c is an if-then-else expression. */
915 bool is_if_then_else(const ExpressionCell& c);
916 /** Checks if @p c is an uninterpreted-function expression. */
917 bool is_uninterpreted_function(const ExpressionCell& c);
918 
919 /** Casts @p expr_ptr of const ExpressionCell* to
920  * @c const ExpressionConstant*.
921  * @pre @p *expr_ptr is of @c ExpressionConstant.
922  */
923 const ExpressionConstant* to_constant(const ExpressionCell* expr_ptr);
924 /** Casts @p e of Expression to @c const ExpressionConstant*.
925  * @pre @p *(e.ptr_) is of @c ExpressionConstant.
926  */
927 const ExpressionConstant* to_constant(const Expression& e);
928 
929 /** Casts @p expr_ptr of const ExpressionCell* to
930  * @c const ExpressionRealConstant*.
931  * @pre @p *expr_ptr is of @c ExpressionRealConstant.
932  */
933 const ExpressionRealConstant* to_real_constant(const ExpressionCell* expr_ptr);
934 /** Casts @p e of Expression to @c const ExpressionRealConstant*.
935  * @pre @p *(e.ptr_) is of @c ExpressionRealConstant.
936  */
937 const ExpressionRealConstant* to_real_constant(const Expression& e);
938 
939 /** Casts @p expr_ptr of const ExpressionCell* to
940  * @c const ExpressionVar*.
941  * @pre @p *expr_ptr is of @c ExpressionVar.
942  */
943 const ExpressionVar* to_variable(const ExpressionCell* expr_ptr);
944 /** Casts @p e of Expression to @c const ExpressionVar*.
945  * @pre @p *(e.ptr_) is of @c ExpressionVar.
946  */
947 const ExpressionVar* to_variable(const Expression& e);
948 
949 /** Casts @p expr_ptr of const ExpressionCell* to
950  * @c const UnaryExpressionCell*.
951  * @pre @c *expr_ptr is of @c UnaryExpressionCell.
952  */
953 const UnaryExpressionCell* to_unary(const ExpressionCell* expr_ptr);
954 /** Casts @p e of Expression to @c const UnaryExpressionCell*.
955  * @pre @c *(e.ptr_) is of @c UnaryExpressionCell.
956  */
957 const UnaryExpressionCell* to_unary(const Expression& e);
958 
959 /** Casts @p expr_ptr of const ExpressionCell* to
960  * @c const BinaryExpressionCell*.
961  * @pre @c *expr_ptr is of @c BinaryExpressionCell.
962  */
963 const BinaryExpressionCell* to_binary(const ExpressionCell* expr_ptr);
964 /** Casts @p e of Expression to @c const BinaryExpressionCell*.
965  * @pre @c *(e.ptr_) is of @c BinaryExpressionCell.
966  */
967 const BinaryExpressionCell* to_binary(const Expression& e);
968 
969 /** Casts @p expr_ptr of const ExpressionCell* to
970  * @c const ExpressionAdd*.
971  * @pre @c *expr_ptr is of @c ExpressionAdd.
972  */
973 const ExpressionAdd* to_addition(const ExpressionCell* expr_ptr);
974 /** Casts @p e of Expression to @c const ExpressionAdd*.
975  * @pre @c *(e.ptr_) is of @c ExpressionAdd.
976  */
977 const ExpressionAdd* to_addition(const Expression& e);
978 /** Casts @p expr_ptr of ExpressionCell* to @c ExpressionAdd*.
979  * @pre @c *expr_ptr is of @c ExpressionAdd.
980  */
981 ExpressionAdd* to_addition(ExpressionCell* expr_ptr);
982 /** Casts @p e of Expression to @c ExpressionAdd*.
983  * @pre @c *(e.ptr_) is of @c ExpressionAdd.
984  */
985 ExpressionAdd* to_addition(Expression& e);
986 
987 /** Casts @p expr_ptr of const ExpressionCell* to
988  * @c const ExpressionMul*.
989  * @pre @c *expr_ptr is of @c ExpressionMul.
990  */
991 const ExpressionMul* to_multiplication(const ExpressionCell* expr_ptr);
992 /** Casts @p e of Expression to @c const ExpressionMul*.
993  * @pre @c *(e.ptr_) is of @c ExpressionMul.
994  */
995 const ExpressionMul* to_multiplication(const Expression& e);
996 /** Casts @p expr_ptr of ExpressionCell* to @c ExpressionMul*.
997  * @pre @c *expr_ptr is of @c ExpressionMul.
998  */
999 ExpressionMul* to_multiplication(ExpressionCell* expr_ptr);
1000 /** Casts @p e of Expression to @c ExpressionMul*.
1001  * @pre @c *(e.ptr_) is of @c ExpressionMul.
1002  */
1003 ExpressionMul* to_multiplication(Expression& e);
1004 
1005 /** Casts @p expr_ptr of const ExpressionCell* to
1006  * @c const ExpressionDiv*.
1007  * @pre @c *expr_ptr is of @c ExpressionDiv.
1008  */
1009 const ExpressionDiv* to_division(const ExpressionCell* expr_ptr);
1010 /** Casts @p e of Expression to @c const ExpressionDiv*.
1011  * @pre @c *(e.ptr_) is of @c ExpressionDiv.
1012  */
1013 const ExpressionDiv* to_division(const Expression& e);
1014 
1015 /** Casts @p expr_ptr of const ExpressionCell* to
1016  * @c const ExpressionLog*.
1017  * @pre @c *expr_ptr is of @c ExpressionLog.
1018  */
1019 const ExpressionLog* to_log(const ExpressionCell* expr_ptr);
1020 /** Casts @p e of Expression to @c const ExpressionLog*.
1021  * @pre @c *(e.ptr_) is of @c ExpressionLog.
1022  */
1023 const ExpressionLog* to_log(const Expression& e);
1024 
1025 /** Casts @p expr_ptr of const ExpressionCell* to
1026  * @c const ExpressionExp*.
1027  * @pre @c *expr_ptr is of @c ExpressionExp.
1028  */
1029 const ExpressionExp* to_exp(const ExpressionCell* expr_ptr);
1030 /** Casts @p e of Expression to @c const ExpressionExp*.
1031  * @pre @c *(e.ptr_) is of @c ExpressionExp.
1032  */
1033 const ExpressionExp* to_exp(const Expression& e);
1034 
1035 /** Casts @p expr_ptr of const ExpressionCell* to
1036  * @c const ExpressionAbs*.
1037  * @pre @c *expr_ptr is of @c ExpressionAbs.
1038  */
1039 const ExpressionAbs* to_abs(const ExpressionCell* expr_ptr);
1040 /** Casts @p e of Expression to @c const ExpressionAbs*.
1041  * @pre @c *(e.ptr_) is of @c ExpressionAbs.
1042  */
1043 const ExpressionAbs* to_abs(const Expression& e);
1044 
1045 /** Casts @p expr_ptr of const ExpressionCell* to
1046  * @c const ExpressionExp*.
1047  * @pre @c *expr_ptr is of @c ExpressionExp.
1048  */
1049 const ExpressionExp* to_exp(const ExpressionCell* expr_ptr);
1050 /** Casts @p e of Expression to @c const ExpressionExp*.
1051  * @pre @c *(e.ptr_) is of @c ExpressionExp.
1052  */
1053 const ExpressionExp* to_exp(const Expression& e);
1054 
1055 /** Casts @p expr_ptr of const ExpressionCell* to
1056  * @c const ExpressionSqrt*.
1057  * @pre @c *expr_ptr is of @c ExpressionSqrt.
1058  */
1059 const ExpressionSqrt* to_sqrt(const ExpressionCell* expr_ptr);
1060 /** Casts @p e of Expression to @c const ExpressionSqrt*.
1061  * @pre @c *(e.ptr_) is of @c ExpressionSqrt.
1062  */
1063 const ExpressionSqrt* to_sqrt(const Expression& e);
1064 
1065 /** Casts @p expr_ptr of const ExpressionCell* to
1066  * @c const ExpressionPow*.
1067  * @pre @c *expr_ptr is of @c ExpressionPow.
1068  */
1069 const ExpressionPow* to_pow(const ExpressionCell* expr_ptr);
1070 /** Casts @p e of Expression to @c const ExpressionPow*.
1071  * @pre @c *(e.ptr_) is of @c ExpressionPow.
1072  */
1073 const ExpressionPow* to_pow(const Expression& e);
1074 
1075 /** Casts @p expr_ptr of const ExpressionCell* to
1076  * @c const ExpressionSin*.
1077  * @pre @c *expr_ptr is of @c ExpressionSin.
1078  */
1079 const ExpressionSin* to_sin(const ExpressionCell* expr_ptr);
1080 /** Casts @p e of Expression to @c const ExpressionSin*.
1081  * @pre @c *(e.ptr_) is of @c ExpressionSin.
1082  */
1083 const ExpressionSin* to_sin(const Expression& e);
1084 
1085 /** Casts @p expr_ptr of const ExpressionCell* to
1086  * @c const ExpressionCos*.
1087  * @pre @c *expr_ptr is of @c ExpressionCos.
1088  */
1089 const ExpressionCos* to_cos(const ExpressionCell* expr_ptr);
1090 /** Casts @p e of Expression to @c const ExpressionCos*.
1091  * @pre @c *(e.ptr_) is of @c ExpressionCos.
1092  */
1093 const ExpressionCos* to_cos(const Expression& e);
1094 
1095 /** Casts @p expr_ptr of const ExpressionCell* to
1096  * @c const ExpressionTan*.
1097  * @pre @c *expr_ptr is of @c ExpressionTan.
1098  */
1099 const ExpressionTan* to_tan(const ExpressionCell* expr_ptr);
1100 /** Casts @p e of Expression to @c const ExpressionTan*.
1101  * @pre @c *(e.ptr_) is of @c ExpressionTan.
1102  */
1103 const ExpressionTan* to_tan(const Expression& e);
1104 
1105 /** Casts @p expr_ptr of const ExpressionCell* to
1106  * @c const ExpressionAsin*.
1107  * @pre @c *expr_ptr is of @c ExpressionAsin.
1108  */
1109 const ExpressionAsin* to_asin(const ExpressionCell* expr_ptr);
1110 /** Casts @p e of Expression to @c const ExpressionAsin*.
1111  * @pre @c *(e.ptr_) is of @c ExpressionAsin.
1112  */
1113 const ExpressionAsin* to_asin(const Expression& e);
1114 
1115 /** Casts @p expr_ptr of const ExpressionCell* to
1116  * @c const ExpressionAcos*.
1117  * @pre @c *expr_ptr is of @c ExpressionAcos.
1118  */
1119 const ExpressionAcos* to_acos(const ExpressionCell* expr_ptr);
1120 /** Casts @p e of Expression to @c const ExpressionAcos*.
1121  * @pre @c *(e.ptr_) is of @c ExpressionAcos.
1122  */
1123 const ExpressionAcos* to_acos(const Expression& e);
1124 
1125 /** Casts @p expr_ptr of const ExpressionCell* to
1126  * @c const ExpressionAtan*.
1127  * @pre @c *expr_ptr is of @c ExpressionAtan.
1128  */
1129 const ExpressionAtan* to_atan(const ExpressionCell* expr_ptr);
1130 /** Casts @p e of Expression to @c const ExpressionAtan*.
1131  * @pre @c *(e.ptr_) is of @c ExpressionAtan.
1132  */
1133 const ExpressionAtan* to_atan(const Expression& e);
1134 
1135 /** Casts @p expr_ptr of const ExpressionCell* to
1136  * @c const ExpressionAtan2*.
1137  * @pre @c *expr_ptr is of @c ExpressionAtan2.
1138  */
1139 const ExpressionAtan2* to_atan2(const ExpressionCell* expr_ptr);
1140 /** Casts @p e of Expression to @c const ExpressionAtan2*.
1141  * @pre @c *(e.ptr_) is of @c ExpressionAtan2.
1142  */
1143 const ExpressionAtan2* to_atan2(const Expression& e);
1144 
1145 /** Casts @p expr_ptr of const ExpressionCell* to
1146  * @c const ExpressionSinh*.
1147  * @pre @c *expr_ptr is of @c ExpressionSinh.
1148  */
1149 const ExpressionSinh* to_sinh(const ExpressionCell* expr_ptr);
1150 /** Casts @p e of Expression to @c const ExpressionSinh*.
1151  * @pre @c *(e.ptr_) is of @c ExpressionSinh.
1152  */
1153 const ExpressionSinh* to_sinh(const Expression& e);
1154 
1155 /** Casts @p expr_ptr of const ExpressionCell* to
1156  * @c const ExpressionCosh*.
1157  * @pre @c *expr_ptr is of @c ExpressionCosh.
1158  */
1159 const ExpressionCosh* to_cosh(const ExpressionCell* expr_ptr);
1160 /** Casts @p e of Expression to @c const ExpressionCosh*.
1161  * @pre @c *(e.ptr_) is of @c ExpressionCosh.
1162  */
1163 const ExpressionCosh* to_cosh(const Expression& e);
1164 
1165 /** Casts @p expr_ptr of const ExpressionCell* to
1166  * @c const ExpressionTanh*.
1167  * @pre @c *expr_ptr is of @c ExpressionTanh.
1168  */
1169 const ExpressionTanh* to_tanh(const ExpressionCell* expr_ptr);
1170 /** Casts @p e of Expression to @c const ExpressionTanh*.
1171  * @pre @c *(e.ptr_) is of @c ExpressionTanh.
1172  */
1173 const ExpressionTanh* to_tanh(const Expression& e);
1174 
1175 /** Casts @p expr_ptr of const ExpressionCell* to
1176  * @c const ExpressionMin*.
1177  * @pre @c *expr_ptr is of @c ExpressionMin.
1178  */
1179 const ExpressionMin* to_min(const ExpressionCell* expr_ptr);
1180 /** Casts @p e of Expression to @c const ExpressionMin*.
1181  * @pre @c *(e.ptr_) is of @c ExpressionMin.
1182  */
1183 const ExpressionMin* to_min(const Expression& e);
1184 
1185 /** Casts @p expr_ptr of const ExpressionCell* to
1186  * @c const ExpressionMax*.
1187  * @pre @c *expr_ptr is of @c ExpressionMax.
1188  */
1189 const ExpressionMax* to_max(const ExpressionCell* expr_ptr);
1190 /** Casts @p e of Expression to @c const ExpressionMax*.
1191  * @pre @c *(e.ptr_) is of @c ExpressionMax.
1192  */
1193 const ExpressionMax* to_max(const Expression& e);
1194 
1195 /** Casts @p expr_ptr of const ExpressionCell* to
1196  * @c const ExpressionIfThenElse*.
1197  * @pre @c *expr_ptr is of @c ExpressionIfThenElse.
1198  */
1199 const ExpressionIfThenElse* to_if_then_else(const ExpressionCell* expr_ptr);
1200 /** Casts @p e of Expression to @c const ExpressionIfThenElse*.
1201  * @pre @c *(e.ptr_) is of @c ExpressionIfThenElse.
1202  */
1203 const ExpressionIfThenElse* to_if_then_else(const Expression& e);
1204 
1205 /** Casts @p expr_ptr of const ExpressionCell* to `const
1206  * ExpressionUninterpretedFunction*`.
1207  * @pre @c *expr_ptr is of @c ExpressionUninterpretedFunction.
1208  */
1209 const ExpressionUninterpretedFunction* to_uninterpreted_function(
1210  const ExpressionCell* expr_ptr);
1211 /** Casts @p e of Expression to `const ExpressionUninterpretedFunction*`.
1212  * @pre @c *(e.ptr_) is of @c ExpressionUninterpretedFunction.
1213  */
1214 const ExpressionUninterpretedFunction* to_uninterpreted_function(
1215  const Expression& e);
1216 
1217 } // namespace symbolic
1218 } // namespace drake
1219 } // namespace dreal
Symbolic expression representing tangent function.
Definition: symbolic_expression_cell.h:663
Symbolic expression representing absolute value function.
Definition: symbolic_expression_cell.h:567
virtual bool EqualTo(const ExpressionCell &c) const =0
Checks structural equality.
Symbolic expression representing if-then-else expression.
Definition: symbolic_expression_cell.h:812
const Expression & get_else_expression() const
Returns the &#39;else&#39; expression.
Definition: symbolic_expression_cell.h:832
Symbolic expression representing cosine function.
Definition: symbolic_expression_cell.h:649
Symbolic expression representing an uninterpreted function.
Definition: symbolic_expression_cell.h:845
Symbolic expression representing a multiplication of powers.
Definition: symbolic_expression_cell.h:426
const Expression & get_first_argument() const
Returns the first argument.
Definition: symbolic_expression_cell.h:175
Symbolic expression representing arctangent function.
Definition: symbolic_expression_cell.h:713
spdlog::logger * log()
Provide a global logger.
Definition: logging.cc:33
Represents the base class for unary expressions.
Definition: symbolic_expression_cell.h:130
const std::string & get_name() const
Returns the name of this expression.
Definition: symbolic_expression_cell.h:861
Symbolic expression representing a real constant represented by a double interval [lb...
Definition: symbolic_expression_cell.h:256
Sum type of symbolic::Expression and symbolic::Formula.
Definition: api.cc:9
double get_constant() const
Returns the constant.
Definition: symbolic_expression_cell.h:319
std::map< Expression, double > & get_mutable_expr_to_coeff_map()
Returns map from an expression to its coefficient.
Definition: symbolic_expression_cell.h:328
Symbolic expression representing a floating-point constant (double).
Definition: symbolic_expression_cell.h:233
Represents an abstract class which is the base of concrete symbolic-expression classes.
Definition: symbolic_expression_cell.h:26
Symbolic expression representing hyperbolic sine function.
Definition: symbolic_expression_cell.h:742
virtual bool Less(const ExpressionCell &c) const =0
Provides lexicographical ordering between expressions.
virtual std::ostream & Display(std::ostream &os) const =0
Outputs string representation of expression into output stream os.
Represents a symbolic variable.
Definition: symbolic_variable.h:16
size_t get_hash() const
Returns hash value.
Definition: symbolic_expression_cell.h:32
Symbolic expression representing hyperbolic cosine function.
Definition: symbolic_expression_cell.h:756
Symbolic expression representing hyperbolic tangent function.
Definition: symbolic_expression_cell.h:770
ExpressionCell & operator=(ExpressionCell &&e)=delete
Move-assigns (DELETED).
double get_constant() const
Returns constant term.
Definition: symbolic_expression_cell.h:440
const Expression & get_second_argument() const
Returns the second argument.
Definition: symbolic_expression_cell.h:177
Symbolic expression representing a variable.
Definition: symbolic_expression_cell.h:212
const std::map< Expression, double > & get_expr_to_coeff_map() const
Returns map from an expression to its coefficient.
Definition: symbolic_expression_cell.h:321
bool include_ite() const
Returns true if this symbolic expression includes an ITE (If-Then-Else) expression.
Definition: symbolic_expression_cell.h:48
virtual ~ExpressionCell()=default
Default destructor.
Symbolic expression representing square-root.
Definition: symbolic_expression_cell.h:598
Expression GetExpression()
Returns an expression pointing to this ExpressionCell.
Definition: symbolic_expression_cell.cc:246
Symbolic expression representing exponentiation using the base of natural logarithms.
Definition: symbolic_expression_cell.h:584
Factory class to help build ExpressionAdd expressions.
Definition: symbolic_expression_cell.h:348
const std::map< Expression, Expression > & get_base_to_exponent_map() const
Returns map from a term to its exponent.
Definition: symbolic_expression_cell.h:442
virtual Expression Differentiate(const Variable &x) const =0
Differentiates this symbolic expression with respect to the variable var.
ExpressionKind get_kind() const
Returns expression kind.
Definition: symbolic_expression_cell.h:29
Represents a symbolic environment (mapping from a variable to a value).
Definition: symbolic_environment.h:52
bool is_polynomial() const
Checks if this symbolic expression is convertible to Polynomial.
Definition: symbolic_expression_cell.h:44
const Formula & get_conditional_formula() const
Returns the conditional formula.
Definition: symbolic_expression_cell.h:828
Symbolic expression representing logarithms.
Definition: symbolic_expression_cell.h:549
Symbolic expression representing division.
Definition: symbolic_expression_cell.h:535
Symbolic expression representing sine function.
Definition: symbolic_expression_cell.h:635
Factory class to help build ExpressionMul expressions.
Definition: symbolic_expression_cell.h:470
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...
Symbolic expression representing an addition which is a sum of products.
Definition: symbolic_expression_cell.h:304
Symbolic expression representing min function.
Definition: symbolic_expression_cell.h:784
Symbolic expression representing arcsine function.
Definition: symbolic_expression_cell.h:677
Symbolic expression representing arccosine function.
Definition: symbolic_expression_cell.h:695
virtual double Evaluate(const Environment &env) const =0
Evaluates under a given environment (by default, an empty environment).
virtual Expression Expand()=0
Expands out products and positive integer powers in expression.
std::map< Expression, Expression > & get_mutable_base_to_exponent_map()
Returns map from a term to its exponent.
Definition: symbolic_expression_cell.h:449
Symbolic expression representing max function.
Definition: symbolic_expression_cell.h:798
Represents the base class for binary expressions.
Definition: symbolic_expression_cell.h:169
unsigned use_count() const
Returns the reference count of this cell.
Definition: symbolic_expression_cell.h:78
Symbolic expression representing atan2 function (arctangent function with two arguments).
Definition: symbolic_expression_cell.h:728
Represents a set of variables.
Definition: symbolic_variables.h:25
Represents a symbolic form of an expression.
Definition: symbolic_expression.h:164
Symbolic expression representing NaN (not-a-number).
Definition: symbolic_expression_cell.h:278
ExpressionCell()=delete
Default constructor (DELETED).
Represents a symbolic form of a first-order logic formula.
Definition: symbolic_formula.h:101
Symbolic expression representing power function.
Definition: symbolic_expression_cell.h:616
const Expression & get_then_expression() const
Returns the &#39;then&#39; expression.
Definition: symbolic_expression_cell.h:830
const Variables & GetVariables() const
Collects variables in expression.
Definition: symbolic_expression_cell.cc:248
const Expression & get_argument() const
Returns the argument.
Definition: symbolic_expression_cell.h:136