I have managed to create an Array of Records using Z3 but now am struggling to see the syntax I need to perform a $\forall$ operation on the Array... here is a snippet sample of the SMT-LIB2 code i have so far.
(declare-datatypes () ((rec (mk-R5 (age Int) (area Int) (married Bool)))))
(declare-const recs (Array Int rec))
(declare-const r1 rec)
(assert(= (age r1) 15))
(assert(= (area r1) 10001))
(assert(= (married r1) true))
(declare-const r2 rec)
(assert(= (age r2) 35))
(assert(= (area r2) 2845))
(assert(= (married r2) true))
(declare-const x Int)
(declare-const y Int)
(assert (= recs (store recs x r1)))
(assert (= recs (store recs y r2)))
(assert(forall ((i rec)) (= (married i) true)))
(check-sat)
(get-model)
I guess the third-last line should have some reference to the Array but I've tried everything and the tutorial did not help me with this problem.
How do I perform a $\forall$ operation over the Array I have here?
It appears you are trying to put two records in an array, and then say something about those elements. Unfortunately, your encoding doesn't quite mean that.
The first thing to notice is the meaning of the following line:
This says that
recs
is an array indexed by all integers. That is, the domain is the set of all Int values. This is probably not what you meant.Also, the lines:
are better written like this:
Think of it as saying what you know about index
x
andy
; as opposed to some imperative assignment statements to "modify"recs
as you tried to write. There is no notion of modifying any values in smt-lib; you simply state what you know is true about the model you are building.One way to fix your forall-assertion would be to write it like this:
We quantify over the indices, and say that if the index is
i
ory
, then those records havemarried
people. With these modifications, Z3 responds:which is a bit hard to read, but it does give you a model as you specified.
It seems to me, however, that this wasn't really what you were trying to model; but it's hard to tell from your question. If you describe actual problem you are trying to solve, the answers might be more helpful.