1

I'm curious what the limitations on z3's map operator are. According to the z3 tutorial (http://rise4fun.com/z3/tutorial), "Z3 provides a parametrized map function on arrays. It allows applying arbitrary functions to the range of arrays."

Map appears to work when I'm mapping built-in functions or functions declared with (declare-fun ...) syntax. When I attempt to use map with function (really macros) defined with (define-fun ...) syntax, I receive the error invalid function declaration reference, named expressions (aka macros) cannot be referenced.

Is there a standard way to map user-defined functions over arrays?

Here is some code that illustrates my confusion:

;simple function, equivalent to or
(define-fun my-or ((x Bool) (y Bool)) Bool (or x y))
(assert (forall ((x Bool) (y Bool)) (= (my-or x y) (or x y))))
(check-sat)

;mapping or with map works just fine
(define-sort Set () (Array Int Bool))
(declare-const a Set)
(assert ( = a ((_ map or) a a) ))
(check-sat)

;but this fails with error
(assert ( = a ((_ map my-or) a a) ))

I'm currently hacking around the problem like this:

(define-fun my-or-impl ((x Bool) (y Bool)) Bool (or x y))
(declare-fun my-or (Bool Bool) Bool)
(assert (forall ((x Bool) (y Bool)) (= (my-or x y) (my-or-impl x y))))
(check-sat)

But I'm hoping that there's a way to solve this which doesn't involve universal quantifiers.

4

2 回答 2

1

不幸的是,define-fun这只是Z3中的一个宏定义。它们在 Z3 SMT 2.0 解析器中实现。它们不是 Z3 内核的一部分。也就是说,Z3 求解器甚至没有“看到”这些定义。使用declare-fun和量词的方法有效,但正如你所说,我们应该避免使用量词,因为它们会产生性能问题,而且使用量词很容易产生 Z3 无法解决的问题。最好的选择是使用(_ map or).

于 2013-10-12T19:18:11.410 回答
0

最好的选择是使用 (_ map or)。

除非有人想在数组上映射一个非内置函数......我想declare-funplusassert是唯一的方法吗?

于 2013-10-24T13:04:22.483 回答