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

前端 未结 2 1716
情深已故
情深已故 2021-01-06 06:41

How do I get the maximum of a formula using smt-lib2?

I want something like this:

(declare-fun x () Int)
(declare-fun y () Int)
(declare-fun z () Int         


        
相关标签:
2条回答
  • 2021-01-06 06:53

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

    0 讨论(0)
  • 2021-01-06 07:04

    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.

    0 讨论(0)
提交回复
热议问题