dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
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#include <optional>
10
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"
17
18namespace dlinear::drake::symbolic {
19
27 public:
29 ExpressionKind get_kind() const { return kind_; }
30
32 size_t get_hash() const;
33
35 const Variables &GetVariables() const;
36
38 virtual bool EqualTo(const ExpressionCell &c) const = 0;
39
41 virtual bool Less(const ExpressionCell &c) const = 0;
42
44 bool is_polynomial() const;
45
48 bool include_ite() const;
49
53 virtual mpq_class Evaluate(const Environment &env) const = 0;
54
58 virtual Expression Expand() = 0;
59
65 virtual Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) = 0;
66
71 virtual Expression Differentiate(const Variable &x) const = 0;
72
74 virtual std::ostream &Display(std::ostream &os) const = 0;
75
76 virtual std::string to_smt2_string() const = 0;
77
79#ifdef DLINEAR_ENABLED_THREADS
80 unsigned use_count() const { return atomic_load_explicit(&rc_, std::memory_order_acquire); }
81#else
82 unsigned use_count() const { return rc_; }
83#endif
84
86 ExpressionCell(const ExpressionCell &e) = delete;
87
90
93
96
98 virtual void UpdateHash();
99
100 protected:
102 explicit ExpressionCell(ExpressionKind k);
105 ExpressionCell(ExpressionKind k, bool is_poly);
108 ExpressionCell(ExpressionKind k, bool is_poly, bool include_ite);
111 ExpressionCell(ExpressionKind k, bool is_poly, bool include_ite, Variables variables);
114 ExpressionCell(ExpressionKind k, bool is_poly, bool include_ite, Variables variables, size_t hash);
116 virtual ~ExpressionCell() = default;
119
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;
124
125 void UpdateHash(size_t hash);
126
127 private:
128 const ExpressionKind kind_{};
129 mutable std::optional<Variables> variables_;
130 mutable std::optional<size_t> hash_{};
131 mutable std::optional<bool> is_polynomial_{false};
132 mutable std::optional<bool> include_ite_{false};
133
134 // Reference counter.
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) {
140 delete this;
141 }
142 }
143#else
144 mutable unsigned rc_{0};
145 void increase_rc() const { ++rc_; }
146 void decrease_rc() const {
147 if (--rc_ == 0) {
148 delete this;
149 }
150 }
151#endif
152
153 // So that Expression can call {increase,decrease}_rc.
154 friend Expression;
155};
156
159 public:
160 bool EqualTo(const ExpressionCell &e) const override;
161 bool Less(const ExpressionCell &e) const override;
162 mpq_class Evaluate(const Environment &env) const override;
164 const Expression &get_argument() const { return e_; }
165
168
171
174
177
180
182 ~UnaryExpressionCell() override = default;
183
184 protected:
187 UnaryExpressionCell(ExpressionKind k, const Expression &e, bool is_poly);
189 virtual mpq_class DoEvaluate(const mpq_class &v) const = 0;
190
191 private:
192 const Expression e_;
193
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;
197};
198
202 public:
203 bool EqualTo(const ExpressionCell &e) const override;
204 bool Less(const ExpressionCell &e) const override;
205 mpq_class Evaluate(const Environment &env) const override;
207 const Expression &get_first_argument() const { return e1_; }
209 const Expression &get_second_argument() const { return e2_; }
210
213
216
219
222
225
227 ~BinaryExpressionCell() override = default;
228
229 protected:
233 BinaryExpressionCell(ExpressionKind k, const Expression &e1, const Expression &e2, bool is_poly);
235 virtual mpq_class DoEvaluate(const mpq_class &v1, const mpq_class &v2) const = 0;
236
237 private:
238 const Expression e1_;
239 const Expression e2_;
240
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;
244};
245
248 public:
252 explicit ExpressionVar(const Variable &v);
253 const Variable &get_variable() const { return var_; }
254 bool EqualTo(const ExpressionCell &e) const override;
255 bool Less(const ExpressionCell &e) const override;
256 mpq_class Evaluate(const Environment &env) const override;
257 Expression Expand() override;
258 Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override;
259 Expression Differentiate(const Variable &x) const override;
260 std::ostream &Display(std::ostream &os) const override;
261
262 private:
263 const Variable var_;
264
265 void ComputeHash(std::optional<size_t>& hash) const override;
266 std::string to_smt2_string() const override;
267};
268
271 public:
272 explicit ExpressionConstant(const mpq_class &v);
273 const mpq_class& get_value() const { return v_; }
274 bool EqualTo(const ExpressionCell &e) const override;
275 bool Less(const ExpressionCell &e) const override;
276 mpq_class Evaluate(const Environment &env) const override;
277 Expression Expand() override;
278 Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override;
279 Expression Differentiate(const Variable &x) const override;
280 std::ostream &Display(std::ostream &os) const override;
281 std::string to_smt2_string() const override;
282 void UpdateHash() override;
283
284 private:
285 const mpq_class v_{};
286
287 virtual void ComputeHash(std::optional<size_t>& hash) const;
288};
289
292 public:
294 bool EqualTo(const ExpressionCell &e) const override;
295 bool Less(const ExpressionCell &e) const override;
296 mpq_class Evaluate(const Environment &env) const override;
297 Expression Expand() override;
298 Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override;
299 Expression Differentiate(const Variable &x) const override;
300 std::ostream &Display(std::ostream &os) const override;
301 std::string to_smt2_string() const override;
302};
303
306 public:
307 ExpressionInfty(int sign);
308 bool EqualTo(const ExpressionCell &e) const override;
309 bool Less(const ExpressionCell &e) const override;
310 mpq_class Evaluate(const Environment &env) const override;
311 Expression Expand() override;
312 Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override;
313 Expression Differentiate(const Variable &x) const override;
314 std::ostream &Display(std::ostream &os) const override;
315 std::string to_smt2_string() const override;
316 int GetSign() const { return sign_; }
317
318 private:
319 int sign_ = 1;
320};
321
336 public:
339 ExpressionAdd(const mpq_class &constant, std::map<Expression, mpq_class> expr_to_coeff_map);
340 bool EqualTo(const ExpressionCell &e) const override;
341 bool Less(const ExpressionCell &e) const override;
342 mpq_class Evaluate(const Environment &env) const override;
343 Expression Expand() override;
344 Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override;
345 Expression Differentiate(const Variable &x) const override;
346 std::ostream &Display(std::ostream &os) const override;
347 std::string to_smt2_string() const override;
349 const mpq_class& get_constant() const { return constant_; }
351 const std::map<Expression, mpq_class> &get_expr_to_coeff_map() const { return expr_to_coeff_map_; }
352
353 // TODO(soonho): Make the following private and allow
354 // only selected functions/method to use them.
355 mpq_class &get_mutable_constant() { return constant_; }
357 std::map<Expression, mpq_class> &get_mutable_expr_to_coeff_map() { return expr_to_coeff_map_; }
358
359 void UpdateHash() override;
360
361 private:
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;
367
368 mpq_class constant_{};
369 std::map<Expression, mpq_class> expr_to_coeff_map_;
370};
371
379 public:
381 ExpressionAddFactory &operator=(const ExpressionAddFactory &) = default;
382 ExpressionAddFactory(ExpressionAddFactory &&) noexcept = default;
383 ExpressionAddFactory &operator=(ExpressionAddFactory &&) = default;
384
387
390
393 ExpressionAddFactory(const mpq_class& constant, const std::map<Expression, mpq_class>& expr_to_coeff_map);
394 ExpressionAddFactory(mpq_class&& constant, std::map<Expression, mpq_class>&& expr_to_coeff_map);
395
398
405
414
415 private:
416 /* Adds constant to this factory.
417 * Adding constant constant into an add factory representing
418 *
419 * c0 + c1 * t1 + ... + cn * tn
420 *
421 * results in (c0 + constant) + c1 * t1 + ... + cn * tn. */
422 ExpressionAddFactory &AddConstant(const mpq_class &constant);
423 /* Adds coeff * term to this factory.
424 *
425 * Adding (coeff * term) into an add factory representing
426 *
427 * c0 + c1 * t1 + ... + cn * tn
428 *
429 * results in c0 + c1 * t1 + ... + (coeff * term) + ... + cn * tn. Note that
430 * it also performs simplifications to merge the coefficients of common terms.
431 */
432 ExpressionAddFactory &AddTerm(const mpq_class &coeff, const Expression &term);
433 /* Adds expr_to_coeff_map to this factory. It calls AddConstant and AddTerm
434 * methods. */
435 ExpressionAddFactory &AddMap(const std::map<Expression, mpq_class> &expr_to_coeff_map);
436
437 bool get_expression_is_called_{false};
438 mpq_class constant_{0.0};
439 std::map<Expression, mpq_class> expr_to_coeff_map_;
440};
441
456 public:
458 ExpressionMul(const mpq_class &constant, std::map<Expression, Expression> base_to_exponent_map);
459 bool EqualTo(const ExpressionCell &e) const override;
460 bool Less(const ExpressionCell &e) const override;
461 mpq_class Evaluate(const Environment &env) const override;
462 Expression Expand() override;
463 Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override;
464 Expression Differentiate(const Variable &x) const override;
465 std::ostream &Display(std::ostream &os) const override;
466 std::string to_smt2_string() const override;
468 const mpq_class& get_constant() const { return constant_; }
470 const std::map<Expression, Expression> &get_base_to_exponent_map() const { return base_to_exponent_map_; }
471
472 // TODO(soonho): Make the following private and allow
473 // only selected functions/method to use them.
474 mpq_class &get_mutable_constant() { return constant_; }
476 std::map<Expression, Expression> &get_mutable_base_to_exponent_map() { return base_to_exponent_map_; }
477
478 private:
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;
483
484 std::ostream &DisplayTerm(std::ostream &os, bool print_mul, const Expression &base, const Expression &exponent) const;
485
486 mpq_class constant_{};
487 std::map<Expression, Expression> base_to_exponent_map_;
488};
489
497 public:
499 ExpressionMulFactory &operator=(const ExpressionMulFactory &) = default;
500 ExpressionMulFactory(ExpressionMulFactory &&) noexcept = default;
501 ExpressionMulFactory &operator=(ExpressionMulFactory &&) = default;
502
505
508
511 ExpressionMulFactory(const mpq_class &constant, const std::map<Expression, Expression>& base_to_exponent_map);
514 ExpressionMulFactory(mpq_class &&constant, std::map<Expression, Expression>&& base_to_exponent_map);
515
518
533
534 private:
535 /* Adds constant to this factory.
536 Adding constant into an mul factory representing
537
538 c * b1 ^ e1 * ... * bn ^ en
539
540 results in (constant * c) * b1 ^ e1 * ... * bn ^ en. */
541 ExpressionMulFactory &AddConstant(const mpq_class &constant);
542 /* Adds pow(base, exponent) to this factory.
543 Adding pow(base, exponent) into an mul factory representing
544
545 c * b1 ^ e1 * ... * bn ^ en
546
547 results in c * b1 ^ e1 * ... * base^exponent * ... * bn ^ en. Note that
548 it also performs simplifications to merge the exponents of common bases.
549 */
550 ExpressionMulFactory &AddTerm(const Expression &base, const Expression &exponent);
551 /* Adds base_to_exponent_map to this factory. It calls AddConstant and AddTerm
552 * methods. */
553 ExpressionMulFactory &AddMap(const std::map<Expression, Expression> &base_to_exponent_map);
554
555 bool get_expression_is_called_{false};
556 mpq_class constant_{1.0};
557 std::map<Expression, Expression> base_to_exponent_map_;
558};
559
562 public:
563 ExpressionDiv(const Expression &e1, const Expression &e2);
564 Expression Expand() override;
565 Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override;
566 Expression Differentiate(const Variable &x) const override;
567 std::ostream &Display(std::ostream &os) const override;
568 std::string to_smt2_string() const override;
569
570 private:
571 mpq_class DoEvaluate(const mpq_class &v1, const mpq_class &v2) const override;
572};
573
576 public:
577 explicit ExpressionLog(const Expression &e);
578 Expression Expand() override;
579 Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override;
580 Expression Differentiate(const Variable &x) const override;
581 std::ostream &Display(std::ostream &os) const override;
582 std::string to_smt2_string() const override;
583
584 friend Expression log(const Expression &e);
585
586 private:
587 /* Throws std::domain_error if v ∉ [0, +oo). */
588 static void check_domain(const mpq_class &v);
589 mpq_class DoEvaluate(const mpq_class &v) const override;
590};
591
594 public:
595 explicit ExpressionAbs(const Expression &e);
596 Expression Expand() override;
597 Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override;
598 Expression Differentiate(const Variable &x) const override;
599 std::ostream &Display(std::ostream &os) const override;
600 std::string to_smt2_string() const override;
601
602 friend Expression abs(const Expression &e);
603
604 private:
605 mpq_class DoEvaluate(const mpq_class &v) const override;
606};
607
611 public:
612 explicit ExpressionExp(const Expression &e);
613 Expression Expand() override;
614 Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override;
615 Expression Differentiate(const Variable &x) const override;
616 std::ostream &Display(std::ostream &os) const override;
617 std::string to_smt2_string() const override;
618
619 private:
620 mpq_class DoEvaluate(const mpq_class &v) const override;
621};
622
625 public:
626 explicit ExpressionSqrt(const Expression &e);
627 Expression Expand() override;
628 Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override;
629 Expression Differentiate(const Variable &x) const override;
630 std::ostream &Display(std::ostream &os) const override;
631 std::string to_smt2_string() const override;
632
633 friend Expression sqrt(const Expression &e);
634
635 private:
636 /* Throws std::domain_error if v ∉ [0, +oo). */
637 static void check_domain(const mpq_class &v);
638 mpq_class DoEvaluate(const mpq_class &v) const override;
639};
640
643 public:
644 ExpressionPow(const Expression &e1, const Expression &e2);
645 Expression Expand() override;
646 Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override;
647 Expression Differentiate(const Variable &x) const override;
648 std::ostream &Display(std::ostream &os) const override;
649 std::string to_smt2_string() const override;
650
651 friend Expression pow(const Expression &e1, const Expression &e2);
652
653 private:
654 /* Throws std::domain_error if v1 is finite negative and v2 is finite
655 non-integer. */
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;
658};
659
662 public:
663 explicit ExpressionSin(const Expression &e);
664 Expression Expand() override;
665 Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override;
666 Expression Differentiate(const Variable &x) const override;
667 std::ostream &Display(std::ostream &os) const override;
668 std::string to_smt2_string() const override;
669
670 private:
671 mpq_class DoEvaluate(const mpq_class &v) const override;
672};
673
676 public:
677 explicit ExpressionCos(const Expression &e);
678 Expression Expand() override;
679 Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override;
680 Expression Differentiate(const Variable &x) const override;
681 std::ostream &Display(std::ostream &os) const override;
682 std::string to_smt2_string() const override;
683
684 private:
685 mpq_class DoEvaluate(const mpq_class &v) const override;
686};
687
690 public:
691 explicit ExpressionTan(const Expression &e);
692 Expression Expand() override;
693 Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override;
694 Expression Differentiate(const Variable &x) const override;
695 std::ostream &Display(std::ostream &os) const override;
696 std::string to_smt2_string() const override;
697
698 private:
699 mpq_class DoEvaluate(const mpq_class &v) const override;
700};
701
704 public:
705 explicit ExpressionAsin(const Expression &e);
706 Expression Expand() override;
707 Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override;
708 Expression Differentiate(const Variable &x) const override;
709 std::ostream &Display(std::ostream &os) const override;
710 std::string to_smt2_string() const override;
711
712 friend Expression asin(const Expression &e);
713
714 private:
715 /* Throws std::domain_error if v ∉ [-1.0, +1.0]. */
716 static void check_domain(const mpq_class &v);
717 mpq_class DoEvaluate(const mpq_class &v) const override;
718};
719
722 public:
723 explicit ExpressionAcos(const Expression &e);
724 Expression Expand() override;
725 Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override;
726 Expression Differentiate(const Variable &x) const override;
727 std::ostream &Display(std::ostream &os) const override;
728 std::string to_smt2_string() const override;
729
730 friend Expression acos(const Expression &e);
731
732 private:
733 /* Throws std::domain_error if v ∉ [-1.0, +1.0]. */
734 static void check_domain(const mpq_class &v);
735 mpq_class DoEvaluate(const mpq_class &v) const override;
736};
737
740 public:
741 explicit ExpressionAtan(const Expression &e);
742 Expression Expand() override;
743 Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override;
744 Expression Differentiate(const Variable &x) const override;
745 std::ostream &Display(std::ostream &os) const override;
746 std::string to_smt2_string() const override;
747
748 private:
749 mpq_class DoEvaluate(const mpq_class &v) const override;
750};
751
755 public:
756 ExpressionAtan2(const Expression &e1, const Expression &e2);
757 Expression Expand() override;
758 Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override;
759 Expression Differentiate(const Variable &x) const override;
760 std::ostream &Display(std::ostream &os) const override;
761 std::string to_smt2_string() const override;
762
763 private:
764 mpq_class DoEvaluate(const mpq_class &v1, const mpq_class &v2) const override;
765};
766
769 public:
770 explicit ExpressionSinh(const Expression &e);
771 Expression Expand() override;
772 Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override;
773 Expression Differentiate(const Variable &x) const override;
774 std::ostream &Display(std::ostream &os) const override;
775 std::string to_smt2_string() const override;
776
777 private:
778 mpq_class DoEvaluate(const mpq_class &v) const override;
779};
780
783 public:
784 explicit ExpressionCosh(const Expression &e);
785 Expression Expand() override;
786 Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override;
787 Expression Differentiate(const Variable &x) const override;
788 std::ostream &Display(std::ostream &os) const override;
789 std::string to_smt2_string() const override;
790
791 private:
792 mpq_class DoEvaluate(const mpq_class &v) const override;
793};
794
797 public:
798 explicit ExpressionTanh(const Expression &e);
799 Expression Expand() override;
800 Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override;
801 Expression Differentiate(const Variable &x) const override;
802 std::ostream &Display(std::ostream &os) const override;
803 std::string to_smt2_string() const override;
804
805 private:
806 mpq_class DoEvaluate(const mpq_class &v) const override;
807};
808
811 public:
812 ExpressionMin(const Expression &e1, const Expression &e2);
813 Expression Expand() override;
814 Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override;
815 Expression Differentiate(const Variable &x) const override;
816 std::ostream &Display(std::ostream &os) const override;
817 std::string to_smt2_string() const override;
818
819 private:
820 mpq_class DoEvaluate(const mpq_class &v1, const mpq_class &v2) const override;
821};
822
825 public:
826 ExpressionMax(const Expression &e1, const Expression &e2);
827 Expression Expand() override;
828 Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override;
829 Expression Differentiate(const Variable &x) const override;
830 std::ostream &Display(std::ostream &os) const override;
831 std::string to_smt2_string() const override;
832
833 private:
834 mpq_class DoEvaluate(const mpq_class &v1, const mpq_class &v2) const override;
835};
836
839 public:
842 ExpressionIfThenElse(const Formula &f_cond, const Expression &e_then, const Expression &e_else);
843 bool EqualTo(const ExpressionCell &e) const override;
844 bool Less(const ExpressionCell &e) const override;
845 mpq_class Evaluate(const Environment &env) const override;
846 Expression Expand() override;
847 Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override;
848 Expression Differentiate(const Variable &x) const override;
849 std::ostream &Display(std::ostream &os) const override;
850 std::string to_smt2_string() const override;
851
853 const Formula &get_conditional_formula() const { return f_cond_; }
855 const Expression &get_then_expression() const { return e_then_; }
857 const Expression &get_else_expression() const { return e_else_; }
858
859 private:
860 void ComputeVariables(std::optional<Variables>& variables) const override;
861 void ComputeHash(std::optional<size_t>& hash) const override;
862
863 const Formula f_cond_;
864 const Expression e_then_;
865 const Expression e_else_;
866};
867
870 public:
873 ExpressionUninterpretedFunction(const std::string &name, const Variables &vars);
874 bool EqualTo(const ExpressionCell &e) const override;
875 bool Less(const ExpressionCell &e) const override;
876 mpq_class Evaluate(const Environment &env) const override;
877 Expression Expand() override;
878 Expression Substitute(const ExpressionSubstitution &expr_subst, const FormulaSubstitution &formula_subst) override;
879 Expression Differentiate(const Variable &x) const override;
880 std::ostream &Display(std::ostream &os) const override;
881 std::string to_smt2_string() const override;
882
884 const std::string &get_name() const { return name_; }
885
886 private:
887 const std::string name_;
888 const Variables variables_;
889
890 void ComputeHash(std::optional<size_t>& hash) const override;
891};
892
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);
943
948const ExpressionConstant *to_constant(const ExpressionCell *expr_ptr);
952const ExpressionConstant *to_constant(const Expression &e);
953
958const ExpressionInfty *to_infty(const ExpressionCell *expr_ptr);
962const ExpressionInfty *to_infty(const Expression &e);
963
968const ExpressionVar *to_variable(const ExpressionCell *expr_ptr);
972const ExpressionVar *to_variable(const Expression &e);
973
978const UnaryExpressionCell *to_unary(const ExpressionCell *expr_ptr);
982const UnaryExpressionCell *to_unary(const Expression &e);
983
988const BinaryExpressionCell *to_binary(const ExpressionCell *expr_ptr);
992const BinaryExpressionCell *to_binary(const Expression &e);
993
998const ExpressionAdd *to_addition(const ExpressionCell *expr_ptr);
1002const ExpressionAdd *to_addition(const Expression &e);
1006ExpressionAdd *to_addition(ExpressionCell *expr_ptr);
1010ExpressionAdd *to_addition(Expression &e);
1011
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);
1029
1034const ExpressionDiv *to_division(const ExpressionCell *expr_ptr);
1038const ExpressionDiv *to_division(const Expression &e);
1039
1044const ExpressionLog *to_log(const ExpressionCell *expr_ptr);
1048const ExpressionLog *to_log(const Expression &e);
1049
1054const ExpressionExp *to_exp(const ExpressionCell *expr_ptr);
1058const ExpressionExp *to_exp(const Expression &e);
1059
1064const ExpressionAbs *to_abs(const ExpressionCell *expr_ptr);
1068const ExpressionAbs *to_abs(const Expression &e);
1069
1074const ExpressionExp *to_exp(const ExpressionCell *expr_ptr);
1078const ExpressionExp *to_exp(const Expression &e);
1079
1084const ExpressionSqrt *to_sqrt(const ExpressionCell *expr_ptr);
1088const ExpressionSqrt *to_sqrt(const Expression &e);
1089
1094const ExpressionPow *to_pow(const ExpressionCell *expr_ptr);
1098const ExpressionPow *to_pow(const Expression &e);
1099
1104const ExpressionSin *to_sin(const ExpressionCell *expr_ptr);
1108const ExpressionSin *to_sin(const Expression &e);
1109
1114const ExpressionCos *to_cos(const ExpressionCell *expr_ptr);
1118const ExpressionCos *to_cos(const Expression &e);
1119
1124const ExpressionTan *to_tan(const ExpressionCell *expr_ptr);
1128const ExpressionTan *to_tan(const Expression &e);
1129
1134const ExpressionAsin *to_asin(const ExpressionCell *expr_ptr);
1138const ExpressionAsin *to_asin(const Expression &e);
1139
1144const ExpressionAcos *to_acos(const ExpressionCell *expr_ptr);
1148const ExpressionAcos *to_acos(const Expression &e);
1149
1154const ExpressionAtan *to_atan(const ExpressionCell *expr_ptr);
1158const ExpressionAtan *to_atan(const Expression &e);
1159
1164const ExpressionAtan2 *to_atan2(const ExpressionCell *expr_ptr);
1168const ExpressionAtan2 *to_atan2(const Expression &e);
1169
1174const ExpressionSinh *to_sinh(const ExpressionCell *expr_ptr);
1178const ExpressionSinh *to_sinh(const Expression &e);
1179
1184const ExpressionCosh *to_cosh(const ExpressionCell *expr_ptr);
1188const ExpressionCosh *to_cosh(const Expression &e);
1189
1194const ExpressionTanh *to_tanh(const ExpressionCell *expr_ptr);
1198const ExpressionTanh *to_tanh(const Expression &e);
1199
1204const ExpressionMin *to_min(const ExpressionCell *expr_ptr);
1208const ExpressionMin *to_min(const Expression &e);
1209
1214const ExpressionMax *to_max(const ExpressionCell *expr_ptr);
1218const ExpressionMax *to_max(const Expression &e);
1219
1224const ExpressionIfThenElse *to_if_then_else(const ExpressionCell *expr_ptr);
1228const ExpressionIfThenElse *to_if_then_else(const Expression &e);
1229
1234const ExpressionUninterpretedFunction *to_uninterpreted_function(const ExpressionCell *expr_ptr);
1238const ExpressionUninterpretedFunction *to_uninterpreted_function(const Expression &e);
1239
1240} // namespace dlinear::drake::symbolic
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 a symbolic form of a first-order logic formula.
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.