Z3 set default value of array to zero

走远了吗. 提交于 2019-12-10 17:47:55

问题


I am trying to solve models for array expressions, where default values for array is equal to 0.

For example, I am trying to solve this example, but I get unknown results all the time

(declare-const arr (Array Int Int))
(declare-const arr2 (Array Int Int))
(declare-const a Int)
(declare-const b Int)

(assert (forall ((x Int)) (= (select arr x) 0)))

(assert (> a 0))
(assert (<= a 10))

(assert (= arr2 (store arr a 1337)))

(assert (> b 0))
(assert (<= b 10))


(assert (= (select arr2 b) 0))

(check-sat)
(get-model)

回答1:


Patrick's advice on not using quantifiers is spot on! They'll make your life harder. However, you're in luck, because z3 supports constant-arrays for your use case, which is quite common. The syntax is:

(assert (= arr ((as const (Array Int Int)) 0)))

This makes sure arr will have all its entries as 0; no quantification needed and z3 handles it internally just fine.

So, your benchmark will be:

(declare-const arr (Array Int Int))
(declare-const arr2 (Array Int Int))
(declare-const a Int)
(declare-const b Int)

(assert (= arr ((as const (Array Int Int)) 0)))

(assert (> a 0))
(assert (<= a 10))

(assert (= arr2 (store arr a 1337)))

(assert (> b 0))
(assert (<= b 10))


(assert (= (select arr2 b) 0))

(check-sat)
(get-model)

which is solved in no time. This way, you can have the entire array start with 0, and modify the range you're interested in; which can depend on variables as usual and is not required to be known ahead of time.



来源:https://stackoverflow.com/questions/54863754/z3-set-default-value-of-array-to-zero

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!