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");
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++)
264 if(
next_token() != smt2_tokenizert::STRING_LITERAL)
265 throw error(
"expected string literal");
272 commands[
"get-assignment"] = [
this]() {
276 throw error(
"model is not available");
288 if(value.is_constant())
293 std::cout <<
'\n' <<
' ';
295 std::cout <<
'(' <<
smt2_format(named_term.second.name) <<
' '
299 std::cout <<
')' <<
'\n';
306 throw error(
"model is not available");
314 for(
const auto &
id :
id_map)
319 if(value.is_not_nil())
324 std::cout <<
'\n' <<
' ';
326 std::cout <<
"(define-fun " <<
smt2_format(name) <<
' ';
328 if(
id.second.type.id() == ID_mathematical_function)
329 throw error(
"models for functions unimplemented");
336 std::cout <<
')' <<
'\n';
354 | ( declare-
const hsymboli hsorti )
355 | ( declare-datatype hsymboli hdatatype_deci)
356 | ( declare-datatypes ( hsort_deci n+1 ) ( hdatatype_deci n+1 ) )
357 | ( declare-fun hsymboli ( hsorti ??? ) hsorti )
358 | ( declare-
sort hsymboli hnumerali )
359 | ( define-fun hfunction_def i )
360 | ( define-fun-rec hfunction_def i )
361 | ( define-funs-rec ( hfunction_deci n+1 ) ( htermi n+1 ) )
362 | ( define-
sort hsymboli ( hsymboli ??? ) hsorti )
364 | ( get-info hinfo_flag i )
365 | ( get-option hkeywordi )
367 | ( get-unsat-assumptions )
372 | ( reset-assertions )
373 | ( set-info hattributei )
374 | ( set-option hoptioni )
381 void print(
unsigned level,
const std::string &message)
override
386 std::cout <<
"(error \"" << message <<
"\")\n";
388 std::cout <<
"; " << message <<
'\n';
401 std::cout << std::flush;
416 satcheckt satcheck{message_handler};
417 boolbvt boolbv{ns, satcheck, message_handler};
420 bool error_found =
false;
422 while(!smt2_solver.exit)
430 smt2_solver.skip_to_end_of_list();
437 smt2_solver.skip_to_end_of_list();
449 int main(
int argc,
const char *argv[])
456 std::cerr <<
"usage: smt2_solver file\n";
460 std::ifstream in(argv[1]);
463 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.
virtual exprt get(const exprt &) const =0
Return expr with variables replaced by values from satisfying assignment if available.
virtual exprt handle(const exprt &)=0
Generate a handle, which is an expression that has the same value as the argument in any model that i...
void set_to_true(const exprt &)
For a Boolean expression expr, add the constraint 'expr'.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
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
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
enum smt2_solvert::@5 status
std::set< irep_idt > constants_done
unsigned get_line_no() const
const std::string & get_buffer() const
void set_line(const irep_idt &line)
virtual void pop()=0
Pop whatever is on top of the stack.
virtual void push(const std::vector< exprt > &assumptions)=0
Pushes a new context on the stack that consists of the given (possibly empty vector of) assumptions.
Expression to hold a symbol (variable)
const irep_idt & get_identifier() const
const lambda_exprt & to_lambda_expr(const exprt &expr)
Cast an exprt to a lambda_exprt.
const function_application_exprt & to_function_application_expr(const exprt &expr)
Cast an exprt to a function_application_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)
int main(int argc, const char *argv[])
#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.