在Z3 Python API中从sort创建常量

时间:2014-10-13 19:18:12

标签: python z3 z3py

给定一个Z3排序和一个字符串s我试图创建一个名为s的Z3常量。

例如,给定IntSort()和名称"x"我想得到一个名为"x"的整数常量。

我知道我可以调用Int('x')但是因为我动态创建了这个变量,所以我无法预测给定变量的类型。我要做的是创建一个与系统提供的变量相同但具有新名称的变量(我必须能够在运行时指定)。

更具体地说,

1. I get a model for a user defined formula calling the Z3 Solver on it, 
2. I save it in a database (recording for each assignment in such a model the variable name, the value to be assigned to it and the sort of that variable)
3. I retrieve that assignment after a while from the database and I try it o a new formula having the same variables of the original one. 

为了做到这一点,我将每个作业转换为var == value形式的一个子句,我将它们与目标公式一起添加到求解器中,并检查是否具有可满足性。

到目前为止,我只使用整数排序,所以我使用Int函数硬编码了字符串到常量的转换。现在我试图将方法概括为不同的逻辑和不同的数据类型,因此我需要一些东西来创建我在数据库中保存的正常常量。

您认为这种方法合理吗?你觉得有什么办法可以做得更好吗?

1 个答案:

答案 0 :(得分:2)

听起来你想要使用' Const'功能。 例如:

A = DeclareSort('A')
a = Const('a', A)