Why does Z3 return unknown for this nonlinear inte

2019-08-14 17:16发布

问题:

I have a simple example in nonlinear integer arithmetic, namely a search for Pythagorean triples. Based on what I read in related questions (see below), I'd expect Z3 to find a solution to this problem, but it returns 'unknown'. Here is the example in SMT-LIB v2:

(declare-fun x () Int)
(declare-fun y () Int)
(declare-fun z () Int)
(declare-fun xSquared () Int)
(declare-fun ySquared () Int)
(declare-fun zSquared () Int)
(declare-fun xSquaredPlusYSquared () Int)

(assert (= xSquared (* x x)))
(assert (= ySquared (* y y)))
(assert (= zSquared (* z z)))
(assert (= xSquaredPlusYSquared (+ xSquared ySquared)))

(assert (and (> x 0) (> y 0) (> z 0) (= xSquaredPlusYSquared zSquared)))

(check-sat)

(exit)

There are a few related questions, most notably:

  • How does Z3 handle non-linear integer arithmetic?

  • Need help understanding the equation

  • Combining nonlinear Real with linear Int

  • Z3 support for nonlinear arithmetic

  • z3 limitations in handling nonlinear real arithmetics

回答1:

It seems that Z3 won't attempt finding a solution by bit-blasting unless variables have a finite range. Replacing (check-sat) with the following command will find the solution:

(check-sat-using (then (using-params add-bounds :add-bound-lower -100 :add-bound-upper 100) smt))

Alternatively, one can add assert statements forcing each variable to have some finite range.



标签: z3 smt