Skip to content

Question(z3py ,Array,SMT): 3 Dimention Array as the other Array's Index #5247

Answered by aytey
allen0917-user asked this question in Q&A
Discussion options

You must be logged in to vote

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:

[three = K(Int, K(Int, K(Int, 3))),
 two = K(Int, K(Int, 2)),
 one = K(Int, 1)]

(K is for "constant array")

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
1 reply
@aytey
Comment options

Answer selected by allen0917-user
Comment options

You must be logged in to vote
4 replies
@allen0917-user
Comment options

@aytey
Comment options

@aytey
Comment options

@allen0917-user
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants