51 for(
const auto &
id :
id_map)
53 if(
id.second.type.id() == ID_mathematical_function)
56 if(
id.second.definition.is_nil())
59 const irep_idt &identifier =
id.first;
67 exprt def =
id.second.definition;
79 if(expr.
id()==ID_function_application)
83 if(app.function().id() == ID_symbol)
87 auto f_it =
id_map.find(identifier);
91 const auto &f = f_it->second;
94 f.type.id() == ID_mathematical_function,
95 "type of function symbol must be mathematical_function_type");
100 domain.size() == app.arguments().size(),
101 "number of parameters must match number of arguments");
104 if(!f.definition.is_nil())
106 exprt body = f.definition;
108 if(body.
id() == ID_lambda)
138 std::cout <<
"sat\n";
143 std::cout <<
"unsat\n";
148 std::cout <<
"error\n";
153 commands[
"check-sat-assuming"] = [
this]() {
154 std::vector<exprt> assumptions;
157 throw error(
"check-sat-assuming expects list as argument");
164 assumptions.push_back(
solver.handle(e));
168 throw error(
"check-sat-assuming expects ')' at end of list");
179 std::cout <<
"sat\n";
184 std::cout <<
"unsat\n";
189 std::cout <<
"error\n";
204 commands[
"get-unsat-assumptions"] = [
this]() {
205 throw error(
"not yet implemented");
209 std::vector<exprt> ops;
212 throw error(
"get-value expects list as argument");
221 throw error(
"get-value expects ')' at end of list");
224 throw error(
"model is not available");
226 std::vector<exprt> values;
227 values.reserve(ops.size());
229 for(
const auto &op : ops)
231 if(op.id() != ID_symbol)
232 throw error(
"get-value expects symbol");
236 const auto id_map_it =
id_map.find(identifier);
238 if(id_map_it ==
id_map.end())
239 throw error() <<
"unexpected symbol '" << identifier <<
'\'';
244 throw error() <<
"no value for '" << identifier <<
'\'';
246 values.push_back(value);
251 for(std::size_t op_nr = 0; op_nr < ops.size(); op_nr++)
266 if(str_token != smt2_tokenizert::STRING_LITERAL)
267 throw error(
"expected string literal");
273 commands[
"get-assignment"] = [
this]() {
277 throw error(
"model is not available");
289 if(value.is_constant())
294 std::cout <<
'\n' <<
' ';
296 std::cout <<
'(' <<
smt2_format(named_term.second.name) <<
' '
300 std::cout <<
')' <<
'\n';
307 throw error(
"model is not available");
315 for(
const auto &
id :
id_map)
320 if(value.is_not_nil())
325 std::cout <<
'\n' <<
' ';
327 std::cout <<
"(define-fun " <<
smt2_format(name) <<
' ';
329 if(
id.second.type.id() == ID_mathematical_function)
330 throw error(
"models for functions unimplemented");
337 std::cout <<
')' <<
'\n';
355 | ( declare-
const hsymboli hsorti )
356 | ( declare-datatype hsymboli hdatatype_deci)
357 | ( declare-datatypes ( hsort_deci n+1 ) ( hdatatype_deci n+1 ) )
358 | ( declare-fun hsymboli ( hsorti ??? ) hsorti )
359 | ( declare-
sort hsymboli hnumerali )
360 | ( define-fun hfunction_def i )
361 | ( define-fun-rec hfunction_def i )
362 | ( define-funs-rec ( hfunction_deci n+1 ) ( htermi n+1 ) )
363 | ( define-
sort hsymboli ( hsymboli ??? ) hsorti )
365 | ( get-info hinfo_flag i )
366 | ( get-option hkeywordi )
368 | ( get-unsat-assumptions )
373 | ( reset-assertions )
374 | ( set-info hattributei )
375 | ( set-option hoptioni )
382 void print(
unsigned level,
const std::string &message)
override
387 std::cout <<
"(error \"" << message <<
"\")\n";
389 std::cout <<
"; " << message <<
'\n';
402 std::cout << std::flush;
417 satcheckt satcheck{message_handler};
418 boolbvt boolbv{ns, satcheck, message_handler};
421 bool error_found =
false;
423 while(!smt2_solver.
exit)
450int main(
int argc,
const char *argv[])
457 std::cerr <<
"usage: smt2_solver file\n";
461 std::ifstream in(argv[1]);
464 std::cerr <<
"failed to open " << argv[1] <<
'\n';
Thrown when an unexpected error occurs during the analysis (e.g., when the SAT solver returns an erro...
A constant literal expression.
Base class for all expressions.
const irep_idt & id() const
exprt application(const operandst &arguments) const
void set_verbosity(unsigned _verbosity)
virtual void print(unsigned level, const std::string &message)=0
source_locationt source_location
Class that provides messages with a built-in verbosity 'level'.
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
void print(unsigned level, const std::string &message) override
void flush(unsigned) override
void print(unsigned, const xmlt &) override
void print(unsigned, const jsont &) override
void skip_to_end_of_list()
This skips tokens until all bracketed expressions are closed.
smt2_parsert(std::istream &_in)
std::unordered_map< std::string, std::function< void()> > commands
smt2_tokenizert::smt2_errort error() const
smt2_tokenizert::tokent next_token()
smt2_tokenizert smt2_tokenizer
smt2_solvert(std::istream &_in, stack_decision_proceduret &_solver)
void expand_function_applications(exprt &)
stack_decision_proceduret & solver
std::set< irep_idt > constants_done
enum smt2_solvert::@001242151172300253377233256121047043052122124150 status
Exception thrown by the tokenizer (and the parser built on top of it) to report a syntactic error at ...
unsigned get_line_no() const
void set_line(const irep_idt &line)
Expression to hold a symbol (variable).
void identifier(const irep_idt &identifier)
const function_application_exprt & to_function_application_expr(const exprt &expr)
Cast an exprt to a function_application_exprt.
const lambda_exprt & to_lambda_expr(const exprt &expr)
Cast an exprt to a lambda_exprt.
const mathematical_function_typet & to_mathematical_function_type(const typet &type)
Cast a typet to a mathematical_function_typet.
exprt simplify_expr(exprt src, const namespacet &ns)
int solver(std::istream &in)
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.