2

我正在尝试使用 Z3 为一组描述偏序理论的 SAT 断言生成模型。我尝试了 Z3 指南中的子类型示例,但似乎无法获得具体模型。有没有一种方法可以让 Z3 生成一个模型来描述元素之间的顺序并满足我所做的所有断言?

例如,以下是“子类型”的约束。Z3 是否有可能产生类似“int-type *<* real-type *<* complex-type *<* obj-type *<* root-type”和“string-type *<* obj-type”的模型*<* root-type”(如果我使用“*<*”来表示子类型关系)?

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

目前,我得到了

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

预先感谢您提供的任何帮助。

4

1 回答 1

0

我认为你的线

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

是错的。

正确的是

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

此处获得可能的正确模型

于 2014-03-12T02:03:25.507 回答