Question

How can I access the values of parameterized sorts?

For instance, if I have the following declarations:

(declare-sort Pair 2)
(declare-const x (Pair Int Int))

How do I access the first element in the pair which x represents?

Was it helpful?

Solution

You can create a parametric record with two selectors first and second for accessing its field.

Here is an example:

(declare-datatypes (T1 T2) ((Pair (mk-pair (first T1) (second T2)))))
(declare-const p1 (Pair Bool Int))
(declare-const p2 (Pair Int Int))
(assert (first p1))
(assert (> (first p2) 2))
(assert (= (second p1) (second p2)))
(check-sat)
(get-model)

There is also a comprehensive introduction on algebraic datatypes in Z3 SMT guide.

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