Z3
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules 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 4116 of file z3py.py.

Constructor & Destructor Documentation

def __init__ (   self,
  name,
  ctx = None 
)

Definition at line 4142 of file z3py.py.

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

Member Function Documentation

def __repr__ (   self)

Definition at line 4174 of file z3py.py.

4175  def __repr__(self):
4176  return "Datatype(%s, %s)" % (self.name, self.constructors)
def __repr__
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().

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

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

Definition at line 4147 of file z3py.py.

Referenced by Datatype.declare().

4148  def declare_core(self, name, rec_name, *args):
4149  if __debug__:
4150  _z3_assert(isinstance(name, str), "String expected")
4151  _z3_assert(isinstance(rec_name, str), "String expected")
4152  _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)")
4153  self.constructors.append((name, rec_name, args))
def declare_core
Definition: z3py.py:4147

Field Documentation

constructors

Definition at line 4145 of file z3py.py.

Referenced by Datatype.__repr__().

ctx

Definition at line 4143 of file z3py.py.

Referenced by Probe.__eq__(), Probe.__ge__(), AstVector.__getitem__(), AstMap.__getitem__(), ApplyResult.__getitem__(), Probe.__gt__(), Probe.__le__(), Probe.__lt__(), Probe.__ne__(), Fixedpoint.add_rule(), Tactic.apply(), ApplyResult.as_expr(), Fixedpoint.assert_exprs(), ApplyResult.convert_model(), Fixedpoint.get_answer(), Fixedpoint.get_assertions(), Fixedpoint.get_cover_delta(), Fixedpoint.get_rules(), AstMap.keys(), Fixedpoint.param_descrs(), Tactic.param_descrs(), Fixedpoint.parse_file(), Fixedpoint.parse_string(), Fixedpoint.set(), Tactic.solver(), Fixedpoint.statistics(), Solver.to_smt2(), and Fixedpoint.update_rule().

name

Definition at line 4144 of file z3py.py.

Referenced by Datatype.__repr__().