如何在Z3-PY中实现C位运算符?
我希望能够将以下规则应用到我的如何在Z3-PY中实现C位运算符?,c,bitwise-operators,z3,z3py,C,Bitwise Operators,Z3,Z3py,我希望能够将以下规则应用到我的解算器s,其中“^”和“&”运算符是来自C的“或”和“和”。input\u list是一个100元素IntVector: s.add( ((input_list[6] ^ input_list[10]) & 0xF) + ((input_list[3] + input_list[5] - 25) ^ (3*input_list[99])) == 73) 运行此代码会出现类型错误: TypeError: unsupported operand type(s)
解算器
s,其中“^”和“&”运算符是来自C的“或”和“和”。input\u list
是一个100元素IntVector
:
s.add(
((input_list[6] ^ input_list[10]) & 0xF) +
((input_list[3] + input_list[5] - 25) ^ (3*input_list[99])) == 73)
运行此代码会出现类型错误:
TypeError: unsupported operand type(s) for ^: 'ArithRef' and 'ArithRef'
用Z3的布尔运算符替换“^”和“&”,如下所示:
s.add(
(And(Or(input_list[6],input_list[10]),0xF) +
Or((input_list[3] + input_list[5] - 25), (3*input_list[99]))) == 73)
给出此错误:
z3.z3types.Z3Exception: b'Sort mismatch at argument #1 for function (declare-fun or (Bool Bool) Bool) supplied sort is Int'
如何将此操作表示为z3解算器的规则?这里的问题是SMTLib(和z3)中的
Int
类型是一个完整的数学整数。它没有任何“位”,也没有任何方式的限制。也就是说,它不是您可以对其执行位操作的东西。您没有给出实际的完全可执行代码,但下面是一个简单的示例,说明了您遇到的错误:
从z3导入*
x、 y=整数('x y')
s=解算器()
s、 加(x^y==0)
打印(s.check())
打印(s.model())
对于上述代码,我得到:
Traceback (most recent call last):
File "a.py", line 6, in <module>
s.add(x ^ y == 0)
TypeError: unsupported operand type(s) for ^: 'ArithRef' and 'ArithRef'
现在我得到:
sat
[y = 0, x = 0]
您可以在这里阅读更多关于z3中位精度算术的内容:注意,
^
在C中是异或,或者是|