Z3
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Data Fields
Datatype Class Reference

Public Member Functions

def __init__
 
def declare_core
 
def declare
 
def __repr__
 
def create
 

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

Constructor & Destructor Documentation

def __init__ (   self,
  name,
  ctx = None 
)

Definition at line 4059 of file z3py.py.

4060  def __init__(self, name, ctx=None):
4061  self.ctx = _get_ctx(ctx)
4062  self.name = name
4063  self.constructors = []

Member Function Documentation

def __repr__ (   self)

Definition at line 4090 of file z3py.py.

4091  def __repr__(self):
4092  return "Datatype(%s, %s)" % (self.name, self.constructors)
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 4093 of file z3py.py.

Referenced by Datatype.declare().

4094  def create(self):
4095  """Create a Z3 datatype based on the constructors declared using the mehtod `declare()`.
4096 
4097  The function `CreateDatatypes()` must be used to define mutually recursive datatypes.
4098 
4099  >>> List = Datatype('List')
4100  >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4101  >>> List.declare('nil')
4102  >>> List = List.create()
4103  >>> List.nil
4104  nil
4105  >>> List.cons(10, List.nil)
4106  cons(10, nil)
4107  """
4108  return CreateDatatypes([self])[0]
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 4071 of file z3py.py.

Referenced by Datatype.create().

4072  def declare(self, name, *args):
4073  """Declare constructor named `name` with the given accessors `args`.
4074  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.
4075 
4076  In the followin example `List.declare('cons', ('car', IntSort()), ('cdr', List))`
4077  declares the constructor named `cons` that builds a new List using an integer and a List.
4078  It also declares the accessors `car` and `cdr`. The accessor `car` extracts the integer of a `cons` cell,
4079  and `cdr` the list of a `cons` cell. After all constructors were declared, we use the method create() to create
4080  the actual datatype in Z3.
4081 
4082  >>> List = Datatype('List')
4083  >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4084  >>> List.declare('nil')
4085  >>> List = List.create()
4086  """
4087  if __debug__:
4088  _z3_assert(isinstance(name, str), "String expected")
4089  return self.declare_core(name, "is_" + name, *args)
def declare_core (   self,
  name,
  rec_name,
  args 
)

Definition at line 4064 of file z3py.py.

Referenced by Datatype.declare().

4065  def declare_core(self, name, rec_name, *args):
4066  if __debug__:
4067  _z3_assert(isinstance(name, str), "String expected")
4068  _z3_assert(isinstance(rec_name, str), "String expected")
4069  _z3_assert(all(map(_valid_accessor, args)), "Valid list of accessors expected. An accessor is a pair of the form (String, Datatype|Sort)")
4070  self.constructors.append((name, rec_name, args))

Field Documentation

constructors

Definition at line 4062 of file z3py.py.

Referenced by Datatype.__repr__().

ctx

Definition at line 4060 of file z3py.py.

Referenced by Probe.__eq__(), Probe.__ge__(), ApplyResult.__getitem__(), Probe.__gt__(), Probe.__le__(), Probe.__lt__(), Probe.__ne__(), Tactic.apply(), ApplyResult.as_expr(), ApplyResult.convert_model(), Fixedpoint.get_assertions(), Fixedpoint.get_cover_delta(), Fixedpoint.get_rules(), Tactic.param_descrs(), Fixedpoint.parse_file(), Fixedpoint.parse_string(), Tactic.solver(), and Fixedpoint.statistics().

name

Definition at line 4061 of file z3py.py.

Referenced by Datatype.__repr__().