首页 文章

Python相当于Z3_API Z3_benchmark_to_smtlib_string的第7个参数

提问于
浏览
0

我们目前在python上使用z3来检查程序跟踪的可行性 . 基于跟踪我们创建z3公式和断言,我们的下一个方法是使用SMT2作为中间语言通过Z3_benchmark_to_smtlib_string将这些断言提供给iZ3和smtinterpol .

一个小例子:x = Int('x')y = Int('y')

s = Solver()

# Assertions
s.assert_and_track(x > y, 'p1')
s.assert_and_track(x == 0, 'p2')
s.assert_and_track(y > 0, 'p3')

a = s.assertions()
v = a[0].as_ast()
f = And(a[1], a[2])
print Z3_benchmark_to_smtlib_string(a[0].ctx_ref(), "name", "QF_LIA", "unsat", "", 1, v, f.as_ast())

这会产生输出

; name    
(set-info :status unsat)
(set-logic QF_LIA)
(declare-fun y () Int)
(declare-fun x () Int)
(assert
(> x y))
(assert
(let (($x12 (> y 0)))
(let (($x10 (= x 0)))
(and $x10 $x12))))
(check-sat)

经过一些经过精心修改后,将它喂给smtinterpol是好的:

; name
(set-info :status unsat)
(set-option :produce-proofs true)
(set-logic QF_LIA)
(declare-fun y () Int)
(declare-fun x () Int)
(assert (!
(> x y) :named p1))
(assert (!
(let (($x12 (> y 0)))
(let (($x10 (= x 0)))
(and $x10 $x12))) :named p2))
(check-sat)
(get-interpolants p1 p2)

我们希望有一种可能性,即在smt2输出中,所有断言都没有通过AND将所有1:end断言通过AND组合成一个等式 . 如果试图通过c代码文档猜测(capi.html#gaf93844a5964ad8dee609fac3470d86e4“> http://research.microsoft.com/en-us/um/redmond/projects/z3/group_capi.html#gaf93844a5964ad8dee609fac3470d86e4)的格式第6和第7个参数,但我可以得到它给他一个断言列表 .

我试过例如:

print Z3_benchmark_to_smtlib_string(a[0].ctx_ref(), "name", "QF_LIA", "unsat", "", 2, f.as_ast(), v)

但会遇到

exception: access violation reading 0x00000004

只是给出一个列表是行不通的:

print Z3_benchmark_to_smtlib_string(a[0].ctx_ref(), "name", "QF_LIA", "unsat", "", 2, [a[0].as_ast(), a[1].as_ast()], a[2].as_ast())

基本上,有人知道什么是__in_ecount(num_assumptions)Z3_ast const的python等价物?或者是否有另一种可能从解算器的断言列表生成smt2输出?

1 回答

  • 1

    如您所知,Python API不会将python包装器暴露给打印基准测试的函数 . C签名是:

    /**
       \brief Convert the given benchmark into SMT-LIB formatted string.
    
       \conly \warning The result buffer is statically allocated by Z3. It will
       \conly be automatically deallocated when #Z3_del_context is invoked.
       \conly So, the buffer is invalidated in the next call to \c Z3_benchmark_to_smtlib_string.
    
       \param c - context.
       \param name - name of benchmark. The argument is optional.
       \param logic - the benchmark logic. 
       \param status - the status string (sat, unsat, or unknown)
       \param attributes - other attributes, such as source, difficulty or category.
       \param num_assumptions - number of assumptions.
       \param assumptions - auxiliary assumptions.
       \param formula - formula to be checked for consistency in conjunction with assumptions.
    
       def_API('Z3_benchmark_to_smtlib_string', STRING, (_in(CONTEXT), _in(STRING), _in(STRING), _in(STRING), _in(STRING), _in(UINT), _in_array(5, AST), _in(AST)))
    */
    Z3_string Z3_API Z3_benchmark_to_smtlib_string(__in   Z3_context c, 
                                                   __in Z3_string name,
                                                   __in Z3_string logic,
                                                   __in Z3_string status,
                                                   __in Z3_string attributes,
                                                   __in   unsigned num_assumptions,
                                                   __in_ecount(num_assumptions) Z3_ast const assumptions[],
                                                   __in   Z3_ast formula);
    

    在z3.py中有几个类似函数的例子,它们将数组作为参数,并且它们使用相同的模式,其中给C函数提供两个参数:(1)数组的长度(2)实际的数组 . 您应该将数组的长度和unpickled数组传递给C函数 . 此更改的示例的变体如下:http://rise4fun.com/Z3Py/rGEp

相关问题