function declaration in z3

五迷三道 提交于 2019-12-21 05:44:20

问题


In z3 is it possible to declare a function that takes another function as an argument? For instance, this

(declare-fun foo ( ((Int) Bool) ) Int)

doesn't quite seem to work. Thanks.


回答1:


As Leonardo mentioned, SMT-Lib does not allow higher-order functions. This is not merely a syntactic restriction: Reasoning with higher-order functions is (generally) beyond what SMT solvers can deal with. (Although uninterpreted functions can be used in some special cases.)

If you do need to reason with higher-order functions, then interactive theorem provers are the main weapon of choice: Isabelle, HOL, Coq being some of the examples.

However, sometimes you want the higher-order functions not to reason about them, but rather merely to simplify programming tasks. SMT-Lib input language is not suitable for high-level programming that end-users typically need in practical situations. If that is your use case, then I'd recommend not using SMT-Lib directly, but rather working with a programming language that gives you access to Z3 (or other SMT solvers). There are several choices, depending on what host language is most suitable for your use case:

  • If you are a Python user, Z3Py that just shipped with Z3 4.0 is the way to go,
  • If you are a Scala user, then look into Scala^Z3.
  • If Haskell is your preferred language, then take a look at SBV.

Each binding has its own feature set, Z3Py probably being the most versatile since it's directly supported by the Z3 folks. (It also provides access to Z3 internals that remain inaccessible for the other choices, at least for the time being.)




回答2:


No, this is not possible. However, you can define a function that takes an array as an argument.

(declare-fun foo ((Array Int Bool)) Int)

You can use this trick to simulate high-order functions like the one in your question.

Here is an example: http://rise4fun.com/Z3/qsED

The Z3 guide contains more information about Z3 and SMT.



来源:https://stackoverflow.com/questions/10567391/function-declaration-in-z3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!