Use Z3 and SMT-LIB to get a maximum of two values

泄露秘密 提交于 2019-11-30 23:19:46

In Z3, you can easily define a macro max and use it for getting maximum of two values:

(define-fun max ((x Int) (y Int)) Int
  (ite (< x y) y x))

There is another trick to model max using uninterpreted functions, which will be helpful to use with Z3 API:

(declare-fun max (Int Int) Int)
(assert (forall ((x Int) (y Int))
    (= (max x y) (ite (< x y) y x))))

Note that you have to set (set-option :macro-finder true), so Z3 is able to replace universal quantifiers with body of the function when checking satisfiability.

You've got abs, and per basic math max(a,b) = (a+b+abs(a-b))/2

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