How to prove that the Z3 group satisfies the associative law using Z3-SMT-LIB

血红的双手。 提交于 2019-12-13 05:11:57

问题


I am trying to prove that the Z3 group satisfies the associative law using the following Z3-SMT-LIB code

(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)  

The corresponding output is

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

Run this example online here

The questions are:

  1. Is this proof correct?

  2. There is a more elegant proof?


回答1:


Every group must satisfy the associativity axiom. I guess you are trying to prove that every model for the first block of assertions satisfy the associativity axiom. To complete the example, we should also prove the inverse element axiom.

To prove these two properties, we can use the following commands:

(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 cannot prove them. However, it succeeds if we assert that that we are only interested in models of size at most 3.

(assert (forall ((x S)) (or (= x a) (= x b) (= x c))))

Here is the complete example.



来源:https://stackoverflow.com/questions/20431326/how-to-prove-that-the-z3-group-satisfies-the-associative-law-using-z3-smt-lib

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!