我有以下程序:
;;; Sets
(declare-fun lock_0 (Int) Bool)
(declare-fun lock_1 (Int) Bool)
(declare-fun lock_2 (Int) Bool)
(declare-fun lock_3 (Int) Bool)
;;; verify if sets lock_0 and lock_1 haven't elements in common
(assert (exists ((x Int)) (=> (lock_0 x) (not (lock_1 x)))))
;;; verify if sets lock_2 and lock_3 haven't elements in common
(assert (exists ((x Int)) (=> (lock_2 x) (not (lock_3 x)))))
;;; Sets only contain 1 for Lock_0 and lock_1 or 2 for lock_2 or lock_3
(assert (forall ((x Int)) (= (lock_0 x) (= x 2))))
(assert (forall ((x Int)) (= (lock_1 x) (= x 2))))
(assert (forall ((x Int)) (= (lock_2 x) (= x 1))))
(assert (forall ((x Int)) (= (lock_3 x) (= x 1))))
;;; set [l1]
(declare-fun SL1 (Int) Bool)
;;; set only contain 1
(assert (forall ((x Int)) (= (SL1 x) (= x 1))))
;;; SL1 subset lock_2
(assert (forall ((x Int)) (=> (SL1 x) (lock_2 x))))
;; sat
(check-sat)
( get-value (( lock_0 1 )))
( get-value (( lock_0 2 )))
( get-value (( lock_1 1 )))
( get-value (( lock_1 2 )))
( get-value (( lock_2 1 )))
( get-value (( lock_2 2 )))
( get-value (( lock_3 1 )))
( get-value (( lock_3 2 )))
( get-value (( SL1 1 )))
( get-value (( SL1 2 )))
结果:
sat
((( lock_0 1 ) false))
((( lock_0 2 ) true))
((( lock_1 1 ) false))
((( lock_1 2 ) true))
((( lock_2 1 ) true))
((( lock_2 2 ) false))
((( lock_3 1 ) true))
((( lock_3 2 ) false))
((( SL1 1 ) true))
((( SL1 2 ) false))
我需要生成lock_0
以下lock_1
集合:
[] - Empty set
[2]
lock_2
并生成lock_3
以下集合:
[] - Empty set
[1]
但集合lock_0
并lock_1
不能有共同的元素。
但最后我得到:
( get-value (( lock_0 2 ))) true
( get-value (( lock_1 2 ))) true
结果对每个人都是正确的,在一种情况下应该是错误的,例如:
( get-value (( lock_0 2 ))) false
( get-value (( lock_1 2 ))) true
因为集合不能包含相等的元素。
lock_2
和的问题相同lock_3
。
如果我添加:
;;; Set [l2]
(declare-fun SL2 (Int) Bool)
;;; set only contain 2
(assert (forall ((x Int)) (= (SL2 x) (= x 2))))
;;; SL2 is subset lock_0
(assert (forall ((x Int)) (=> (SL2 x) (lock_0 x))))
;; unsat
(check-sat)
我希望结果是不满意的,但是由于集合(lock_0 and lock_1
或lock_2 and lock_3
)相等,我会坐下来。
例如:如果我得到lock_0 = []
andlock_1 = [2]
和lock_2 = [1]
and lock_3 = []
,程序是正确的。
我怎么解决这个问题?
开始编辑
添加这段代码:
(assert (forall ((x Int)) (or (not (lock_0 x)) (not (lock_1 x)))))
结果不满意。它应该是坐着的。
那么如何为同一个集合、空集合或集合 {2} 生成?还是不可能做到?
如果这是不可能的,那么我们可以让元素 0 是空集吗?但为此,我只能拥有以下套装:
[0] - empty set
[2]
所以我这样做:(assert (forall ((x Int)) (= (lock_1 x) (or (= x 0) (= x 2)))))
但是,如果我想要这些集合lock_0
并且lock_1
可能也有 3 作为一个元素应该得到:
[0] - empty set
[2]
[3]
[2,3] - may not include zero, since only the zero should be used as the singleton set [0]
所以我这样做:(assert (forall ((x Int)) (= (lock_1 x) (or (= x 0) (and (!= x 0) (or (= x 2) (= x 3)))))))
是对的吗?
另一个问题:如果我想创建一个接受集合的函数?因为集合是一个函数。例如:
(define-fun example ((s1 Set) (s2 Set) (x Int)) Int
(if (and (s1 x) (not (s2 x)))
(* x x)
0))
但我不知道用什么来代替 Set (Set s1),请帮帮我。
结束编辑