Datatypes with functions as attributes in Z3 Python

512 views Asked by At

I am using the Python bindings for Z3, and trying to create a Z3 datatype whose attributes are functions. For example, I might execute the following:

Foo = Datatype('Foo')
Foo.declare('foo', [('my_function', Function('f', IntSort(), BoolSort()))])
Foo.create()

This is an attempt to create a datatype Foo with attribute my_function, where I would be able to call my_function x (if x is a variable of type Foo) in order to get out some function from ints to bools.

However, I run into the following error at the second line:

z3types.Z3Exception: Valid list of accessors expected. An accessor is a pair of the form (String, Datatype|Sort)

Is it possible to declare Z3 datatypes with functions as attributes, perhaps using a different syntax?

Or is it something that is not allowed? The post function declaration in z3 suggests to me that higher-order functions are not allowed in Z3, so perhaps adding a function to a datatype is disallowed so as to prevent the creation of higher-order functions using those datatypes.

1

There are 1 answers

0
Nikolaj Bjorner On BEST ANSWER

You can use the Array type to encode function spaces.

Foo = Datatype('Foo')
Foo.declare('foo', ('my_function', ArraySort(IntSort(), BoolSort())))
print Foo.create()