Skip to content

Commit fb28475

Browse files
authored
Merge pull request #8530 from diffblue/smt2-nand-nor
SMT2: implement nand, nor, xnor
2 parents ce40fbd + 10eac1d commit fb28475

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
@@ -1413,6 +1413,38 @@ void smt2_convt::convert_expr(const exprt &expr)
14131413
}
14141414
out << ")";
14151415
}
1416+
else if(expr.id() == ID_nand || expr.id() == ID_nor || expr.id() == ID_xnor)
1417+
{
1418+
DATA_INVARIANT(
1419+
expr.is_boolean(),
1420+
"logical nand, nor, xnor expressions should have Boolean type");
1421+
DATA_INVARIANT(
1422+
expr.operands().size() >= 1,
1423+
"logical nand, nor, xnor expressions should have at least one operand");
1424+
1425+
// SMT-LIB doesn't have nand, nor, xnor
1426+
out << "(not ";
1427+
if(expr.operands().size() == 1)
1428+
convert_expr(to_multi_ary_expr(expr).op0());
1429+
else
1430+
{
1431+
if(expr.id() == ID_nand)
1432+
out << "(and";
1433+
else if(expr.id() == ID_nor)
1434+
out << "(and";
1435+
else if(expr.id() == ID_xnor)
1436+
out << "(xor";
1437+
else
1438+
DATA_INVARIANT(false, "unexpected expression");
1439+
for(const auto &op : expr.operands())
1440+
{
1441+
out << ' ';
1442+
convert_expr(op);
1443+
}
1444+
out << ')'; // or, and, xor
1445+
}
1446+
out << ')'; // not
1447+
}
14161448
else if(expr.id()==ID_implies)
14171449
{
14181450
const implies_exprt &implies_expr = to_implies_expr(expr);

0 commit comments

Comments
 (0)