Skip to content

Commit f2350c9

Browse files
committed
SMT2 backend: use check-sat-assuming, when available
Instead of assing the assumptions as (hard) constraints, use the SMT-LIB command check-sat-assuming, which has been designed for this particular use-case.
1 parent 211b539 commit f2350c9

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

src/solvers/smt2/smt2_conv.cpp

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ smt2_convt::smt2_convt(
5454
solvert _solver,
5555
std::ostream &_out)
5656
: use_FPA_theory(false),
57+
use_array_of_bool(false),
5758
use_as_const(false),
59+
use_check_sat_assuming(false),
5860
use_datatypes(false),
59-
use_array_of_bool(false),
6061
use_lambda_for_array(false),
6162
emit_set_logic(true),
6263
ns(_ns),
@@ -81,8 +82,9 @@ smt2_convt::smt2_convt(
8182
break;
8283

8384
case solvert::CPROVER_SMT2:
84-
use_as_const = true;
8585
use_array_of_bool = true;
86+
use_as_const = true;
87+
use_check_sat_assuming = true;
8688
emit_set_logic = false;
8789
break;
8890

@@ -100,8 +102,9 @@ smt2_convt::smt2_convt(
100102
break;
101103

102104
case solvert::Z3:
103-
use_as_const = true;
104105
use_array_of_bool = true;
106+
use_as_const = true;
107+
use_check_sat_assuming = true;
105108
use_lambda_for_array = true;
106109
emit_set_logic = false;
107110
use_datatypes = true;
@@ -173,26 +176,36 @@ void smt2_convt::write_footer(std::ostream &os)
173176
{
174177
os << "\n";
175178

176-
// add the assumptions, if any
177-
if(!assumptions.empty())
178-
{
179-
os << "; assumptions\n";
179+
// fix up the object sizes
180+
for(const auto &object : object_sizes)
181+
define_object_size(object.second, object.first);
180182

183+
if(use_check_sat_assuming && !assumptions.empty())
184+
{
185+
os << "(check-sat-assuming (";
181186
for(const auto &assumption : assumptions)
182-
{
183-
os << "(assert ";
184187
convert_literal(to_literal_expr(assumption).get_literal());
185-
os << ")"
186-
<< "\n";
187-
}
188+
os << "))\n";
188189
}
190+
else
191+
{
192+
// add the assumptions, if any
193+
if(!assumptions.empty())
194+
{
195+
os << "; assumptions\n";
189196

190-
// fix up the object sizes
191-
for(const auto &object : object_sizes)
192-
define_object_size(object.second, object.first);
197+
for(const auto &assumption : assumptions)
198+
{
199+
os << "(assert ";
200+
convert_literal(to_literal_expr(assumption).get_literal());
201+
os << ")"
202+
<< "\n";
203+
}
204+
}
205+
206+
os << "(check-sat)\n";
207+
}
193208

194-
os << "(check-sat)"
195-
<< "\n";
196209
os << "\n";
197210

198211
if(solver!=solvert::BOOLECTOR)

src/solvers/smt2/smt2_conv.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ class smt2_convt : public stack_decision_proceduret
5959
~smt2_convt() override = default;
6060

6161
bool use_FPA_theory;
62+
bool use_array_of_bool;
6263
bool use_as_const;
64+
bool use_check_sat_assuming;
6365
bool use_datatypes;
64-
bool use_array_of_bool;
6566
bool use_lambda_for_array;
6667
bool emit_set_logic;
6768

0 commit comments

Comments
 (0)