10 #ifdef PARSER_ENABLE_BITVECTOR
13 #ifdef PARSER_ENABLE_UNINTERPRETED
18 #include "../ParserSettings.h"
20 #include <boost/mpl/for_each.hpp>
30 typedef boost::mpl::vector<
32 #ifdef PARSER_ENABLE_ARITHMETIC
35 #ifdef PARSER_ENABLE_BITVECTOR
38 #ifdef PARSER_ENABLE_UNINTERPRETED
50 #ifdef PARSER_ENABLE_ARITHMETIC
53 #ifdef PARSER_ENABLE_BITVECTOR
56 #ifdef PARSER_ENABLE_UNINTERPRETED
82 static void addConstants(qi::symbols<char, types::ConstType>& constants) {
90 qi::symbols<char, carl::Sort>&
sorts;
93 T::addSimpleSorts(
sorts);
113 if (t.second->declareVariable(name,
sort,
var, te(t.first)))
return;
115 SMTRAT_LOG_ERROR(
"smtrat.parser",
"Variable \"" << name <<
"\" was declared with an invalid sort \"" <<
sort <<
"\":" << te);
118 SMTRAT_LOG_ERROR(
"smtrat.parser",
"Variable \"" << name <<
"\" will not be declared due to a name clash.");
122 void declareFunction(
const std::string& name,
const std::vector<carl::Sort>& args,
const carl::Sort&
sort) {
124 std::vector<carl::Sort> our_args(args);
125 for (
auto& a: our_args) {
126 if (carl::SortManager::getInstance().getType(a) == carl::VariableType::VT_BOOL) {
127 a = carl::SortManager::getInstance().getSort(
"UF_Bool");
130 if (carl::SortManager::getInstance().getType(
sort) == carl::VariableType::VT_BOOL) {
131 state->
declared_functions[name] = carl::newUninterpretedFunction(name, our_args, carl::SortManager::getInstance().getSort(
"UF_Bool"));
136 SMTRAT_LOG_ERROR(
"smtrat.parser",
"Function \"" << name <<
"\" will not be declared due to a name clash.");
146 if (t.second->declareVariable(arg.first, arg.second,
result, te(t.first)))
return result;
148 SMTRAT_LOG_ERROR(
"smtrat.parser",
"Function argument \"" << arg.first <<
"\" could not be declared:" << te);
151 SMTRAT_LOG_ERROR(
"smtrat.parser",
"Function argument \"" << arg.first <<
"\" will not be declared due to a name clash.");
160 if (arguments.size() == 0) {
163 SMTRAT_LOG_DEBUG(
"smtrat.parser",
"Defining function \"" << name <<
"\" as \"" << definition <<
"\".");
169 SMTRAT_LOG_ERROR(
"smtrat.parser",
"Function \"" << name <<
"\" will not be defined due to a name clash.");
175 SMTRAT_LOG_DEBUG(
"smtrat.parser",
"Resolving symbol \"" << identifier <<
"\".");
178 if (identifier.
indices ==
nullptr) {
183 if (t.second->resolveSymbol(identifier,
result, te(t.first)))
return result;
185 SMTRAT_LOG_ERROR(
"smtrat.parser",
"Tried to resolve symbol \"" << identifier <<
"\" which is unknown." << te);
193 if (identifier.
indices ==
nullptr) {
217 if (!converter(term, subject)) {
218 SMTRAT_LOG_WARN(
"smtrat.parser",
"Ignoring annotation on unsupported expression. We only annotated formulas.");
221 for (
const auto& attr: attributes) {
222 if (attr.key ==
"named") {
223 if (carl::variant_is_type<std::string>(attr.value)) {
224 const std::string& value = boost::get<std::string>(attr.value);
225 SMTRAT_LOG_DEBUG(
"smtrat.parser",
"Naming term: " << value <<
" = " << term);
228 SMTRAT_LOG_WARN(
"smtrat.parser",
"Ignoring naming with unsupported value type for term " << term);
231 SMTRAT_LOG_WARN(
"smtrat.parser",
"Ignoring unsupported annotation " << attr <<
" for term " << term);
245 if (arguments.size() != 3) {
246 SMTRAT_LOG_ERROR(
"smtrat.parser",
"Failed to construct ITE expression, only exactly three arguments are allowed, but \"" << arguments <<
"\" were given.");
252 if (!converter(arguments[0], ifterm)) {
253 SMTRAT_LOG_ERROR(
"smtrat.parser",
"Failed to construct ITE expression, the first argument must be a formula, but \"" << arguments[0] <<
"\" was given.");
257 if (ifterm.is_true())
return arguments[1];
258 if (ifterm.is_false())
return arguments[2];
261 if (t.second->handleITE(ifterm, arguments[1], arguments[2],
result, te(t.first)))
return result;
263 SMTRAT_LOG_ERROR(
"smtrat.parser",
"Failed to construct ITE \"" << ifterm <<
"\" ? \"" << arguments[1] <<
"\" : \"" << arguments[2] <<
"\": " << te);
273 if (t.second->handleDistinct(arguments,
result, te(t.first)))
return result;
275 SMTRAT_LOG_ERROR(
"smtrat.parser",
"Failed to construct distinct for \"" << arguments <<
"\": " << te);
283 bool wasInstantiated =
false;
285 if (t.second->instantiate(
var, repl, subject, errors(t.first))) {
286 for (
const auto& f:
function.globalFormulas) {
288 bool res = t.second->instantiate(
var, repl, tmp, errors);
292 wasInstantiated =
true;
296 if (!wasInstantiated) {
297 SMTRAT_LOG_ERROR(
"smtrat.parser",
"Failed to instantiate function: " << errors);
309 if (
function.arguments.size() != arguments.size()) {
310 errors.
next() <<
"Function was expected to have " <<
function.arguments.size() <<
" arguments, but was instantiated with " << arguments.size() <<
".";
313 result =
function.definition;
314 for (
const auto& aux:
function.auxiliaries) {
316 bool wasRefreshed =
false;
319 if (t.second->refreshVariable(aux, repl, te(t.first))) {
325 SMTRAT_LOG_ERROR(
"smtrat.parser",
"Failed to refresh auxiliary variable \"" << aux <<
"\": " << te);
331 for (std::size_t i = 0; i < arguments.size(); i++) {
332 if (!
instantiate(
function,
function.arguments[i], arguments[i],
result))
return false;
341 if (identifier.
symbol ==
"ite") {
342 if (identifier.
indices !=
nullptr) {
343 SMTRAT_LOG_ERROR(
"smtrat.parser",
"The function \"" << identifier <<
"\" should not have indices.");
348 }
else if (identifier.
symbol ==
"distinct") {
349 if (identifier.
indices !=
nullptr) {
350 SMTRAT_LOG_ERROR(
"smtrat.parser",
"The function \"" << identifier <<
"\" should not have indices.");
358 if (identifier.
indices !=
nullptr) {
359 SMTRAT_LOG_ERROR(
"smtrat.parser",
"The function \"" << identifier <<
"\" should not have indices.");
363 SMTRAT_LOG_DEBUG(
"smtrat.parser",
"Trying to call function \"" << identifier <<
"\" with arguments " << arguments <<
".");
364 if ((*deffunit->second)(arguments,
result, te(identifier.
symbol))) {
368 SMTRAT_LOG_ERROR(
"smtrat.parser",
"Failed to call function \"" << identifier <<
"\" with arguments " << arguments <<
":" << te);
374 if (identifier.
indices ==
nullptr) {
375 SMTRAT_LOG_ERROR(
"smtrat.parser",
"The function \"" << identifier <<
"\" should have indices.");
379 SMTRAT_LOG_DEBUG(
"smtrat.parser",
"Trying to call function \"" << identifier <<
"\" with arguments " << arguments <<
".");
384 SMTRAT_LOG_ERROR(
"smtrat.parser",
"Failed to call function \"" << identifier <<
"\" with arguments " << arguments <<
":" << te);
390 if (identifier.
indices !=
nullptr) {
391 SMTRAT_LOG_ERROR(
"smtrat.parser",
"The function \"" << identifier <<
"\" should not have indices.");
395 SMTRAT_LOG_DEBUG(
"smtrat.parser",
"Trying to call function \"" << identifier <<
"\" with arguments " << arguments <<
".");
400 SMTRAT_LOG_ERROR(
"smtrat.parser",
"Failed to call function \"" << identifier <<
"\" with arguments " << arguments <<
":" << te);
405 if (t.second->functionCall(identifier, arguments,
result, te(t.first)))
return result;
407 SMTRAT_LOG_ERROR(
"smtrat.parser",
"Failed to call \"" << identifier <<
"\" with arguments " << arguments <<
":" << te);
413 SMTRAT_LOG_DEBUG(
"smtrat.parser",
"Declaring " << (universal ?
"universal" :
"existential") <<
" variables " <<
vars <<
" and term " << term);
420 SMTRAT_LOG_ERROR(
"smtrat.parser",
"Failed to declare " << (universal ?
"universal" :
"existential") <<
" variables " <<
vars <<
" and term " << term <<
":" << te);
virtual void annotateName(const FormulaT &f, const std::string &name)=0
void sort(T *array, int size, LessThan lt)
carl::mpl_variant_of< TermTypes >::type TermType
Variant type for all terms.
carl::mpl_variant_of< VariableTypes >::type VariableType
Variant type for all variables.
QuantifierType type(const std::pair< QuantifierType, std::vector< carl::Variable >> &p)
std::vector< carl::Variable > vars(const std::pair< QuantifierType, std::vector< carl::Variable >> &p)
Class to create the formulas for axioms.
carl::Formula< Poly > FormulaT
carl::Formulas< Poly > FormulasT
const auto & settings_parser()
#define SMTRAT_LOG_WARN(channel, msg)
#define SMTRAT_LOG_ERROR(channel, msg)
#define SMTRAT_LOG_DEBUG(channel, msg)
Implements the theory of arithmetic, including LRA, LIA, NRA and NIA.
Implements the theory of bitvectors.
Implements the theory of bitvectors.
Implements the core theory of the booleans.
std::vector< std::size_t > * indices
void registerFunction(const std::string &name, const FunctionInstantiator *fi)
FormulasT global_formulas
std::map< std::string, const FunctionInstantiator * > defined_functions
std::map< std::string, types::TermType > constants
bool isSymbolFree(const std::string &name, bool output=true)
std::map< std::string, const IndexedFunctionInstantiator * > defined_indexed_functions
std::map< std::string, types::VariableType > variables
std::set< types::VariableType > auxiliary_variables
void pushExpressionScope()
std::map< std::string, types::TermType > bindings
void popExpressionScope()
bool resolveSymbol(const std::string &name, const std::map< std::string, T > &map, Res &result) const
InstructionHandler & handler
std::map< std::string, const UserFunctionInstantiator * > defined_user_functions
std::map< std::string, carl::UninterpretedFunction > declared_functions
Helper functor for addConstants() method.
qi::symbols< char, types::ConstType > & constants
ConstantAdder(qi::symbols< char, types::ConstType > &constants)
Helper functor for addSimpleSorts() method.
qi::symbols< char, carl::Sort > & sorts
SimpleSortAdder(qi::symbols< char, carl::Sort > &sorts)
The Theories class combines all implemented theories and provides a single interface to interact with...
std::map< std::string, AbstractTheory * > theories
void addGlobalFormulas(FormulasT &formulas)
void defineFunction(const std::string &name, const std::vector< types::VariableType > &arguments, const carl::Sort &sort, const types::TermType &definition)
types::VariableType resolveVariable(const Identifier &identifier) const
boost::mpl::vector< CoreTheory *, ArithmeticTheory *, BitvectorTheory *, UninterpretedTheory *, BooleanEncodingTheory * >::type Modules
void handleLet(const std::string &symbol, const types::TermType &term)
types::TermType functionCall(const Identifier &identifier, const std::vector< types::TermType > &arguments)
types::TermType resolveSymbol(const Identifier &identifier) const
void declareVariable(const std::string &name, const carl::Sort &sort)
void pushScriptScope(std::size_t n)
const auto & annotateTerm(const types::TermType &term, const std::vector< Attribute > &attributes)
types::TermType handleDistinct(const std::vector< types::TermType > &arguments)
void popScriptScope(std::size_t n)
types::VariableType declareFunctionArgument(const std::pair< std::string, carl::Sort > &arg)
bool instantiate(const UserFunctionInstantiator &function, const types::VariableType &var, const types::TermType &repl, types::TermType &subject)
void popExpressionScope(std::size_t n)
bool instantiateUserFunction(const UserFunctionInstantiator &function, const std::vector< types::TermType > &arguments, types::TermType &result, TheoryError &errors)
types::TermType quantifiedTerm(const std::vector< std::pair< std::string, carl::Sort >> &vars, const types::TermType &term, bool universal)
bool isVariableDeclared(const std::string &name) const
static void addSimpleSorts(qi::symbols< char, carl::Sort > &sorts)
Collects simple sorts from all theory modules.
Theories(ParserState *state)
types::TermType handleITE(const std::vector< types::TermType > &arguments)
static void addConstants(qi::symbols< char, types::ConstType > &constants)
Collects constants from all theory modules.
void pushExpressionScope(std::size_t n)
void declareFunction(const std::string &name, const std::vector< carl::Sort > &args, const carl::Sort &sort)
Implements the theory of equalities and uninterpreted functions.
Converts variants to some type using the Converter class.