Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Distinct in z3 SMT and python

Tags:

z3

z3py

My question is that Does "Distinct" works in z3 python?. I've compared the following code and it seem not giving the same results:

(declare-const x Int)
(declare-const y Int)
(assert (distinct x y))
(check-sat)
(get-model)

The result was:

sat

  (model 
  (define-fun y () Int
    0)
  (define-fun x () Int
    1)
  )

I've added negative assertion just to test and the result was unsat which is correct:

(assert (= x y))

unsat
Z3(6, 10): ERROR: model is not available

But when I use z3 in python it give me always sat as follows:

x = Int('x')
y = Int('y')
Distinct(x, y)
s = Solver
s = Solver() 
s.check()

when I add the following assertion It should give me unsat but It returns sat:

s.add(x == y)
[y = 0, x = 0]

Is this means that I used wrong syntax ?

like image 215
Moody Avatar asked Nov 16 '25 09:11

Moody


1 Answers

The `Distinct' function only creates a term, it doesn't add itself to the solver. Here's an example that works for me:

x = Int('x')
y = Int('y')
d = Distinct(x, y)

s = Solver()
s.add(d) # SAT without this one, UNSAT with
s.add(x == y)
print s
print s.check()
like image 83
Christoph Wintersteiger Avatar answered Nov 18 '25 21:11

Christoph Wintersteiger