Helper class for declaring Z3 datatypes.
>>> List = Datatype('List')
>>> List.declare('cons', ('car', IntSort()), ('cdr', List))
>>> List.declare('nil')
>>> List = List.create()
>>> # List is now a Z3 declaration
>>> List.nil
nil
>>> List.cons(10, List.nil)
cons(10, nil)
>>> List.cons(10, List.nil).sort()
List
>>> cons = List.cons
>>> nil = List.nil
>>> car = List.car
>>> cdr = List.cdr
>>> n = cons(1, cons(0, nil))
>>> n
cons(1, cons(0, nil))
>>> simplify(cdr(n))
cons(0, nil)
>>> simplify(car(n))
1
Definition at line 4379 of file z3py.py.
Create a Z3 datatype based on the constructors declared using the mehtod `declare()`.
The function `CreateDatatypes()` must be used to define mutually recursive datatypes.
>>> List = Datatype('List')
>>> List.declare('cons', ('car', IntSort()), ('cdr', List))
>>> List.declare('nil')
>>> List = List.create()
>>> List.nil
nil
>>> List.cons(10, List.nil)
cons(10, nil)
Definition at line 4445 of file z3py.py.
Referenced by Datatype.declare().
4446 """Create a Z3 datatype based on the constructors declared using the mehtod `declare()`. 4448 The function `CreateDatatypes()` must be used to define mutually recursive datatypes. 4450 >>> List = Datatype('List') 4451 >>> List.declare('cons', ('car', IntSort()), ('cdr', List)) 4452 >>> List.declare('nil') 4453 >>> List = List.create() 4456 >>> List.cons(10, List.nil)
def declare |
( |
|
self, |
|
|
|
name, |
|
|
|
args |
|
) |
| |
Declare constructor named `name` with the given accessors `args`.
Each accessor is a pair `(name, sort)`, where `name` is a string and `sort` a Z3 sort or a reference to the datatypes being declared.
In the followin example `List.declare('cons', ('car', IntSort()), ('cdr', List))`
declares the constructor named `cons` that builds a new List using an integer and a List.
It also declares the accessors `car` and `cdr`. The accessor `car` extracts the integer of a `cons` cell,
and `cdr` the list of a `cons` cell. After all constructors were declared, we use the method create() to create
the actual datatype in Z3.
>>> List = Datatype('List')
>>> List.declare('cons', ('car', IntSort()), ('cdr', List))
>>> List.declare('nil')
>>> List = List.create()
Definition at line 4422 of file z3py.py.
Referenced by Datatype.create().
4422 def declare(self, name, *args):
4423 """Declare constructor named `name` with the given accessors `args`. 4424 Each accessor is a pair `(name, sort)`, where `name` is a string and `sort` a Z3 sort or a reference to the datatypes being declared. 4426 In the followin example `List.declare('cons', ('car', IntSort()), ('cdr', List))` 4427 declares the constructor named `cons` that builds a new List using an integer and a List. 4428 It also declares the accessors `car` and `cdr`. The accessor `car` extracts the integer of a `cons` cell, 4429 and `cdr` the list of a `cons` cell. After all constructors were declared, we use the method create() to create 4430 the actual datatype in Z3. 4432 >>> List = Datatype('List') 4433 >>> List.declare('cons', ('car', IntSort()), ('cdr', List)) 4434 >>> List.declare('nil') 4435 >>> List = List.create() 4438 _z3_assert(isinstance(name, str),
"String expected")
4439 _z3_assert(name !=
"",
"Constructor name cannot be empty")
4440 return self.declare_core(name,
"is_" + name, *args)