我试图使用以下Z3-SMT-LIB代码证明Z3组满足关联定律
(set-option :mbqi true)
(declare-sort S)
(declare-fun f (S S) S)
(declare-const a S)
(declare-const b S)
(declare-const c S)
(assert (forall ((x S) (y S))
(= (f x y) (f y x))))
(assert (forall ((x S))
(= (f x a) x)))
(assert (= (f b b) c))
(assert (= (f b c) a))
(assert (= (f c c) b))
(check-sat)
(get-model)
(declare-fun x () S)
(declare-fun y () S)
(declare-fun z () S)
(assert (not (=> (and (or (= x a) (= x b) (= x c)) (or (= y a) (= y b) (= y c))
(or (= z a) (= z b) (= z c)))
(= (f x (f y z)) (f (f x y) z)))))
(check-sat)
相应的输出是
sat
(model
;; universe for S:
;; S!val!1 S!val!0 S!val!2
;; -----------
;; definitions for universe elements:
(declare-fun S!val!1 () S)
(declare-fun S!val!0 () S)
(declare-fun S!val!2 () S)
;; cardinality constraint:
(forall ((x S)) (or (= x S!val!1) (= x S!val!0) (= x S!val!2)))
;; -----------
(define-fun b () S S!val!0)
(define-fun c () S S!val!1)
(define-fun a () S S!val!2)
(define-fun f ((x!1 S) (x!2 S)) S
(ite (and (= x!1 S!val!0) (= x!2 S!val!0)) S!val!1
(ite (and (= x!1 S!val!0) (= x!2 S!val!1)) S!val!2
(ite (and (= x!1 S!val!1) (= x!2 S!val!1)) S!val!0
(ite (and (= x!1 S!val!1) (= x!2 S!val!0)) S!val!2
(ite (and (= x!1 S!val!0) (= x!2 S!val!2)) S!val!0
(ite (and (= x!1 S!val!2) (= x!2 S!val!0)) S!val!0
(ite (and (= x!1 S!val!2) (= x!2 S!val!1)) S!val!1
(ite (and (= x!1 S!val!1) (= x!2 S!val!2)) S!val!1 x!1)))))))))
)
unsat
在线here
运行此示例问题是:
此证明是否正确?
有更优雅的证据吗?
答案 0 :(得分:1)
每个群体都必须满足相关性公理。我猜你试图证明第一个断言块的每个模型都满足关联公理。为了完成这个例子,我们还应该证明逆元素公理。
为了证明这两个属性,我们可以使用以下命令:
(push)
;; prove the inverse axiom
(assert (not (forall ((x S)) (exists ((y S)) (= (f x y) a)))))
(check-sat)
(pop)
(push)
;; prove the associativity axiom
(assert (not (forall ((x S) (y S) (z S)) (= (f x (f y z)) (f (f x y) z)))))
(check-sat)
(pop)
Z3无法证明这一点。但是,如果我们断言我们只对大小最多为3的模型感兴趣,它就会成功。
(assert (forall ((x S)) (or (= x a) (= x b) (= x c))))
Here就是完整的例子。