我尝试形式化一个以数组和数组列表作为参数的函数,并返回列表中数组的索引。我尝试了非常不同的方法并从 Z3 获得了“未知”。
这是我尝试的一些代码,其中第一个和第二个公理都不起作用(以及其他几个我没有在这里包含的代码):
(declare-fun SameArray ((Array Int Real) (Array Int Real)) Bool)
(declare-fun Match ((Array Int Real) (Array Int (Array Int Real))) Int)
(assert (forall ((array1 (Array Int Real)) (array2 (Array Int Real)))
(=
(SameArray array1 array2)
(ite (forall ((i Int)) (= (select array1 i) (select array2 i) )) true false)
)
)
)
;(assert (forall ((pattern (Array Int Real)) (list (Array Int (Array Int Real))) )
; (or
; (exists ((index Int))
; (and
; (= (SameArray pattern (select list index)) true)
; (forall ((j Int)) (or (= (SameArray pattern (select list j)) false) (>= j index)))
; (= (Match pattern list) index)
; )
; )
; (= (Match pattern list) (- 1))
; )
;))
(assert (forall ((pattern (Array Int Real)) (list (Array Int (Array Int Real))) )
(exists ((index Int))
(and
(= (Match pattern list) index)
(or
(and
(= (SameArray pattern (select list index)) true)
(forall ((j Int)) (or (= (SameArray pattern (select list j)) false) (>= j index)))
)
(= index (- 1))
)
)
)
))
; Testing - SameArray
(declare-const a1 (Array Int Real))
(declare-const a2 (Array Int Real))
(assert (= (store a1 1 1.1) a1))
(assert (= (store a1 2 1.2) a1))
(assert (= (store a1 3 1.3) a1))
(assert (= (store a2 1 2.1) a2))
(assert (= (store a2 2 2.2) a2))
(assert (= (store a2 3 2.3) a2))
(assert (= (SameArray a1 a1) true))
(assert (= (SameArray a1 a2) false))
(check-sat)
; Testing - Match
(declare-const aAll (Array Int (Array Int Real)) )
(assert (= (store aAll 1 a2) aAll))
(assert (= (store aAll 2 a1) aAll))
(assert (= (Match a1 aAll) 2))
(check-sat)
编辑:即使是非常简单的虚拟版本也不起作用。我有模式(P => Q)和(不是 P => Q')。我不知道为什么 Z3 给了我一个未知数。
(assert (forall ((pattern (Array Int Real)) (list (Array Int (Array Int Real))) )
(=>
(forall ((j Int)) (= (SameArray pattern (select list j)) false))
(= (Match pattern list) (- 1))
)
))
(assert (forall ((pattern (Array Int Real)) (list (Array Int (Array Int Real))) )
(=>
(not (forall ((j Int)) (= (SameArray pattern (select list j)) false)))
(= (Match pattern list) 1)
)
))