在z3中映射用户定义的函数

时间:2013-10-08 20:47:51

标签: z3

我很好奇z3的地图运营商的限制是什么。根据z3教程(http://rise4fun.com/z3/tutorial),“Z3在数组上提供了参数化的映射函数。它允许将任意函数应用于数组范围。”

当我映射使用(declare-fun ...)语法声明的内置函数或函数时,映射似乎起作用。当我尝试使用带有(define-fun ...)语法定义的函数(真正的宏)的map时,我收到错误无效的函数声明引用,无法引用命名表达式(aka宏)。

是否有一种标准方法可以在数组上映射用户定义的函数?

以下是一些说明我困惑的代码:

;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) ))

我目前正在解决这个问题:

(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)

但是我希望有一种方法可以解决这个问题,而不涉及通用量词。

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

  

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

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