Question

This question is strongly related to this and this question.

The distinct function of Z3

(declare-const a S)
(declare-const b S)
(assert (distinct a b))

allows constraining sets of variables (here a and b) such that all variables in the set must take different values.

My question is: is it also possible to force a variable to take a unique value without explicitly referring to the set of variables from which it should be distinct? Something like

(declare-unique-const a S)
(declare-unique-const b S)
(declare-unique-const c S)

This would be nice in situations where you declare new variables in an iterative process, for example, during program verification.

If it is not possible, I guess one has to keep track of all distinct variables and use that set to emit appropriate distinct (newvar, oldvar1, ..., oldvarn)) constraints.

Was it helpful?

Solution

We can define an auxiliary fresh function f from S to Int, and assert

f(a_1) = 1
f(a_1) = 2
f(a_3) = 3
...
f(a_n) = n

Then, a_1, ..., a_n must be different from each other. If we want to say that b is also different from all a_is. We just assert

f(b) = n+1

In this approach, we only have to track the counter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top