z3 C ++ API&伊特

时间:2013-01-04 15:59:46

标签: z3

也许我错过了什么,但使用z3 C ++ API构建if-then-else表达式的方法是什么?

我可以使用C API,但我想知道为什么C ++ API中没有这样的函数。

的问候, 于连

1 个答案:

答案 0 :(得分:8)

我们可以混合使用C和C ++ API。文件examples/c++/example.cpp包含使用C API创建if-then-else表达式的示例。函数to_expr实际上是用{+ 1}}包装C ++“智能指针”Z3_ast,它自动管理我们的引用计数器。

expr

I just added the ite function to the C++ API。它将在下一版本(v4.3.2)中提供。如果需要,可以添加到系统中的void ite_example() { std::cout << "if-then-else example\n"; context c; expr f = c.bool_val(false); expr one = c.int_val(1); expr zero = c.int_val(0); expr ite = to_expr(c, Z3_mk_ite(c, f, one, zero)); std::cout << "term: " << ite << "\n"; } 文件中。要包含的好地方是函数z3++.h

implies

使用此功能,我们可以写:

/**
   \brief Create the if-then-else expression <tt>ite(c, t, e)</tt>

   \pre c.is_bool()
*/
friend expr ite(expr const & c, expr const & t, expr const & e) {
    check_context(c, t); check_context(c, e);
    assert(c.is_bool());
    Z3_ast r = Z3_mk_ite(c.ctx(), c, t, e);
    c.check_error();
    return expr(c.ctx(), r);
}