Z3查找有效排列

时间:2018-06-11 16:49:49

标签: z3

我试图让Z3找到满足某些约束条件的固定大小序列的所有可能排列。但是,到目前为止我已经开发了代码,我遇到了超时错误:

(set-option :produce-unsat-cores true)
(set-option :produce-models true)

; --------------- Basic Definitions -------------------
(declare-datatypes () ((Obj A B C)))

; --------------- Predicates -------------------------------

(define-sort MyList () (Seq Obj))

(define-fun in_list ((o Obj) (l MyList)) Bool (seq.contains l (seq.unit o)))

(define-fun permutation ((l1 MyList) (l2 MyList)) Bool
                    (forall ((o Obj)) (= (in_list o l1) (in_list o l2))))


; Two difference permutations of the same list
(declare-const l0 MyList)
(declare-const l1 MyList)

(assert (= 2 (seq.len l0)))
(assert (= 2 (seq.len l1)))
(assert (not (= l1 l0)))
(assert (permutation l0 l1))

; --------------- Verify -------------------
(check-sat)
(get-model)

看起来这应该是一个非常简单的解决方案(即使是暴力也应该花费几毫秒),所以我非常困惑导致超时的原因。有什么帮助吗?

1 个答案:

答案 0 :(得分:1)

当量词出现时,你已经遇到了Z3可以做的限制。

您可能希望查看此问题:Defining a Theory of Sets with Z3/SMT-LIB2

在这种情况下,问题是关于一般设定操作,但我认为您也会找到适用于您的案例的答案。 (简而言之,禁用MBQI,看看是否可以使用函数而不是序列。)