Z3:如何在Z3 python中对If-the-else进行编码?

时间:2013-04-12 09:45:04

标签: python z3

我想在Z3 python中对If-the-else进行编码,但找不到任何关于如何操作的文档或示例。

我有一个示例代码,如下所示。

F = True
tmp = BitVec('tmp', 1)
tmp1 = BitVec('tmp1', 8)

现在如何将此条件编码为F:

if tmp == 1, then tmp1 == 100. otherwise, tmp1 == 0 

非常感谢。

2 个答案:

答案 0 :(得分:6)

你需要Z3的If功能:

def z3py.If   (       a,
          b,
          c,
          ctx = None 
  )   
     

创建一个Z3 if-then-else表达式。

>>> x = Int('x')
>>> y = Int('y')
>>> max = If(x > y, x, y)
>>> max
If(x > y, x, y)
>>> simplify(max)
If(x <= y, y, x)

(来自here

答案 1 :(得分:4)

您可以使用IfIf有三个参数:条件,如果条件为真,则表达式应为true;如果条件为false,则表达式应为true。所以为了表达你的逻辑,你会写:

If(tmp==1, tmp1==100, tmp1==0)