Z3:将int转换为bitvector [英] Z3: Covert int sort into bitvector
问题描述
:变量x定义为int排序
(declare-const x Int)
:A variable x is defined as an int sort by (declare-const x Int)
是否有任何方法可以将x转换为bitvector排序?因为有时x涉及int理论无法处理的位操作,如&,|,^。
Is there any method to convert the x into a bitvector sort? Because sometimes x involves bit operations such as &, |, ^ that int theory cannot handle.
我不想在开始时将变量x定义为位向量因为我认为除了位操作之外,int理论支持的操作(例如+, - ,*,/)比bitvectors支持的操作运行得快得多。
I do not want to define the variable x as a bitvector in the beginning because I suppose the operations (e.g., +, -, *, /) supported by int theory except bit operations run much faster than those operations supported in bitvectors.
所以实际上,我想将int sort转换为bitvector sort或vise vesa in demand。
So actually, I want to covert int sort into bitvector sort or vise vesa in demand.
谢谢。
陈婷
推荐答案
是的,您可以使用 bv2int
和<$ c之类的东西$ C> int2bv 。请注意,位向量长度很重要,int2bv是参数化的(需要位向量长度)。
Yes, you can use things like bv2int
and int2bv
. Note the bitvector length matters and that int2bv is parametric (requires the bitvector length).
这是一个最小的例子(rise4fun链接: http://rise4fun.com/Z3/wxcp ):
Here is a minimal example (rise4fun link: http://rise4fun.com/Z3/wxcp ):
(declare-fun x () (_ BitVec 32))
(declare-fun y () Int)
(declare-fun z () (_ BitVec 16))
(assert (= y 129))
(assert (= (bv2int x) y))
; (assert (= ((_ int2bv 32) y) x)) ; try with this uncommented
(assert (= ((_ int2bv 16) y) z))
(check-sat)
(get-model)
(get-value (x y z)) ; gives ((x #x00000000) (y 129) (z #x0081))
另一个例子是这里:
目前看来这些功能可能存在一些问题:使用Z3检查溢出
It looks like there may be some issues with these functions currently: Check overflow with Z3
在其他解算器中也可以使用不同的名称调用这些名称( bv2nat
和 nat2bv
): http://smtlib.cs.uiowa.edu/theories/FixedSizeBitVectors.smt2
These may also be called by different names in other solvers (bv2nat
and nat2bv
): http://smtlib.cs.uiowa.edu/theories/FixedSizeBitVectors.smt2
这篇关于Z3:将int转换为bitvector的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!