使用Yices计算归纳数据类型的简单示例是:
(define-type T (datatype c1
c2
(c3 val::bool)))
(define x1::T)
(define x2::T)
(assert (/= x1 x2))
(check)
,相应的输出是:
sat
(= x1 c1)
(= (c3 false) x2)
使用以下代码
使用Z3-SMT-LIB解决此示例(declare-datatypes () ((T c1 ( c3 (T Bool)))))
(declare-fun x1 () T)
(declare-fun x2 () T)
(assert (not (= x2 x1)))
(check-sat)
(get-model)
,相应的输出是
sat
(model
(define-fun x2 () T (c3 false))
(define-fun x1 () T c1)
)
在线here
运行此示例观察到Yices和Z3产生相同的结果。
其他例子:
Yices:
(define-type T (datatype c1
c2
(c3 val::bool)))
(define x1::T)
(define x2::T)
(define x3::T)
(define x4::T)
(assert (/= x1 x2))
(assert (/= x1 x3))
(assert (/= x1 x4))
(assert (/= x2 x3))
(assert (/= x2 x4))
(assert (/= x3 x4))
(check)
sat
(= x1 c1)
(= x3 c2)
(= (c3 false) x4)
(= (c3 true) x2)
Z3:
(declare-datatypes () ((T c1 c2 ( c3 (T Bool)))))
(declare-fun x1 () T)
(declare-fun x2 () T)
(declare-fun x3 () T)
(declare-fun x4 () T)
(assert (not (= x4 x3)))
(assert (not (= x4 x2)))
(assert (not (= x4 x1)))
(assert (not (= x3 x2)))
(assert (not (= x3 x1)))
(assert (not (= x2 x1)))
(check-sat)
(get-model)
sat
(model
(define-fun x3 () T c2)
(define-fun x2 () T (c3 false))
(define-fun x1 () T c1)
(define-fun x4 () T (c3 true))
)
在线here
运行此示例在本例中观察到Yices和Z3产生不同的结果。
其他例子:自然数作为归纳型:
Yices
(define-type Nat (datatype zero
(succ val::Nat)))
(define x1::Nat)
(define x2::Nat)
(define x3::Nat)
(assert (/= x1 x2))
(assert (/= x1 x3))
(assert (/= x2 x3))
(check)
sat
(= zero x1)
(= (succ x2) x3)
(= (succ x1) x2)
Z3
(declare-datatypes () ((Nat zero (succ (Nat Nat)))))
(declare-fun x1 () Nat)
(declare-fun x2 () Nat)
(declare-fun x3 () Nat)
(assert (not (= x1 x2)))
(assert (not (= x1 x3)))
(assert (not (= x2 x3)))
(check-sat)
(get-model)
sat
(model
(define-fun x3 () Nat (succ (succ (succ zero))))
(define-fun x2 () Nat (succ zero))
(define-fun x1 () Nat zero)
)
在线here
运行此示例在本例中观察到Yices和Z3产生不同的结果。
问题是;
如何编写Z3代码,目的是获得与Yices相同的结果。
如何使用Z3和Yices获得所有可能的模型。
答案 0 :(得分:1)
您的示例包含无数个模型。 Z3和Yices产生不同的模型,但两者产生的解决方案都是正确的。
Z3和Yices对归纳数据类型使用略有不同的决策过程。这就是他们生产不同型号的原因。没有办法强制它们总是为具有多个模型的输入断言集生成相同的解决方案。
关于枚举所有可能的模型,我们可以使用Z3 API。看这篇文章: