SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
AbstractTheory.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Common.h"
4 #include "TheoryTypes.h"
5 #include "ParserState.h"
6 
7 #include <boost/spirit/include/qi_symbols.hpp>
8 
9 namespace smtrat {
10 namespace parser {
11 
12  namespace qi = boost::spirit::qi;
13 
14 /**
15  * Base class for all theories.
16  *
17  * A theory represents one or multiple SMT-LIB theories and takes care of
18  * converting smtlib constructs into our datastructures.
19  *
20  * A theory has two kinds of functions:
21  * <ul>
22  * <li>
23  * Initializer are static functions that initialize global datastructures.
24  * These are for example the set of constants.
25  * </li>
26  * <li>
27  * Handlers are member functions that implement a certain SMT-LIB functionality.
28  * Handlers always return a boolean that indicates if the theory could complete the request.
29  * Oftentimes, a theory will return false because the request should be handled by another theory.
30  * Handlers are used, whenever the parser can not easily decide which theory to use and thus tries to call every theory.
31  * The result of a handler is always a term that is returned through a reference argument.
32  * </li>
33  *
34  * A theory may override any of the following methods.
35  */
38 
40  virtual ~AbstractTheory() {}
41 
42  /**
43  * Declare a new variable with the given name and the given sort.
44  */
45  virtual bool declareVariable(const std::string&, const carl::Sort&, types::VariableType&, TheoryError& errors) {
46  errors.next() << "Variable declaration is not supported.";
47  return false;
48  }
49  /**
50  * Resolve a symbol that was not declared within the ParserState.
51  * This might be a symbol that actually uses indices, for example bitvector constants.
52  */
53  virtual bool resolveSymbol(const Identifier&, types::TermType&, TheoryError& errors) {
54  errors.next() << "Custom symbols are not supported.";
55  return false;
56  }
57  /**
58  * Resolve an if-then-else operator.
59  */
60  virtual bool handleITE(const FormulaT&, const types::TermType&, const types::TermType&, types::TermType&, TheoryError& errors) {
61  errors.next() << "ITEs are not supported.";
62  return false;
63  }
64  /**
65  * Resolve a distinct operator.
66  */
67  virtual bool handleDistinct(const std::vector<types::TermType>&, types::TermType&, TheoryError& errors) {
68  errors.next() << "Distinct is not supported.";
69  return false;
70  }
71  template<typename T, typename Builder>
72  FormulaT expandDistinct(const std::vector<T>& values, const Builder& neqBuilder) {
73  FormulasT subformulas;
74  for (std::size_t i = 0; i < values.size() - 1; i++) {
75  for (std::size_t j = i + 1; j < values.size(); j++) {
76  subformulas.emplace_back(neqBuilder(values[i], values[j]));
77  }
78  }
79  return FormulaT(carl::FormulaType::AND, subformulas);
80  }
81  /**
82  * Instantiate a variable within a term.
83  */
85  errors.next() << "Instantiation of arguments is not supported.";
86  return false;
87  }
89  errors.next() << "Refreshing variables is not supported.";
90  return false;
91  }
92  /**
93  * Resolve another unknown function call.
94  */
95  virtual bool functionCall(const Identifier&, const std::vector<types::TermType>&, types::TermType&, TheoryError& errors) {
96  errors.next() << "Functions are not supported.";
97  return false;
98  }
99 
100  /**
101  * Resolve a quantified term.
102  */
103  virtual bool declareQuantifiedTerm(const std::vector<std::pair<std::string, carl::Sort>>& , const carl::FormulaType& , const types::TermType& , types::TermType& , TheoryError& errors){
104  errors.next() << "Quantified terms are not supported.";
105  return false;
106  }
107 
108  /**
109  * Initialize the global symbol table for simple sorts.
110  */
111  static void addSimpleSorts(qi::symbols<char, carl::Sort>&) {}
112  /**
113  * Initialize the global symbol table for constants.
114  */
115  static void addConstants(qi::symbols<char, types::ConstType>&) {}
116 };
117 
118 }
119 }
carl::mpl_variant_of< TermTypes >::type TermType
Variant type for all terms.
Definition: TheoryTypes.h:160
carl::mpl_variant_of< VariableTypes >::type VariableType
Variant type for all variables.
Definition: TheoryTypes.h:132
Class to create the formulas for axioms.
carl::Formula< Poly > FormulaT
Definition: types.h:37
carl::Formulas< Poly > FormulasT
Definition: types.h:39
Base class for all theories.
virtual bool handleDistinct(const std::vector< types::TermType > &, types::TermType &, TheoryError &errors)
Resolve a distinct operator.
AbstractTheory(ParserState *state)
virtual bool declareVariable(const std::string &, const carl::Sort &, types::VariableType &, TheoryError &errors)
Declare a new variable with the given name and the given sort.
virtual bool resolveSymbol(const Identifier &, types::TermType &, TheoryError &errors)
Resolve a symbol that was not declared within the ParserState.
virtual bool functionCall(const Identifier &, const std::vector< types::TermType > &, types::TermType &, TheoryError &errors)
Resolve another unknown function call.
virtual bool refreshVariable(const types::VariableType &, types::VariableType &, TheoryError &errors)
virtual bool handleITE(const FormulaT &, const types::TermType &, const types::TermType &, types::TermType &, TheoryError &errors)
Resolve an if-then-else operator.
static void addSimpleSorts(qi::symbols< char, carl::Sort > &)
Initialize the global symbol table for simple sorts.
FormulaT expandDistinct(const std::vector< T > &values, const Builder &neqBuilder)
static void addConstants(qi::symbols< char, types::ConstType > &)
Initialize the global symbol table for constants.
virtual bool declareQuantifiedTerm(const std::vector< std::pair< std::string, carl::Sort >> &, const carl::FormulaType &, const types::TermType &, types::TermType &, TheoryError &errors)
Resolve a quantified term.
virtual bool instantiate(const types::VariableType &, const types::TermType &, types::TermType &, TheoryError &errors)
Instantiate a variable within a term.
TheoryError & next()
Definition: Common.h:25