I tried to realize something in smtlib like a union in C:
union IntBoolType
{
int i;
boolean b;
} x;
My achievement so far:
(declare-datatypes (Int) ((IntPart INone (part (i Int)))))
(declare-datatypes (Bool) ((BoolPart BNone (part (b Bool)))))
(declare-datatypes () ((IntBoolType (mk (ipart (IntPart Int))
(bpart (BoolPart Bool))))))
The idea is, that IntBoolType
should contain either an int or (xor) a boolean value. To denote "None" I introduced the two fields on the sub-datatypes.
I declared a couple of constants of type IntBoolType
(ibt1
to ibt10
) and now I wanted to define assertions to support these requirements:
(assert (distinct ibt1 ibt2 ibt3 ... ibt10)
(assert (xor (= (ipart ibt1) INone) (= (bpart ibt1) BNone)))
The second assertion is necessary, because otherwise I got one solution with INone
and BNone
.
However, now z3 prints outputs which contains both integers and boolean values. Did I miss something? Is there a smarter way to encode this problem?