Skip to content

Commit ab4d90f

Browse files
authored
Merge pull request #6037 from diffblue/check-sat-assuming
SMT2: implement check-sat-assuming
2 parents 5914d75 + 211b539 commit ab4d90f

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
check-sat-assuming1.smt2
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^unsat$
7+
--
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(declare-fun a () Bool)
2+
(declare-fun b () Bool)
3+
(define-fun c () Bool (and a b))
4+
5+
(assert c)
6+
7+
(check-sat-assuming ((not a)))

src/solvers/smt2/smt2_solver.cpp

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ Author: Daniel Kroening, [email protected]
2525
class smt2_solvert:public smt2_parsert
2626
{
2727
public:
28-
smt2_solvert(std::istream &_in, decision_proceduret &_solver)
28+
smt2_solvert(std::istream &_in, stack_decision_proceduret &_solver)
2929
: smt2_parsert(_in), solver(_solver), status(NOT_SOLVED)
3030
{
3131
setup_commands();
3232
}
3333

3434
protected:
35-
decision_proceduret &solver;
35+
stack_decision_proceduret &solver;
3636

3737
void setup_commands();
3838
void define_constants();
@@ -158,7 +158,47 @@ void smt2_solvert::setup_commands()
158158
};
159159

160160
commands["check-sat-assuming"] = [this]() {
161-
throw error("not yet implemented");
161+
std::vector<exprt> assumptions;
162+
163+
if(next_token() != smt2_tokenizert::OPEN)
164+
throw error("check-sat-assuming expects list as argument");
165+
166+
while(smt2_tokenizer.peek() != smt2_tokenizert::CLOSE &&
167+
smt2_tokenizer.peek() != smt2_tokenizert::END_OF_FILE)
168+
{
169+
auto e = expression(); // any term
170+
expand_function_applications(e);
171+
assumptions.push_back(solver.handle(e));
172+
}
173+
174+
if(next_token() != smt2_tokenizert::CLOSE)
175+
throw error("check-sat-assuming expects ')' at end of list");
176+
177+
// add constant definitions as constraints
178+
define_constants();
179+
180+
// add the assumptions
181+
solver.push(assumptions);
182+
183+
switch(solver())
184+
{
185+
case decision_proceduret::resultt::D_SATISFIABLE:
186+
std::cout << "sat\n";
187+
status = SAT;
188+
break;
189+
190+
case decision_proceduret::resultt::D_UNSATISFIABLE:
191+
std::cout << "unsat\n";
192+
status = UNSAT;
193+
break;
194+
195+
case decision_proceduret::resultt::D_ERROR:
196+
std::cout << "error\n";
197+
status = NOT_SOLVED;
198+
}
199+
200+
// remove the assumptions again
201+
solver.pop();
162202
};
163203

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

211+
commands["get-unsat-assumptions"] = [this]() {
212+
throw error("not yet implemented");
213+
};
214+
171215
commands["get-value"] = [this]() {
172216
std::vector<exprt> ops;
173217

0 commit comments

Comments
 (0)