@@ -57,6 +57,7 @@ smt2_convt::smt2_convt(
57
57
use_as_const(false ),
58
58
use_datatypes(false ),
59
59
use_array_of_bool(false ),
60
+ use_lambda_for_array(false ),
60
61
emit_set_logic(true ),
61
62
ns(_ns),
62
63
out(_out),
@@ -101,6 +102,7 @@ smt2_convt::smt2_convt(
101
102
case solvert::Z3:
102
103
use_as_const = true ;
103
104
use_array_of_bool = true ;
105
+ use_lambda_for_array = true ;
104
106
emit_set_logic = false ;
105
107
use_datatypes = true ;
106
108
break ;
@@ -1304,6 +1306,31 @@ void smt2_convt::convert_expr(const exprt &expr)
1304
1306
out << it->second ;
1305
1307
}
1306
1308
}
1309
+ else if (expr.id () == ID_array_comprehension)
1310
+ {
1311
+ const auto &array_comprehension = to_array_comprehension_expr (expr);
1312
+
1313
+ DATA_INVARIANT (
1314
+ array_comprehension.type ().id () == ID_array,
1315
+ " array_comprehension expression shall have array type" );
1316
+
1317
+ if (use_lambda_for_array)
1318
+ {
1319
+ out << " (lambda ((" ;
1320
+ convert_expr (array_comprehension.arg ());
1321
+ out << " " ;
1322
+ convert_type (array_comprehension.type ().size ().type ());
1323
+ out << " )) " ;
1324
+ convert_expr (array_comprehension.body ());
1325
+ out << " )" ;
1326
+ }
1327
+ else
1328
+ {
1329
+ const auto &it = defined_expressions.find (array_comprehension);
1330
+ CHECK_RETURN (it != defined_expressions.end ());
1331
+ out << it->second ;
1332
+ }
1333
+ }
1307
1334
else if (expr.id ()==ID_index)
1308
1335
{
1309
1336
convert_index (to_index_expr (expr));
@@ -4408,6 +4435,44 @@ void smt2_convt::find_symbols(const exprt &expr)
4408
4435
}
4409
4436
}
4410
4437
}
4438
+ else if (expr.id () == ID_array_comprehension)
4439
+ {
4440
+ if (!use_lambda_for_array)
4441
+ {
4442
+ if (defined_expressions.find (expr) == defined_expressions.end ())
4443
+ {
4444
+ const auto &array_comprehension = to_array_comprehension_expr (expr);
4445
+ const auto &array_size = array_comprehension.type ().size ();
4446
+
4447
+ const irep_idt id =
4448
+ " array_comprehension." + std::to_string (defined_expressions.size ());
4449
+ out << " (declare-fun " << id << " () " ;
4450
+ convert_type (array_comprehension.type ());
4451
+ out << " )\n " ;
4452
+
4453
+ out << " ; the following is a substitute for lambda i . x(i)\n " ;
4454
+ out << " ; universally quantified initialization of the array\n " ;
4455
+ out << " (assert (forall ((" ;
4456
+ convert_expr (array_comprehension.arg ());
4457
+ out << " " ;
4458
+ convert_type (array_size.type ());
4459
+ out << " )) (=> (and (bvule (_ bv0 " << boolbv_width (array_size.type ())
4460
+ << " ) " ;
4461
+ convert_expr (array_comprehension.arg ());
4462
+ out << " ) (bvult " ;
4463
+ convert_expr (array_comprehension.arg ());
4464
+ out << " " ;
4465
+ convert_expr (array_size);
4466
+ out << " )) (= (select " << id << " " ;
4467
+ convert_expr (array_comprehension.arg ());
4468
+ out << " ) " ;
4469
+ convert_expr (array_comprehension.body ());
4470
+ out << " ))))\n " ;
4471
+
4472
+ defined_expressions[expr] = id;
4473
+ }
4474
+ }
4475
+ }
4411
4476
else if (expr.id ()==ID_array)
4412
4477
{
4413
4478
if (defined_expressions.find (expr)==defined_expressions.end ())
0 commit comments