Skip to content

Commit e5f6346

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

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/solvers/smt2/smt2_conv.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,34 @@ void smt2_convt::convert_expr(const exprt &expr)
13621362
}
13631363
out << ")";
13641364
}
1365+
else if(expr.id() == ID_nand || expr.id() == ID_nor)
1366+
{
1367+
DATA_INVARIANT(
1368+
expr.is_boolean(),
1369+
"logical nand, nor expressions should have Boolean type");
1370+
DATA_INVARIANT(
1371+
expr.operands().size() >= 1,
1372+
"logical nand, nor expressions should have at least one operand");
1373+
1374+
// SMT-LIB doesn't have nand, nor
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
1383+
out << "(or";
1384+
for(const auto &op : expr.operands())
1385+
{
1386+
out << " ";
1387+
convert_expr(op);
1388+
}
1389+
out << ')'; // or, and
1390+
}
1391+
out << ')'; // not
1392+
}
13651393
else if(expr.id()==ID_implies)
13661394
{
13671395
const implies_exprt &implies_expr = to_implies_expr(expr);

0 commit comments

Comments
 (0)