Skip to content

Commit 10eac1d

Browse files
committed
SMT2: implement nand, nor, xnor
This adds the multi-ary Boolean operators nand/nor/xnor to the SMT2 backend.
1 parent fa299c5 commit 10eac1d

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Diff for: src/solvers/smt2/smt2_conv.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,38 @@ void smt2_convt::convert_expr(const exprt &expr)
13621362
}
13631363
out << ")";
13641364
}
1365+
else if(expr.id() == ID_nand || expr.id() == ID_nor || expr.id() == ID_xnor)
1366+
{
1367+
DATA_INVARIANT(
1368+
expr.is_boolean(),
1369+
"logical nand, nor, xnor expressions should have Boolean type");
1370+
DATA_INVARIANT(
1371+
expr.operands().size() >= 1,
1372+
"logical nand, nor, xnor expressions should have at least one operand");
1373+
1374+
// SMT-LIB doesn't have nand, nor, xnor
1375+
out << "(not ";
1376+
if(expr.operands().size() == 1)
1377+
convert_expr(to_multi_ary_expr(expr).op0());
1378+
else
1379+
{
1380+
if(expr.id() == ID_nand)
1381+
out << "(and";
1382+
else if(expr.id() == ID_nor)
1383+
out << "(and";
1384+
else if(expr.id() == ID_xnor)
1385+
out << "(xor";
1386+
else
1387+
DATA_INVARIANT(false, "unexpected expression");
1388+
for(const auto &op : expr.operands())
1389+
{
1390+
out << ' ';
1391+
convert_expr(op);
1392+
}
1393+
out << ')'; // or, and, xor
1394+
}
1395+
out << ')'; // not
1396+
}
13651397
else if(expr.id()==ID_implies)
13661398
{
13671399
const implies_exprt &implies_expr = to_implies_expr(expr);

0 commit comments

Comments
 (0)