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)
(assert (= x 2))
(assert (= y 4))
(assert (= z (max x y))
(check-sat)
(get-model)
(exit)
Of course, ‘max’ is unknown to smtlibv2.
So, how can this be done?
In Z3, you can easily define a macro
maxand use it for getting maximum of two values:There is another trick to model
maxusing uninterpreted functions, which will be helpful to use with Z3 API: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.