3

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 ?

Moody
  • 137
  • 1
  • 9

1 Answers1

7

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()
Christoph Wintersteiger
  • 8,234
  • 1
  • 16
  • 30