Skip to content

SMT2: implement check-sat-assuming #6037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions regression/smt2_solver/basic-bv1/check-sat-assuming1.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CORE
check-sat-assuming1.smt2

^EXIT=0$
^SIGNAL=0$
^unsat$
--
7 changes: 7 additions & 0 deletions regression/smt2_solver/basic-bv1/check-sat-assuming1.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(declare-fun a () Bool)
(declare-fun b () Bool)
(define-fun c () Bool (and a b))

(assert c)

(check-sat-assuming ((not a)))
50 changes: 47 additions & 3 deletions src/solvers/smt2/smt2_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ Author: Daniel Kroening, [email protected]
class smt2_solvert:public smt2_parsert
{
public:
smt2_solvert(std::istream &_in, decision_proceduret &_solver)
smt2_solvert(std::istream &_in, stack_decision_proceduret &_solver)
: smt2_parsert(_in), solver(_solver), status(NOT_SOLVED)
{
setup_commands();
}

protected:
decision_proceduret &solver;
stack_decision_proceduret &solver;

void setup_commands();
void define_constants();
Expand Down Expand Up @@ -158,7 +158,47 @@ void smt2_solvert::setup_commands()
};

commands["check-sat-assuming"] = [this]() {
throw error("not yet implemented");
std::vector<exprt> assumptions;

if(next_token() != smt2_tokenizert::OPEN)
throw error("check-sat-assuming expects list as argument");

while(smt2_tokenizer.peek() != smt2_tokenizert::CLOSE &&
smt2_tokenizer.peek() != smt2_tokenizert::END_OF_FILE)
{
auto e = expression(); // any term
expand_function_applications(e);
assumptions.push_back(solver.handle(e));
}

if(next_token() != smt2_tokenizert::CLOSE)
throw error("check-sat-assuming expects ')' at end of list");

// add constant definitions as constraints
define_constants();

// add the assumptions
solver.push(assumptions);

switch(solver())
{
case decision_proceduret::resultt::D_SATISFIABLE:
std::cout << "sat\n";
status = SAT;
break;

case decision_proceduret::resultt::D_UNSATISFIABLE:
std::cout << "unsat\n";
status = UNSAT;
break;

case decision_proceduret::resultt::D_ERROR:
std::cout << "error\n";
status = NOT_SOLVED;
}

// remove the assumptions again
solver.pop();
};

commands["display"] = [this]() {
Expand All @@ -168,6 +208,10 @@ void smt2_solvert::setup_commands()
std::cout << smt2_format(e) << '\n';
};

commands["get-unsat-assumptions"] = [this]() {
throw error("not yet implemented");
};

commands["get-value"] = [this]() {
std::vector<exprt> ops;

Expand Down