dReal4
term.h
1 #pragma once
2 
3 #include <iostream>
4 
5 #include "dreal/smt2/sort.h"
7 
8 /// Sum type of symbolic::Expression and symbolic::Formula.
9 namespace dreal {
10 class Term {
11  public:
12  enum class Type { EXPRESSION, FORMULA };
13 
14  /// Default Constructor. It constructs Term(false).
15  Term();
16 
17  /// Construct a term with @p e.
18  explicit Term(Expression e);
19 
20  /// Construct a term with @p f.
21  explicit Term(Formula f);
22 
23  /// Default copy constructor.
24  Term(const Term&) = default;
25 
26  /// Default move constructor.
27  Term(Term&&) = default;
28 
29  /// Default copy assign operator.
30  Term& operator=(const Term&) = default;
31 
32  /// Default move assign operator.
33  Term& operator=(Term&&) = default;
34 
35  /// Default destructor.
36  ~Term() = default;
37 
38  /// Assignment operator.
40 
41  /// Assignment operator.
43 
44  /// Returns its type.
45  Type type() const;
46 
47  /// Returns the expression inside.
48  /// @throw runtime_error if it does not include an expression.
49  const Expression& expression() const;
50 
51  /// Returns the expression inside.
52  /// @throw runtime_error if it does not include an expression.
54 
55  /// Returns the formula inside.
56  /// @throw runtime_error if it does not include a formula.
57  const Formula& formula() const;
58 
59  /// Returns the formula inside.
60  /// @throw runtime_error if it does not include a formula.
62 
63  /// Creates a new term which substitutes the variable `v` in this term with
64  /// `t`.
65  Term Substitute(const Variable& v, const Term& t);
66 
67  /// Checks if this term can be matched with `s`. Throws std::runtime_error if
68  /// `s` is mismatched.
69  void Check(Sort s) const;
70 
71  /// Checks if this term can be matched with `t`. Throws std::runtime_error if
72  /// `t` is mismatched.
73  void Check(Variable::Type t) const;
74 
75  private:
76  Type type_;
77  Expression e_;
78  Formula f_;
79 };
80 
81 std::ostream& operator<<(std::ostream& os, const Term& t);
82 } // namespace dreal
Term & operator=(const Term &)=default
Default copy assign operator.
Sum type of symbolic::Expression and symbolic::Formula.
Definition: api.cc:9
~Term()=default
Default destructor.
Term()
Default Constructor. It constructs Term(false).
Definition: term.cc:16
void Check(Sort s) const
Checks if this term can be matched with s.
Definition: term.cc:56
Type
Supported types of symbolic variables.
Definition: symbolic_variable.h:22
Represents a symbolic variable.
Definition: symbolic_variable.h:16
const Formula & formula() const
Returns the formula inside.
Definition: term.cc:33
Definition: term.h:10
const Expression & expression() const
Returns the expression inside.
Definition: term.cc:22
Formula & mutable_formula()
Returns the formula inside.
Definition: term.cc:44
Term Substitute(const Variable &v, const Term &t)
Creates a new term which substitutes the variable v in this term with t.
Definition: term.cc:46
Expression & mutable_expression()
Returns the expression inside.
Definition: term.cc:29
This is the header file that we consolidate Drake&#39;s symbolic classes and expose them inside of dreal ...
Represents a symbolic form of an expression.
Definition: symbolic_expression.h:164
Represents a symbolic form of a first-order logic formula.
Definition: symbolic_formula.h:101
Type type() const
Returns its type.
Definition: term.cc:20