How to produce the model for partial orders?

蹲街弑〆低调 提交于 2019-12-10 23:56:43

问题


I am trying to use Z3 to produce a model for a set of SAT assertions describing a partial order theory. I tried the subtype example in Z3 guide but it seems I cannot get a concrete model. Is there a way that Z3 can produce a model that describes the orders among elements and satisfies all assertions I made?

For example, following are the constraints for "subtype". Is it possible that Z3 may produce a model like "int-type *<* real-type *<* complex-type *<* obj-type *<* root-type" and "string-type *<* obj-type *<* root-type" (if I use "*<*" to denote subtype relation)?

(set-option :produce-models true)
(declare-sort Type)
(declare-fun subtype (Type Type) Bool)

(assert (forall ((x Type)) (subtype x x)))

(assert (forall ((x Type) (y Type))
          (=> (and (subtype x y) (subtype y x)) 
              (= x y))))

(assert (forall ((x Type) (y Type) (z Type))
          (=> (and (subtype x y) (subtype y z)) 
              (subtype x z)))) 

(assert (forall ((x Type) (y Type) (z Type))
          (=> (and (subtype x y) (subtype x z)) 
              (or (subtype y z) (subtype z y)))))               

(declare-const obj-type Type)
(declare-const int-type Type)
(declare-const real-type Type)
(declare-const complex-type Type)
(declare-const string-type Type)


(assert (forall ((x Type)) (subtype x obj-type)))

(assert (subtype int-type real-type))
(assert (subtype real-type complex-type))
(assert (not (subtype string-type real-type)))
(declare-const root-type Type)
(assert (subtype obj-type root-type))


(check-sat)
(get-model)

Currently, I got

sat
(model 
  ;; universe for Type:
  ;;   Type!val!0 Type!val!3 Type!val!2 Type!val!4 Type!val!1 
  ;; -----------
  ;; definitions for universe elements:
  (declare-fun Type!val!0 () Type)
  (declare-fun Type!val!3 () Type)
  (declare-fun Type!val!2 () Type)
  (declare-fun Type!val!4 () Type)
  (declare-fun Type!val!1 () Type)
  ;; cardinality constraint:
  (forall ((x Type))
          (or (= x Type!val!0)
              (= x Type!val!3)
              (= x Type!val!2)
              (= x Type!val!4)
              (= x Type!val!1)))
  ;; -----------
  (define-fun complex-type () Type
    Type!val!2)
  (define-fun real-type () Type
    Type!val!1)
  (define-fun obj-type () Type
    Type!val!4)
  (define-fun root-type () Type
    Type!val!4)
  (define-fun string-type () Type
    Type!val!3)
  (define-fun int-type () Type
    Type!val!0)
  (define-fun subtype!73 ((x!1 Type) (x!2 Type)) Bool
    (ite (and (= x!1 Type!val!3) (= x!2 Type!val!1)) false
    (ite (and (= x!1 Type!val!2) (= x!2 Type!val!3)) false
    (ite (and (= x!1 Type!val!4) (= x!2 Type!val!1)) false
    (ite (and (= x!1 Type!val!4) (= x!2 Type!val!3)) false
    (ite (and (= x!1 Type!val!2) (= x!2 Type!val!1)) false
    (ite (and (= x!1 Type!val!1) (= x!2 Type!val!3)) false
    (ite (and (= x!1 Type!val!4) (= x!2 Type!val!0)) false
    (ite (and (= x!1 Type!val!4) (= x!2 Type!val!2)) false
    (ite (and (= x!1 Type!val!0) (= x!2 Type!val!3)) false
    (ite (and (= x!1 Type!val!2) (= x!2 Type!val!0)) false
    (ite (and (= x!1 Type!val!1) (= x!2 Type!val!0)) false
    (ite (and (= x!1 Type!val!3) (= x!2 Type!val!0)) false
      true)))))))))))))
  (define-fun k!72 ((x!1 Type)) Type
    (ite (= x!1 Type!val!1) Type!val!1
    (ite (= x!1 Type!val!4) Type!val!4
    (ite (= x!1 Type!val!3) Type!val!3
    (ite (= x!1 Type!val!0) Type!val!0
      Type!val!2)))))
  (define-fun subtype ((x!1 Type) (x!2 Type)) Bool
    (subtype!73 (k!72 x!1) (k!72 x!2)))
)

Thank you in advance for any help you could give.


回答1:


I think that your line

(assert (forall ((x Type)) (subtype x obj-type)))

is wrong.

The correct is

(assert (forall ((x Type)) (subtype x root-type)))  

The possible correct model is obtained here



来源:https://stackoverflow.com/questions/22334501/how-to-produce-the-model-for-partial-orders

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