I have been unable to print/display a set object returned as part of a Z3 model. Consider the following example (in F#):
let ctx:Context = new Context()
let ASort = ctx.MkEnumSort("S",[| "A"; "B"; "C"|])
let ASetSort = ctx.MkSetSort(ASort)
let xs = ctx.MkConst("xs",ASetSort)
let p = mkPredDecl ctx ("p",[|ASetSort|])
let px = ctx.MkApp(p,xs) :?> BoolExpr
let s = ctx.MkSolver()
s.Assert (ctx.MkAnd(px, ctx.MkNot(ctx.MkEq(xs,ctx.MkEmptySet(ASort)))))
assert (s.Check() = Status.SATISFIABLE)
let xs_interp = s.Model.Eval(xs)
xs_interp
The solver returns a set (in this case a singleton set {A} but it doesnt matter). I couldn't see any way of actually printing it out. The standard ToString()
method simply says its an array and displaying the model shows that the set is internally represented using a query function. I tried the following
let foo xs x =
let mem= ctx.MkSetMembership(x,xs_interp) :?> BoolExpr
s.Assert mem
s.Check()= Status.SATISFIABLE
Array.filter (foo xs) ASort.Consts
Not only is it clunky but it doesnt work! I suppose I could walk over the query function representation of the set but that doesnt seem so good to me if the representation of sets in Z3 changes it would break my code. Is there something in the API i am missing? Could the ToString() method be perhaps modified to actually print the set contents?