我试图在smtlib中实现某些东西,比如C中的联合:
union IntBoolType
{
int i;
boolean b;
} x;
到目前为止我的成就:
(declare-datatypes (Int) ((IntPart INone (part (i Int)))))
(declare-datatypes (Bool) ((BoolPart BNone (part (b Bool)))))
(declare-datatypes () ((IntBoolType (mk (ipart (IntPart Int))
(bpart (BoolPart Bool))))))
这个想法是,IntBoolType
应该包含一个int或(xor)一个布尔值。表示"无"我在子数据类型上介绍了两个字段。
我声明了几个类型IntBoolType
(ibt1
到ibt10
)的常量,现在我想定义断言来支持这些要求:
(assert (distinct ibt1 ibt2 ibt3 ... ibt10)
(assert (xor (= (ipart ibt1) INone) (= (bpart ibt1) BNone)))
第二个断言是必要的,因为否则我得到了一个INone
和BNone
的解决方案。
但是,现在z3打印的输出包含整数和布尔值。我错过了什么?有没有更聪明的方法来编码这个问题?
答案 0 :(得分:0)
备份一秒钟,考虑您创建的相应ML类型。
type intpart = int option
type boolpart = bool option
type intbooltype = Mk of intpart * boolpart
它始终是一对选项。我猜你想要的是:
type ('a,'b) either = Left of 'a | Right of 'b
在CVC4和z3支持的数据类型扩展中编写它的方法是:
(declare-datatypes (U T) ((Either (Left (left U))
(Right (right T)))))
(注意这与C联盟不同,但这是另一个故事。)