是否可以在 smtlib 中声明函数排序?

Is it possible to declare a function sort in smtlib?

例如,

$ z3 -in
(declare-fun f (Int Real) Int)
(assert (= f f))
(check-sat)
sat

没关系。

但是,我想通过 as?

来限定它
$ z3 -in
(declare-fun f (Int Real) Int)
(assert (= (as f ???) (as f ???)))
(check-sat)
sat

我应该填写什么???

必须是排序,但我应该使用什么排序?

我试过 ((Int Real) Int)(-> (Int Real) Int)(_ (Int Real) Int),但其中 none 个是正确的。

是否可以在 smtlib 中声明函数排序?

如果无法声明函数排序,如何在以下程序中消除歧义f

$ z3 -in
(declare-fun f (Int Real) Real)
(declare-fun f (Int Bool) Real)
(assert (= f f))
(error "line 3 column 11: ambiguous constant reference, more than one constant with the same sort, use a qualified expression (as <symbol> <sort>) to disambigua
te f")

注意如果我不用函数也没问题:

$ z3 -in
(declare-fun f () Int)
(assert (= (as f Int) (as f Int)))
(check-sat)
sat

谢谢。

注解

(as f Int)

是正确的,尽管(如您所见)非常混乱。此注释 并非 必然意味着 fInt。相反,它意味着 f 结果是 Int,因此它也可以是一个函数。

这确实很混乱,但它遵循标准 http://smtlib.cs.uiowa.edu/papers/smt-lib-reference-v2.6-r2021-05-12.pdf,第 27 页:

Recall that every function symbol f is separately associated with one or more ranks, each specifying the sorts of f ’s arguments and result. To simplify sort checking, a function symbol in a term can be annotated with one of its result sorts σ. Such an annotated function symbol is a qualified identifier of the form (as f σ).

如上文(as f σ)所示,类型σf的结果排序

另请注意,求解器对这些注释的支持相当不一致。有关之前对此的讨论,请参阅 https://github.com/Z3Prover/z3/issues/2135