Question(z3py ,Array,SMT): 3 Dimention Array as the other Array's Index #5247
-
Hi , I'm a z3 beginner from Taiwan. And I'm trying to implement some constrants (SMT problems )with 2d and 3d arrays,some thing like this: ∀k∈[1,2,3]:∀i∈[1,2,3]:∀j∈[1,2,3] #constraint(2) And here is what I'm trying to do:
And It seems that i need to declare two of the array with z3 variable, so that i can use them as variables of my constraint.
but i don't know how to implement 3 dimention array with "z3 variable" I want to know how can i implement "3 dimention array" with z3 variable?and as index of the other array? Any help , I'll be very appreciate! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
How about this: from z3 import *
s = Solver()
one_dimension_sort = ArraySort(IntSort(), IntSort())
two_dimension_sort = ArraySort(IntSort(), one_dimension_sort)
three_dimension_sort = ArraySort(IntSort(), two_dimension_sort)
one_dimension_array = Const("one", one_dimension_sort)
two_dimension_array = Const("two", two_dimension_sort)
three_dimension_array = Const("three", three_dimension_sort)
s.add(one_dimension_array[1] == 1)
s.add(two_dimension_array[1][1] == 2)
s.add(three_dimension_array[1][1][1] == 3)
assert s.check() == sat
print(s.model())
# EOF which gives:
( |
Beta Was this translation helpful? Give feedback.
-
Thanks for your reply , i want to restrict 3darray[k][i][j] in 1~2 |
Beta Was this translation helpful? Give feedback.
How about this:
which gives:
(
K
is for "constant array")