13
13
#include < util/invariant.h>
14
14
#include < util/optional.h>
15
15
#include < util/range.h>
16
- #include < util/replace_expr.h>
17
16
#include < util/simplify_expr.h>
18
17
19
18
// / A method to detect equivalence between experts that can contain typecast
@@ -161,11 +160,11 @@ static optionalt<exprt> eager_quantifier_instantiation(
161
160
* an OR/AND expr.
162
161
**/
163
162
164
- const exprt re = simplify_expr (expr.where (), ns);
163
+ const exprt where_simplified = simplify_expr (expr.where (), ns);
165
164
166
- if (re .is_true () || re .is_false ())
165
+ if (where_simplified .is_true () || where_simplified .is_false ())
167
166
{
168
- return re ;
167
+ return where_simplified ;
169
168
}
170
169
171
170
if (var_expr.is_boolean ())
@@ -189,9 +188,9 @@ static optionalt<exprt> eager_quantifier_instantiation(
189
188
}
190
189
191
190
const optionalt<constant_exprt> min_i =
192
- get_quantifier_var_min (var_expr, re );
191
+ get_quantifier_var_min (var_expr, where_simplified );
193
192
const optionalt<constant_exprt> max_i =
194
- get_quantifier_var_max (var_expr, re );
193
+ get_quantifier_var_max (var_expr, where_simplified );
195
194
196
195
if (!min_i.has_value () || !max_i.has_value ())
197
196
return nullopt;
@@ -202,40 +201,45 @@ static optionalt<exprt> eager_quantifier_instantiation(
202
201
if (lb > ub)
203
202
return nullopt;
204
203
204
+ auto expr_simplified =
205
+ quantifier_exprt (expr.id (), expr.variables (), where_simplified);
206
+
205
207
std::vector<exprt> expr_insts;
206
208
for (mp_integer i = lb; i <= ub; ++i)
207
209
{
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 ())} );
210
212
expr_insts.push_back (constraint_expr);
211
213
}
212
214
213
215
if (expr.id () == ID_forall)
214
216
{
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)
219
221
{
220
222
expr_insts.push_back (binary_predicate_exprt (
221
223
var_expr, ID_gt, from_integer (lb, var_expr.type ())));
222
224
expr_insts.push_back (binary_predicate_exprt (
223
225
var_expr, ID_le, from_integer (ub, var_expr.type ())));
224
226
}
227
+
225
228
return simplify_expr (conjunction (expr_insts), ns);
226
229
}
227
230
else if (expr.id () == ID_exists)
228
231
{
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)
233
236
{
234
237
expr_insts.push_back (binary_predicate_exprt (
235
238
var_expr, ID_gt, from_integer (lb, var_expr.type ())));
236
239
expr_insts.push_back (binary_predicate_exprt (
237
240
var_expr, ID_le, from_integer (ub, var_expr.type ())));
238
241
}
242
+
239
243
return simplify_expr (disjunction (expr_insts), ns);
240
244
}
241
245
0 commit comments