Skip to content

Commit 4c6a340

Browse files
author
Daniel Kroening
committed
smt2: implemented get-assignment
get-assignment returns the satisfying assignment for a given set of named terms.
1 parent 439d38c commit 4c6a340

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
get-assignment1.smt2
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^sat$
7+
^\(\(y_equality true\)\)$
8+
--
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(set-logic QF_BV)
2+
(set-option :produce-assignments true)
3+
4+
(declare-const var_x (_ BitVec 8)) ; nullary function
5+
(declare-const var_y (_ BitVec 8)) ; nullary function
6+
(declare-const var_z (_ BitVec 8)) ; nullary function
7+
8+
(assert (= var_x #x01))
9+
(assert (! (= var_y #x02) :named y_equality))
10+
(assert (= var_z (bvadd var_x var_y)))
11+
12+
(check-sat)
13+
(get-assignment)

src/solvers/smt2/smt2_solver.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,36 @@ void smt2_solvert::command(const std::string &c)
232232

233233
std::cout << smt2_format(constant_exprt(buffer, string_typet())) << '\n';
234234
}
235+
else if(c == "get-assignment")
236+
{
237+
// print satisfying assignment for all named expressions
238+
239+
if(status != SAT)
240+
throw error("model is not available");
241+
242+
bool first = true;
243+
244+
std::cout << '(';
245+
for(const auto &named_term : named_terms)
246+
{
247+
const symbol_tablet symbol_table;
248+
const namespacet ns(symbol_table);
249+
const auto value =
250+
simplify_expr(solver.get(named_term.second.term), ns);
251+
252+
if(value.is_constant())
253+
{
254+
if(first)
255+
first = false;
256+
else
257+
std::cout << '\n' << ' ';
258+
259+
std::cout << '(' << smt2_format(named_term.second.name) << ' '
260+
<< smt2_format(value) << ')';
261+
}
262+
}
263+
std::cout << ')' << '\n';
264+
}
235265
else if(c == "simplify")
236266
{
237267
// this is a command that Z3 appears to implement
@@ -256,7 +286,6 @@ void smt2_solvert::command(const std::string &c)
256286
| ( define-funs-rec ( hfunction_deci n+1 ) ( htermi n+1 ) )
257287
| ( define-sort hsymboli ( hsymboli ??? ) hsorti )
258288
| ( get-assertions )
259-
| ( get-assignment )
260289
| ( get-info hinfo_flag i )
261290
| ( get-model )
262291
| ( get-option hkeywordi )

0 commit comments

Comments
 (0)