@@ -56,6 +56,7 @@ smt2_convt::smt2_convt(
56
56
: use_FPA_theory(false ),
57
57
use_datatypes(false ),
58
58
use_array_of_bool(false ),
59
+ use_lambda_for_array(false ),
59
60
emit_set_logic(true ),
60
61
ns(_ns),
61
62
out(_out),
@@ -97,6 +98,7 @@ smt2_convt::smt2_convt(
97
98
98
99
case solvert::Z3:
99
100
use_array_of_bool = true ;
101
+ use_lambda_for_array = true ;
100
102
emit_set_logic = false ;
101
103
use_datatypes = true ;
102
104
break ;
@@ -1289,6 +1291,31 @@ void smt2_convt::convert_expr(const exprt &expr)
1289
1291
CHECK_RETURN (it != defined_expressions.end ());
1290
1292
out << it->second ;
1291
1293
}
1294
+ else if (expr.id () == ID_array_comprehension)
1295
+ {
1296
+ const auto &array_comprehension = to_array_comprehension_expr (expr);
1297
+
1298
+ DATA_INVARIANT (
1299
+ array_comprehension.type ().id () == ID_array,
1300
+ " array_comprehension expression shall have array type" );
1301
+
1302
+ if (use_lambda_for_array)
1303
+ {
1304
+ out << " (lambda ((" ;
1305
+ convert_expr (array_comprehension.arg ());
1306
+ out << " " ;
1307
+ convert_type (array_comprehension.type ().size ().type ());
1308
+ out << " )) " ;
1309
+ convert_expr (array_comprehension.body ());
1310
+ out << " )" ;
1311
+ }
1312
+ else
1313
+ {
1314
+ const auto &it = defined_expressions.find (array_comprehension);
1315
+ CHECK_RETURN (it != defined_expressions.end ());
1316
+ out << it->second ;
1317
+ }
1318
+ }
1292
1319
else if (expr.id ()==ID_index)
1293
1320
{
1294
1321
convert_index (to_index_expr (expr));
@@ -4390,6 +4417,35 @@ void smt2_convt::find_symbols(const exprt &expr)
4390
4417
defined_expressions[expr]=id;
4391
4418
}
4392
4419
}
4420
+ else if (expr.id () == ID_array_comprehension)
4421
+ {
4422
+ if (!use_lambda_for_array)
4423
+ {
4424
+ if (defined_expressions.find (expr) == defined_expressions.end ())
4425
+ {
4426
+ const auto &array_comprehension = to_array_comprehension_expr (expr);
4427
+
4428
+ const irep_idt id =
4429
+ " array_comprehension." + std::to_string (defined_expressions.size ());
4430
+ out << " (declare-fun " << id << " () " ;
4431
+ convert_type (array_comprehension.type ());
4432
+ out << " )\n " ;
4433
+
4434
+ out << " ; the following is a substitute for lambda i . x(i)\n " ;
4435
+ out << " (assert (forall ((" ;
4436
+ convert_expr (array_comprehension.arg ());
4437
+ out << " " ;
4438
+ convert_type (array_comprehension.type ().size ().type ());
4439
+ out << " )) (= (select " << id << " " ;
4440
+ convert_expr (array_comprehension.arg ());
4441
+ out << " ) " ;
4442
+ convert_expr (array_comprehension.body ());
4443
+ out << " )))\n " ;
4444
+
4445
+ defined_expressions[expr] = id;
4446
+ }
4447
+ }
4448
+ }
4393
4449
else if (expr.id ()==ID_array)
4394
4450
{
4395
4451
if (defined_expressions.find (expr)==defined_expressions.end ())
0 commit comments