SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
FunctionInstantiator.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <type_traits>
4 
5 #include "Conversions.h"
6 #include <carl-formula/formula/functions/Substitution.h>
7 
8 namespace smtrat {
9 namespace parser {
10 
12  virtual ~FunctionInstantiator() {}
13  template<typename T>
14  bool convert(const std::vector<types::TermType>& from, std::vector<T>& to) const {
16  return converter(from, to);
17  }
18  template<typename T>
19  bool convert(const std::vector<types::TermType>& from, std::vector<T>& to, TheoryError& errors) const {
21  return converter(from, to, errors);
22  }
23  virtual bool operator()(const std::vector<types::TermType>&, types::TermType&, TheoryError& errors) const {
24  errors.next() << "Instantiation of this function is not supported.";
25  return false;
26  }
27 };
30  template<typename T>
31  bool convert(const std::vector<types::TermType>& from, std::vector<T>& to) const {
33  return converter(from, to);
34  }
35  virtual bool operator()(const std::vector<std::size_t>&, const std::vector<types::TermType>&, types::TermType&, TheoryError& errors) const {
36  errors.next() << "Instantiation of this function is not supported.";
37  return false;
38  }
39 };
40 
41 template<typename V, typename T>
42 struct Instantiator: public boost::static_visitor<bool> {
43 protected:
44  V var;
47 public:
48  template<typename Res>
49  bool operator()(const Res&) {
50  return false;
51  }
52  bool operator()(carl::Variable v) {
53  if (v == var) result = replacement;
54  return true;
55  }
56  template<typename TYPE = T>
57  typename std::enable_if<std::is_same<TYPE,Poly>::value, bool>::type
58  operator()(const Poly& p) {
60  return true;
61  }
62  bool operator()(const FormulaT& f) {
64  return true;
65  }
66  template<typename VAR = V>
67  typename std::enable_if<std::is_same<VAR,types::BVVariable>::value, bool>::type
69  if (v == var) result = replacement;
70  return true;
71  }
72  template<typename VAR = V>
73  typename std::enable_if<std::is_same<VAR,types::BVVariable>::value, bool>::type
75  std::map<types::BVVariable,types::BVTerm> m;
76  m.emplace(var, replacement);
77  result = t.substitute(m);
78  return true;
79  }
80  bool instantiate(V v, const T& repl, types::TermType& subject) {
81  var = v;
82  replacement = repl;
83  if (boost::apply_visitor(*this, subject)) {
84  subject = this->result;
85  return true;
86  }
87  return false;
88  }
89 };
90 
92  std::vector<types::VariableType> arguments;
93  carl::Sort sort;
95  std::set<types::VariableType> auxiliaries;
97  UserFunctionInstantiator(const std::vector<types::VariableType>& arguments, const carl::Sort& sort, const types::TermType& definition, const std::set<types::VariableType>& auxiliaries):
99 };
100 
101 }
102 }
bool substitute(const FormulaT &constr, const carl::Variable var, const carl::vs::Term< Poly > &term, FormulaT &result)
Definition: VSHelper.h:138
carl::BVVariable BVVariable
Definition: TheoryTypes.h:78
carl::mpl_variant_of< TermTypes >::type TermType
Variant type for all terms.
Definition: TheoryTypes.h:160
carl::BVTerm BVTerm
Typedef for bitvector term.
Definition: TheoryTypes.h:77
QuantifierType type(const std::pair< QuantifierType, std::vector< carl::Variable >> &p)
Definition: QEQuery.h:39
Class to create the formulas for axioms.
carl::Formula< Poly > FormulaT
Definition: types.h:37
carl::MultivariatePolynomial< Rational > Poly
Definition: types.h:25
carl::Formulas< Poly > FormulasT
Definition: types.h:39
bool convert(const std::vector< types::TermType > &from, std::vector< T > &to, TheoryError &errors) const
bool convert(const std::vector< types::TermType > &from, std::vector< T > &to) const
virtual bool operator()(const std::vector< types::TermType > &, types::TermType &, TheoryError &errors) const
bool convert(const std::vector< types::TermType > &from, std::vector< T > &to) const
virtual bool operator()(const std::vector< std::size_t > &, const std::vector< types::TermType > &, types::TermType &, TheoryError &errors) const
std::enable_if< std::is_same< VAR, types::BVVariable >::value, bool >::type operator()(const types::BVVariable &v)
bool operator()(const FormulaT &f)
std::enable_if< std::is_same< TYPE, Poly >::value, bool >::type operator()(const Poly &p)
std::enable_if< std::is_same< VAR, types::BVVariable >::value, bool >::type operator()(const types::BVTerm &t)
bool operator()(carl::Variable v)
bool instantiate(V v, const T &repl, types::TermType &subject)
TheoryError & next()
Definition: Common.h:25
std::vector< types::VariableType > arguments
std::set< types::VariableType > auxiliaries
UserFunctionInstantiator(const std::vector< types::VariableType > &arguments, const carl::Sort &sort, const types::TermType &definition, const std::set< types::VariableType > &auxiliaries)
Converts a vector of variants to a vector of some type using the Converter class.
Definition: Conversions.h:150