Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Z3 转换不同宽度的浮点数_Z3 - Fatal编程技术网

Z3 转换不同宽度的浮点数

Z3 转换不同宽度的浮点数,z3,Z3,我想通过给z3一个断言来比较两种不同宽度的浮点数。 例如,我想比较IEEE 32位和IEEE 64位浮点数 我的尝试如下所示: (set-logic QF_FPA) (set-option :produce-models true) (declare-fun x_64 () (_ FP 11 53)) (declare-fun x_32 () (_ FP 8 24)) (assert (== ((_ asFloat 11 53) roundNearestTiesToEven x_64 ) x_6

我想通过给z3一个断言来比较两种不同宽度的浮点数。 例如,我想比较IEEE 32位和IEEE 64位浮点数

我的尝试如下所示:

(set-logic QF_FPA)
(set-option :produce-models true)
(declare-fun x_64 () (_ FP 11 53))
(declare-fun x_32 () (_ FP 8 24))
(assert (== ((_ asFloat 11 53) roundNearestTiesToEven x_64 ) x_64))
(check-sat)
但我收到一条错误信息:

(错误“第5行第59列:排序不匹配”)

比较32位和64位数字的正确方法是什么


我使用的z3版本是4.3.1(linux版本)

一般来说,这些转换是非常重要的,例如,当从64位转换到32位时,一些精度可能会丢失。这就是转换函数采用舍入模式的原因。浮点数的SMT标准包含以下类型的转换函数:

; from another floating point sort
((_ to_fp eb sb) RoundingMode (_ FloatingPoint m n) (_ FloatingPoint eb sb))
因此,在浮点数之间转换的正确方法是使用to_fp函数。[以前,asFloat函数也有此用途;使用最新的不稳定版本Z3时,我没有发现错误。]完整示例如下:

(set-logic QF_FPA)
(set-option :produce-models true)
(declare-fun x_64 () (_ FP 11 53))
(declare-fun x_32 () (_ FP 8 24))
(assert (== ((_ to_fp 11 53) roundNearestTiesToEven x_32) x_64))
(check-sat)
Z3(最新版本)无误接受并立即解决。或者,我们也可以考虑将
x_64
强制转换为32位,在这种情况下,断言如下所示:

(assert (== ((_ to_fp 8 24) roundNearestTiesToEven x_64) x_32))