[英]Sort-parametric wrapper functions
Assuming the use of several built-in and user defined Z3 sorts, eg Int, Bool, S1, S2, ..., is there a way of writing a generic sort-wrapping and -unwrapping function that kind of casts from sort A to sort B and back? 假设使用了几个内置和用户定义的Z3排序,例如Int,Bool,S1,S2,...,有没有一种方法可以编写一个通用的排序包装和 - 包装函数,从排序A转换为排序B然后回来? For example
例如
(declare-const a S1)
(declare-const b S2)
(declare-const c Int)
(WRAP[S1] b) ; Expression is of sort S1
(WRAP[S1] c) ; Expression is of sort S1
(WRAP[Int] (WRAP[S1] c)) ; Expression is of sort Int
I currently cover each case manually, eg 我目前手动覆盖每个案例,例如
(declare-fun $boolToInt (Bool) Int)
(declare-fun $intToBool (Int) Bool)
(assert (forall ((x Int))
(= x ($boolToInt($intToBool x)))))
(assert (forall ((x Bool))
(= x ($intToBool($boolToInt x)))))
Such wrappers could be created automatically from a given set of sorts, but I would prefer a generic solution of possible. 这样的包装器可以从给定的一组排序中自动创建,但我更喜欢可能的通用解决方案。
You can use datatypes to encode "union types". 您可以使用数据类型来编码“联合类型”。 Here is an example:
这是一个例子:
(declare-sort S1)
(declare-sort S2)
(declare-datatypes () ((S1-S2-Int (WRAP-S1 (S1-Value S1))
(WRAP-S2 (S2-Value S2))
(WRAP-Int (Int-Value Int)))))
(declare-const a S1)
(declare-const b S2)
(declare-const c Int)
(simplify (WRAP-S1 a))
(simplify (= (WRAP-S1 a) (WRAP-Int 10)))
(simplify (S1-Value (WRAP-S1 a)))
(simplify (is-WRAP-S2 (WRAP-S1 a)))
(simplify (is-WRAP-S1 (WRAP-S1 a)))
(simplify (is-WRAP-Int (WRAP-Int c)))
(simplify (S1-Value (WRAP-S2 b)))
You can find more information about datatypes in the Z3 guide . 您可以在Z3指南中找到有关数据类型的更多信息。 The datatype
S1-S2-Int
has three constructors: WRAP-S1
, WRAP-S2
and WRAP-Int
. 数据类型
S1-S2-Int
有三个构造函数: WRAP-S1
, WRAP-S2
和WRAP-Int
。 Z3 automatically generates the recognizer predicates: is-WRAP-S1
, is-WRAP-S2
and is-WRAP-Int
. Z3自动生成识别器谓词:
is-WRAP-S1
, is-WRAP-S2
和is-WRAP-Int
。 The accessors S1-Value
, S2-Value
and Int-Value
are used to "deconstruct" a S1-S2-Int
value. 访问器
S1-Value
, S2-Value
和Int-Value
用于“解构” S1-S2-Int
值。 For example, for all a
, (S1-Value (WRAP-S1 a)) = a
. 例如,对于所有
a
, (S1-Value (WRAP-S1 a)) = a
。 The value of (S1-Value (WRAP-S2 b))
is underspecified. (S1-Value (WRAP-S2 b))
值未指定。 In this case, Z3 treats S1-Value
as a uninterpreted function. 在这种情况下,Z3将
S1-Value
视为未解释的函数。
BTW, the axiom 顺便说一下,公理
(assert (forall ((x Int))
(= x ($boolToInt($intToBool x)))))
is equivalent to false. 相当于假。 It is essentially trying to inject the integers into the Booleans.
它本质上是试图将整数注入布尔值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.