在Z3中排序名称问题

时间:2014-01-17 21:36:56

标签: z3

在上一篇文章Z3 group中,使用名为S的排序来证明某些组公理代表该组。请运行代码code with sort named S但是现在当排序名称更改为G时,代码不起作用。请在code with sort named G行查看问题。有必要使用名称S进行排序,或者是Z3的问题吗?请告诉我。

2 个答案:

答案 0 :(得分:1)

问题的简化版本。

$ z3 -version
Z3 version 4.3.1

使用名称S:

$ cat S.smt 
(declare-sort S)
(declare-fun f (S S) S)
(declare-const a S)
(declare-const b S)
(assert (= (f a a) a))
(assert (= (f a b) b))
(assert (= (f b a) b))
(assert (= (f b b) a))
(check-sat)

;; Restrict the search to models of size at most 2.
(assert (forall ((x S)) (or (= x a) (= x b))))

;; Associativity
(assert (not (forall ((x S) (y S) (z S)) (= (f x (f y z)) (f (f x y) z)))))
(check-sat)

$ z3 -smt2 S.smt
sat
unsat

使用名称G:

$ cat G.smt
(declare-sort G)
(declare-fun f (G G) G)
(declare-const a G)
(declare-const b G)
(assert (= (f a a) a))
(assert (= (f a b) b))
(assert (= (f b a) b))
(assert (= (f b b) a))
(check-sat)

;; Restrict the search to models of size at most 2
(assert (forall ((x G)) (or (= x a) (= x b))))

;; Associativity
(assert (not (forall ((x G) (y G) (z G)) (= (f x (f y z)) (f (f x y) z)))))
(check-sat)

$ z3 -smt2 G.smt
sat
unknown

答案 1 :(得分:0)

请知道以下代码名为G的代码是否正确。非常感谢

(declare-sort G)
(declare-fun f (G G) G)
(declare-const a G)
(declare-const b G)
(declare-const c G)
(assert (forall ((x G) (y G))
            (= (f x y)  (f y x))))
(assert (forall ((x G))
            (= (f x a) x)))
(assert (= (f b b) c))
(assert (= (f b c) a))
(assert (= (f c c) b))
(check-sat)
(get-model)

(push)
;; prove the left-module axiom
(assert (not (forall ((x G)) (= (f a x) x ))) )
(check-sat)
(pop)

(push)
;; prove the right-module axiom
(assert (not (forall ((x G)) (= (f x a) x ))) )
(check-sat)
(pop)


(declare-fun x () G)
(declare-fun y () G)
(declare-fun z () G)

(push)
;; prove the right-inverse axiom
(assert (not (=> (and  (or (= x a) (= x b) (= x c)))   (exists ((y G)) (= (f x y) a)))))
(check-sat)                
(pop)

(push)
;; prove the left-inverse axiom
(assert (not (=> (and  (or (= x a) (= x b) (= x c)))   (exists ((y G)) (= (f y x  ) a)))))
(check-sat)                
(pop)

(push)
;; prove the associativity axiom
(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)  
(pop)    

(push)
;; prove the commutative property
(assert (not (=> (and (or (= x a) (= x b) (= x c)) (or (= y a) (= y b) (= y c))) 

            (=  (f x y ) (f y x )))))

(check-sat)  
(pop) 

并且相应的输出是预期的

sat unsat unsat unsat unsat unsat unsat

请在线运行此代码here