Skip to content

Commit 6850351

Browse files
committed
use quantifier_exprt::instantiate instead of replace_expr
The quantifier_exprt offers a convenient wrapper for doing the instantiation.
1 parent fb6b286 commit 6850351

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/solvers/flattening/boolbv_quantifier.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Author: Daniel Kroening, [email protected]
1313
#include <util/invariant.h>
1414
#include <util/optional.h>
1515
#include <util/range.h>
16-
#include <util/replace_expr.h>
1716
#include <util/simplify_expr.h>
1817

1918
/// A method to detect equivalence between experts that can contain typecast
@@ -161,11 +160,11 @@ static optionalt<exprt> eager_quantifier_instantiation(
161160
* an OR/AND expr.
162161
**/
163162

164-
const exprt re = simplify_expr(expr.where(), ns);
163+
const exprt where_simplified = simplify_expr(expr.where(), ns);
165164

166-
if(re.is_true() || re.is_false())
165+
if(where_simplified.is_true() || where_simplified.is_false())
167166
{
168-
return re;
167+
return where_simplified;
169168
}
170169

171170
if(var_expr.is_boolean())
@@ -189,9 +188,9 @@ static optionalt<exprt> eager_quantifier_instantiation(
189188
}
190189

191190
const optionalt<constant_exprt> min_i =
192-
get_quantifier_var_min(var_expr, re);
191+
get_quantifier_var_min(var_expr, where_simplified);
193192
const optionalt<constant_exprt> max_i =
194-
get_quantifier_var_max(var_expr, re);
193+
get_quantifier_var_max(var_expr, where_simplified);
195194

196195
if(!min_i.has_value() || !max_i.has_value())
197196
return nullopt;
@@ -202,40 +201,45 @@ static optionalt<exprt> eager_quantifier_instantiation(
202201
if(lb > ub)
203202
return nullopt;
204203

204+
auto expr_simplified =
205+
quantifier_exprt(expr.id(), expr.variables(), where_simplified);
206+
205207
std::vector<exprt> expr_insts;
206208
for(mp_integer i = lb; i <= ub; ++i)
207209
{
208-
exprt constraint_expr = re;
209-
replace_expr(var_expr, from_integer(i, var_expr.type()), constraint_expr);
210+
exprt constraint_expr =
211+
expr_simplified.instantiate({from_integer(i, var_expr.type())});
210212
expr_insts.push_back(constraint_expr);
211213
}
212214

213215
if(expr.id() == ID_forall)
214216
{
215-
// maintain the domain constraint if it isn't guaranteed by the
216-
// instantiations (for a disjunction the domain constraint is implied by the
217-
// instantiations)
218-
if(re.id() == ID_and)
217+
// maintain the domain constraint if it isn't guaranteed
218+
// by the instantiations (for a disjunction the domain
219+
// constraint is implied by the instantiations)
220+
if(where_simplified.id() == ID_and)
219221
{
220222
expr_insts.push_back(binary_predicate_exprt(
221223
var_expr, ID_gt, from_integer(lb, var_expr.type())));
222224
expr_insts.push_back(binary_predicate_exprt(
223225
var_expr, ID_le, from_integer(ub, var_expr.type())));
224226
}
227+
225228
return simplify_expr(conjunction(expr_insts), ns);
226229
}
227230
else if(expr.id() == ID_exists)
228231
{
229-
// maintain the domain constraint if it isn't trivially satisfied by the
230-
// instantiations (for a conjunction the instantiations are stronger
231-
// constraints)
232-
if(re.id() == ID_or)
232+
// maintain the domain constraint if it isn't trivially satisfied
233+
// by the instantiations (for a conjunction the instantiations are
234+
// stronger constraints)
235+
if(where_simplified.id() == ID_or)
233236
{
234237
expr_insts.push_back(binary_predicate_exprt(
235238
var_expr, ID_gt, from_integer(lb, var_expr.type())));
236239
expr_insts.push_back(binary_predicate_exprt(
237240
var_expr, ID_le, from_integer(ub, var_expr.type())));
238241
}
242+
239243
return simplify_expr(disjunction(expr_insts), ns);
240244
}
241245

0 commit comments

Comments
 (0)