Skip to content

Commit 9778868

Browse files
committed
fix distinct operator
This adds support for the distinct operator in SMTlib, by directly translating it into "not equal" Prior to this change, the distinct operator was ignored, giving incorrect results
1 parent 268f886 commit 9778868

File tree

7 files changed

+41
-1
lines changed

7 files changed

+41
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(assert (distinct (_ bv0 8) (_ bv1 8)))
2+
(check-sat)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CORE
2+
distinct.smt2
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^sat$
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(assert (distinct (_ bv0 8) (_ bv1 8)(_ bv2 8) (_ bv1 8)))
2+
(check-sat)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CORE
2+
distinct2.smt2
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^unsat$
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(assert (distinct (_ bv0 8)(_ bv0 8)(_ bv2 8) (_ bv2 8)))
2+
(check-sat)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CORE
2+
distinct3.smt2
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^unsat$

src/solvers/smt2/smt2_parser.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,23 @@ void smt2_parsert::setup_expressions()
950950

951951
expressions["distinct"] = [this] {
952952
// pair-wise different constraint, multi-ary
953-
return multi_ary("distinct", operands());
953+
auto op = operands();
954+
if(op.size() == 2)
955+
return binary_predicate(ID_notequal, op);
956+
else
957+
{
958+
std::vector<exprt> pairwise_constraints;
959+
for(std::size_t i = 0; i < op.size(); i++)
960+
{
961+
for(std::size_t j = i; j < op.size(); j++)
962+
{
963+
if(i != j)
964+
pairwise_constraints.push_back(
965+
binary_exprt(op[i], ID_notequal, op[j], bool_typet()));
966+
}
967+
}
968+
return multi_ary(ID_and, pairwise_constraints);
969+
}
954970
};
955971

956972
expressions["ite"] = [this] {

0 commit comments

Comments
 (0)