Z3
Public Member Functions | Data Fields
Datatype Class Reference

Public Member Functions

def __init__
 
def declare_core (self, name, rec_name, args)
 
def declare (self, name, args)
 
def __repr__ (self)
 
def create (self)
 

Data Fields

 ctx
 
 name
 
 constructors
 

Detailed Description

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 4116 of file z3py.py.

Constructor & Destructor Documentation

def __init__ (   self,
  name,
  ctx = None 
)

Definition at line 4142 of file z3py.py.

4142  def __init__(self, name, ctx=None):
4143  self.ctx = _get_ctx(ctx)
4144  self.name = name
4145  self.constructors = []
4146 
def __init__
Definition: z3py.py:4142

Member Function Documentation

def __repr__ (   self)

Definition at line 4174 of file z3py.py.

4174  def __repr__(self):
4175  return "Datatype(%s, %s)" % (self.name, self.constructors)
4176 
def __repr__(self)
Definition: z3py.py:4174
def create (   self)
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 4177 of file z3py.py.

Referenced by Datatype.declare().

4177  def create(self):
4178  """Create a Z3 datatype based on the constructors declared using the mehtod `declare()`.
4179 
4180  The function `CreateDatatypes()` must be used to define mutually recursive datatypes.
4181 
4182  >>> List = Datatype('List')
4183  >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4184  >>> List.declare('nil')
4185  >>> List = List.create()
4186  >>> List.nil
4187  nil
4188  >>> List.cons(10, List.nil)
4189  cons(10, nil)
4190  """
4191  return CreateDatatypes([self])[0]
4192 
def CreateDatatypes(ds)
Definition: z3py.py:4209
def create(self)
Definition: z3py.py:4177
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 4154 of file z3py.py.

Referenced by Datatype.create().

4154  def declare(self, name, *args):
4155  """Declare constructor named `name` with the given accessors `args`.
4156  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.
4157 
4158  In the followin example `List.declare('cons', ('car', IntSort()), ('cdr', List))`
4159  declares the constructor named `cons` that builds a new List using an integer and a List.
4160  It also declares the accessors `car` and `cdr`. The accessor `car` extracts the integer of a `cons` cell,
4161  and `cdr` the list of a `cons` cell. After all constructors were declared, we use the method create() to create
4162  the actual datatype in Z3.
4163 
4164  >>> List = Datatype('List')
4165  >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4166  >>> List.declare('nil')
4167  >>> List = List.create()
4168  """
4169  if __debug__:
4170  _z3_assert(isinstance(name, str), "String expected")
4171  _z3_assert(name != "", "Constructor name cannot be empty")
4172  return self.declare_core(name, "is_" + name, *args)
4173 
def declare(self, name, args)
Definition: z3py.py:4154
def declare_core(self, name, rec_name, args)
Definition: z3py.py:4147
def declare_core (   self,
  name,
  rec_name,
  args 
)

Definition at line 4147 of file z3py.py.

Referenced by Datatype.declare().

4147  def declare_core(self, name, rec_name, *args):
4148  if __debug__:
4149  _z3_assert(isinstance(name, str), "String expected")
4150  _z3_assert(isinstance(rec_name, str), "String expected")
4151  _z3_assert(all([_valid_accessor(a) for a in args]), "Valid list of accessors expected. An accessor is a pair of the form (String, Datatype|Sort)")
4152  self.constructors.append((name, rec_name, args))
4153 
def declare_core(self, name, rec_name, args)
Definition: z3py.py:4147

Field Documentation

constructors

Definition at line 4145 of file z3py.py.

Referenced by Datatype.__repr__().

ctx
name

Definition at line 4144 of file z3py.py.

Referenced by Datatype.__repr__().