SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
ExpressionContent.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cassert>
4 #include <vector>
5 
6 #include <boost/functional/hash.hpp>
7 #include <boost/variant.hpp>
8 
9 #include "../../Common.h"
10 #include "ExpressionTypes.h"
11 #include "Expression.h"
12 
13 namespace smtrat {
14 namespace expression {
15 
16  struct ITEExpression {
21 
22  ITEExpression(ITEType, Expression&& _condition, Expression&& _then, Expression&& _else):
23  condition(std::move(_condition)), thencase(std::move(_then)), elsecase(std::move(_else))
24  {}
25  };
26  inline std::ostream& operator<<(std::ostream& os, const ITEExpression& expr) {
27  return os << "(" << expr.type << " " << expr.condition << " " << expr.thencase << " " << expr.elsecase << ")";
28  }
29 
32  std::vector<carl::Variable> variables;
34 
35  QuantifierExpression(QuantifierType _type, std::vector<carl::Variable>&& _variables, Expression&& _expression):
36  type(_type), variables(std::move(_variables)), expression(std::move(_expression))
37  {}
38  };
39  inline std::ostream& operator<<(std::ostream& os, const QuantifierExpression& expr) {
40  return os << "(" << expr.type << " " << expr.expression << ")";
41  }
42 
43  struct UnaryExpression {
46 
47  UnaryExpression(UnaryType _type, Expression&& _expression):
48  type(_type), expression(std::move(_expression))
49  {}
50  };
51  inline std::ostream& operator<<(std::ostream& os, const UnaryExpression& expr) {
52  return os << "(" << expr.type << " " << expr.expression << ")";
53  }
54 
59 
61  type(_type), lhs(std::move(_lhs)), rhs(std::move(_rhs))
62  {
63  //if (rhs < lhs) std::swap(lhs, rhs);
64  }
65  };
66  inline std::ostream& operator<<(std::ostream& os, const BinaryExpression& expr) {
67  return os << "(" << expr.type << " " << expr.lhs << " " << expr.rhs << ")";
68  }
69 
70  struct NaryExpression {
73 
74  NaryExpression(NaryType _type, Expressions&& _expressions):
75  type(_type), expressions(std::move(_expressions))
76  {
77  normalize();
78  }
79  NaryExpression(NaryType _type, const std::initializer_list<Expression>& _expressions):
80  type(_type), expressions(_expressions)
81  {
82  normalize();
83  }
84  void normalize() {
85  if (type == AND || type == OR || type == XOR || type == IFF) {
86  std::sort(expressions.begin(), expressions.end());
87  }
88  }
89  };
90  inline std::ostream& operator<<(std::ostream& os, const NaryExpression& expr) {
91  os << "(" << expr.type;
92  for (const auto& e: expr.expressions) os << " " << e;
93  return os << ")";
94  }
95 
97  typedef boost::variant<
98  carl::Variable,
105  friend struct std::hash<Content>;
106 
108  std::size_t id;
109  std::size_t hash;
111 
112  template<typename... T>
113  ExpressionContent(T&&... t): content(std::forward<T>(t)...), id(0), hash(0) {
114  updateHash();
115  }
116  private:
117  void updateHash();
118  };
119  inline std::ostream& operator<<(std::ostream& os, const ExpressionContent& expr) {
120  return os << expr.content;
121  }
122  inline std::ostream& operator<<(std::ostream& os, const ExpressionContent* expr) {
123  return os << expr->content;
124  }
125 
126  template<typename T>
127  struct ExpressionTypeChecker: public boost::static_visitor<bool> {
128  bool operator()(const T&) const {
129  return true;
130  }
131  template<typename T2>
132  bool operator()(const T2&) const {
133  return false;
134  }
135  };
136 }
137 }
138 
139 #include "ExpressionHash.h"
void sort(T *array, int size, LessThan lt)
Definition: Sort.h:67
static uint32_t hash(uint32_t x)
Definition: Map.h:32
std::ostream & operator<<(std::ostream &os, const Expression &expr)
std::vector< Expression > Expressions
Class to create the formulas for axioms.
BinaryExpression(BinaryType _type, Expression &&_lhs, Expression &&_rhs)
boost::variant< carl::Variable, ITEExpression, QuantifierExpression, UnaryExpression, BinaryExpression, NaryExpression > Content
ITEExpression(ITEType, Expression &&_condition, Expression &&_then, Expression &&_else)
NaryExpression(NaryType _type, Expressions &&_expressions)
NaryExpression(NaryType _type, const std::initializer_list< Expression > &_expressions)
QuantifierExpression(QuantifierType _type, std::vector< carl::Variable > &&_variables, Expression &&_expression)
std::vector< carl::Variable > variables
UnaryExpression(UnaryType _type, Expression &&_expression)