【发布时间】:2021-10-19 22:35:19
【问题描述】:
我对 smtlib 中的 declare-const 有疑问。
例如,
在z3/cvc4中,以下程序不报错:
C:\Users\Chansey>z3 -in
(declare-const x Int)
(declare-const x Bool)
在 smt-lib-reference 中,它说
(declare-fun f (s1 ... sn) s) ... 如果当前签名中已经存在名称为 f 的函数符号,该命令将报告错误。
所以s这个排序包含在x的整个签名中,对吗?
但是为什么会这样呢?背后的动机是什么?
据我了解,x 是变量标识符,通常(例如在某些通用编程语言中)我们不允许使用不同类型声明相同的变量。所以我觉得上面的代码最好报错。
我曾经想过也许z3/smtlib可以支持重定义?,但不是……
C:\Users\Chansey>z3 -in
(declare-const x Int)
(declare-const x Bool)
(assert (= x true))
(error "line 3 column 11: ambiguous constant reference, more than one constant with the same sort, use a qualified expre
ssion (as <symbol> <sort>) to disambiguate x")
那么上面的代码肯定是错的,为什么不早点报错呢?
PS。如果我用同样的排序,那么会报错(太好了,希望Bool的情况也能报错):
C:\Users\Chansey>z3 -in
(declare-fun x () Int)
(declare-fun x () Int)
(error "line 2 column 21: invalid declaration, constant 'x' (with the given signature) already declared")
谢谢。
【问题讨论】: