如何使用smt-lib2获得最大公式?
我想要这样的东西:
(declare-fun x () Int)
(declare-fun y () Int)
(declare-fun z () Int)
(assert (= x 2))
(assert (= y 4))
(assert (= z (max x y))
(check-sat)
(get-model)
(exit)
Run Code Online (Sandbox Code Playgroud)
当然,smtlibv2不知道'max'.那么,怎么做呢?
在Z3中,您可以轻松定义宏max并使用它来获取最多两个值:
(define-fun max ((x Int) (y Int)) Int
(ite (< x y) y x))
Run Code Online (Sandbox Code Playgroud)
max使用未解释的函数进行建模还有另一个技巧,这将有助于与Z3 API一起使用:
(declare-fun max (Int Int) Int)
(assert (forall ((x Int) (y Int))
(= (max x y) (ite (< x y) y x))))
Run Code Online (Sandbox Code Playgroud)
请注意,您必须设置(set-option :macro-finder true),因此Z3能够在检查可满足性时用函数体替换通用量词.