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

Public Member Functions

def __init__
 
def __deepcopy__
 
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 4662 of file z3py.py.

Constructor & Destructor Documentation

def __init__ (   self,
  name,
  ctx = None 
)

Definition at line 4688 of file z3py.py.

4689  def __init__(self, name, ctx=None):
4690  self.ctx = _get_ctx(ctx)
4691  self.name = name
4692  self.constructors = []
def __init__
Definition: z3py.py:4688

Member Function Documentation

def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 4693 of file z3py.py.

4694  def __deepcopy__(self, memo={}):
4695  r = Datatype(self.name, self.ctx)
4696  r.constructors = copy.deepcopy(self.constructors)
4697  return r
def __deepcopy__
Definition: z3py.py:4693
def __repr__ (   self)

Definition at line 4725 of file z3py.py.

4726  def __repr__(self):
4727  return "Datatype(%s, %s)" % (self.name, self.constructors)
def __repr__
Definition: z3py.py:4725
def create (   self)
Create a Z3 datatype based on the constructors declared using the method `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 4728 of file z3py.py.

Referenced by Datatype.declare().

4729  def create(self):
4730  """Create a Z3 datatype based on the constructors declared using the method `declare()`.
4731 
4732  The function `CreateDatatypes()` must be used to define mutually recursive datatypes.
4733 
4734  >>> List = Datatype('List')
4735  >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4736  >>> List.declare('nil')
4737  >>> List = List.create()
4738  >>> List.nil
4739  nil
4740  >>> List.cons(10, List.nil)
4741  cons(10, nil)
4742  """
4743  return CreateDatatypes([self])[0]
def CreateDatatypes
Definition: z3py.py:4762
def create
Definition: z3py.py:4728
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 following 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 4705 of file z3py.py.

Referenced by Datatype.create().

4706  def declare(self, name, *args):
4707  """Declare constructor named `name` with the given accessors `args`.
4708  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.
4709 
4710  In the following example `List.declare('cons', ('car', IntSort()), ('cdr', List))`
4711  declares the constructor named `cons` that builds a new List using an integer and a List.
4712  It also declares the accessors `car` and `cdr`. The accessor `car` extracts the integer of a `cons` cell,
4713  and `cdr` the list of a `cons` cell. After all constructors were declared, we use the method create() to create
4714  the actual datatype in Z3.
4715 
4716  >>> List = Datatype('List')
4717  >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4718  >>> List.declare('nil')
4719  >>> List = List.create()
4720  """
4721  if z3_debug():
4722  _z3_assert(isinstance(name, str), "String expected")
4723  _z3_assert(name != "", "Constructor name cannot be empty")
4724  return self.declare_core(name, "is-" + name, *args)
def declare
Definition: z3py.py:4705
def declare_core
Definition: z3py.py:4698
def z3_debug
Definition: z3py.py:58
def declare_core (   self,
  name,
  rec_name,
  args 
)

Definition at line 4698 of file z3py.py.

Referenced by Datatype.declare().

4699  def declare_core(self, name, rec_name, *args):
4700  if z3_debug():
4701  _z3_assert(isinstance(name, str), "String expected")
4702  _z3_assert(isinstance(rec_name, str), "String expected")
4703  _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)")
4704  self.constructors.append((name, rec_name, args))
def declare_core
Definition: z3py.py:4698
def z3_debug
Definition: z3py.py:58

Field Documentation

constructors

Definition at line 4691 of file z3py.py.

Referenced by Datatype.__deepcopy__(), and Datatype.__repr__().

ctx

Definition at line 4689 of file z3py.py.

Referenced by AstVector.__copy__(), Datatype.__deepcopy__(), AstVector.__deepcopy__(), AstMap.__deepcopy__(), Fixedpoint.__deepcopy__(), Optimize.__deepcopy__(), ApplyResult.__deepcopy__(), Tactic.__deepcopy__(), Probe.__deepcopy__(), Probe.__eq__(), Probe.__ge__(), AstVector.__getitem__(), AstMap.__getitem__(), ApplyResult.__getitem__(), Probe.__gt__(), Probe.__le__(), Probe.__lt__(), Probe.__ne__(), Fixedpoint.add_rule(), Optimize.add_soft(), Tactic.apply(), ApplyResult.as_expr(), Optimize.assert_and_track(), Fixedpoint.assert_exprs(), Optimize.assert_exprs(), Optimize.assertions(), Fixedpoint.get_answer(), Fixedpoint.get_assertions(), Fixedpoint.get_cover_delta(), Fixedpoint.get_ground_sat_answer(), Fixedpoint.get_rule_names_along_trace(), Fixedpoint.get_rules(), Fixedpoint.get_rules_along_trace(), AstMap.keys(), Optimize.model(), Optimize.objectives(), Fixedpoint.param_descrs(), Optimize.param_descrs(), Tactic.param_descrs(), Fixedpoint.parse_file(), Fixedpoint.parse_string(), Fixedpoint.query(), Fixedpoint.set(), Optimize.set(), Tactic.solver(), Fixedpoint.statistics(), Optimize.statistics(), Solver.to_smt2(), Optimize.unsat_core(), and Fixedpoint.update_rule().

name

Definition at line 4690 of file z3py.py.

Referenced by Datatype.__deepcopy__(), and Datatype.__repr__().