我有一个用smt2-lib格式编写的z3模型。我注意到当我使用时:
(declare-const flat1 (Seq Dummy))
(assert (= flat1 (unroll dummyFormula1)))
模型是坐着的,而当我使用时:
(define-fun flat1 () (Seq Dummy) (unroll dummyFormula1))
该模型报告为未知。为什么差异很重要?如果它有帮助,我可以生成我的模型的最小版本。
编辑#1 - 一个最小的例子
由于this bug,请务必使用github master中的z3运行它。您可以在下面用A)
和B)
表示的两个版本之间进行切换。
(set-option :produce-models true)
; --------------- Basic Definitions -------------------
(declare-datatype Dummy (A B))
(declare-datatype Formula
((Base (forB Dummy))
(And (andB1 Formula) (andB2 Formula))
(Or (orB1 Formula) (orB2 Formula))
(Not (notB Formula))))
(declare-const dummyFormula1 Formula)
(assert (= dummyFormula1 (Base A)))
(declare-const dummyFormula2 Formula)
(assert (= dummyFormula2 (And (Base A) (Base A))))
; --------------- Some functions -----------------------
(define-fun
in_list ((o Dummy) (l (Seq Dummy))) Bool
(seq.contains l (seq.unit o)))
(define-fun
permutation ((l1 (Seq Dummy)) (l2 (Seq Dummy))) Bool
(forall ((o Dummy)) (= (in_list o l1) (in_list o l2))))
(define-fun-rec unroll ((f Formula)) (Seq Dummy)
(match f
(((Base j) (seq.unit j))
((And f1 f2) (seq.++ (unroll f1) (unroll f2)))
((Or f1 f2) (seq.++ (unroll f1) (unroll f2)))
((Not f1) (unroll f1)))))
; -------------- The question -------------------------
;; Here are two versions that should express the same idea, but try commenting
;; the first one and uncommenting the second one!
;; A)
(declare-const flat1 (Seq Dummy))
(assert (= flat1 (unroll dummyFormula1)))
;; B)
; (define-fun flat1 () (Seq Dummy) (unroll dummyFormula1))
; -----------------------------------------------------
(declare-const flat2 (Seq Dummy))
(assert (= flat2 (unroll dummyFormula2)))
(assert (permutation flat1 flat2))
; --------------- Verify -------------------
(check-sat)
(get-model)
很难说没有看到z3的内部。但我想指出,虽然这两个结构非常相似,但是有一个微妙的区别。
如果你看一下标准(http://smtlib.cs.uiowa.edu/papers/smt-lib-reference-v2.6-r2017-07-18.pdf)的第62页,它说:
(define-fun f ((x1 σ1) · · · (xn σn)) σ t)
with n ≥ 0 and t not containing f is semantically equivalent to the command sequence
(declare-fun f (σ1 · · · σn) σ)
(assert (forall ((x1 σ1) · · · (xn σn)) (= ( f x1 · · · xn) t)).
因此,当您使用define-fun
表单时,您明确地使用量化公式。当您手动使用declare-const
/ assert
时,此量化不存在。
现在您可以争辩说您的案例中没有参数,因此应该没有区别,我同意您的看法。但是你也在使用像match
,define-fun-rec
等新功能,所以很明显z3在这里绊倒了。由于您已经有一个最小的例子,为什么不将它发布到z3 github问题网站并在那里得到一些反馈。我怀疑也许宏查找器丢失了一个案例并且不能实例化这个特例,但真的很难说并且可能也有很好的理由。
如果您确实发布并获得了一个好的答案,请更新此问题,以便我们知道发生了什么!