如何生成部分阶数的模型



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

例如,以下是"subtype"的约束。Z3是否可能产生类似于"int-type *<* real-type *<* complex-type *<* obj-type *<*根类型"one_answers"string-type *<* obj-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)))
)

对于您所能给予的帮助,我提前表示感谢。

我觉得你的台词

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

是错误的。

正确的是

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

这里得到了可能正确的模型

相关内容

  • 没有找到相关文章

最新更新