Z3
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions
DatatypeSortRef Class Reference
+ Inheritance diagram for DatatypeSortRef:

Public Member Functions

def num_constructors
 
def constructor
 
def recognizer
 
def accessor
 
- Public Member Functions inherited from SortRef
def as_ast
 
def get_id
 
def kind
 
def subsort
 
def cast
 
def name
 
def __eq__
 
def __ne__
 
- Public Member Functions inherited from AstRef
def __init__
 
def __del__
 
def __str__
 
def __repr__
 
def sexpr
 
def as_ast
 
def get_id
 
def ctx_ref
 
def eq
 
def translate
 
def hash
 
- Public Member Functions inherited from Z3PPObject
def use_pp
 

Additional Inherited Members

- Data Fields inherited from AstRef
 ast
 
 ctx
 

Detailed Description

Datatype sorts.

Definition at line 4361 of file z3py.py.

Member Function Documentation

def accessor (   self,
  i,
  j 
)
In Z3, each constructor has 0 or more accessor. The number of accessors is equal to the arity of the constructor.

>>> List = Datatype('List')
>>> List.declare('cons', ('car', IntSort()), ('cdr', List))
>>> List.declare('nil')
>>> List = List.create()
>>> List.num_constructors()
2
>>> List.constructor(0)
cons
>>> num_accs = List.constructor(0).arity()
>>> num_accs
2
>>> List.accessor(0, 0)
car
>>> List.accessor(0, 1)
cdr
>>> List.constructor(1)
nil
>>> num_accs = List.constructor(1).arity()
>>> num_accs
0

Definition at line 4423 of file z3py.py.

4424  def accessor(self, i, j):
4425  """In Z3, each constructor has 0 or more accessor. The number of accessors is equal to the arity of the constructor.
4426 
4427  >>> List = Datatype('List')
4428  >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4429  >>> List.declare('nil')
4430  >>> List = List.create()
4431  >>> List.num_constructors()
4432  2
4433  >>> List.constructor(0)
4434  cons
4435  >>> num_accs = List.constructor(0).arity()
4436  >>> num_accs
4437  2
4438  >>> List.accessor(0, 0)
4439  car
4440  >>> List.accessor(0, 1)
4441  cdr
4442  >>> List.constructor(1)
4443  nil
4444  >>> num_accs = List.constructor(1).arity()
4445  >>> num_accs
4446  0
4447  """
4448  if __debug__:
4449  _z3_assert(i < self.num_constructors(), "Invalid constructor index")
4450  _z3_assert(j < self.constructor(i).arity(), "Invalid accessor index")
4451  return FuncDeclRef(Z3_get_datatype_sort_constructor_accessor(self.ctx_ref(), self.ast, i, j), self.ctx)
Z3_func_decl Z3_API Z3_get_datatype_sort_constructor_accessor(Z3_context c, Z3_sort t, unsigned idx_c, unsigned idx_a)
Return idx_a&#39;th accessor for the idx_c&#39;th constructor.
Function Declarations.
Definition: z3py.py:591
def ctx_ref
Definition: z3py.py:304
def constructor (   self,
  idx 
)
Return a constructor of the datatype `self`.

>>> List = Datatype('List')
>>> List.declare('cons', ('car', IntSort()), ('cdr', List))
>>> List.declare('nil')
>>> List = List.create()
>>> # List is now a Z3 declaration
>>> List.num_constructors()
2
>>> List.constructor(0)
cons
>>> List.constructor(1)
nil

Definition at line 4376 of file z3py.py.

Referenced by DatatypeSortRef.accessor().

4377  def constructor(self, idx):
4378  """Return a constructor of the datatype `self`.
4379 
4380  >>> List = Datatype('List')
4381  >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4382  >>> List.declare('nil')
4383  >>> List = List.create()
4384  >>> # List is now a Z3 declaration
4385  >>> List.num_constructors()
4386  2
4387  >>> List.constructor(0)
4388  cons
4389  >>> List.constructor(1)
4390  nil
4391  """
4392  if __debug__:
4393  _z3_assert(idx < self.num_constructors(), "Invalid constructor index")
4394  return FuncDeclRef(Z3_get_datatype_sort_constructor(self.ctx_ref(), self.ast, idx), self.ctx)
Function Declarations.
Definition: z3py.py:591
def ctx_ref
Definition: z3py.py:304
Z3_func_decl Z3_API Z3_get_datatype_sort_constructor(Z3_context c, Z3_sort t, unsigned idx)
Return idx&#39;th constructor.
def num_constructors (   self)
Return the number of constructors in the given Z3 datatype. 

>>> List = Datatype('List')
>>> List.declare('cons', ('car', IntSort()), ('cdr', List))
>>> List.declare('nil')
>>> List = List.create()
>>> # List is now a Z3 declaration
>>> List.num_constructors()
2

Definition at line 4363 of file z3py.py.

Referenced by DatatypeSortRef.accessor(), and DatatypeSortRef.constructor().

4364  def num_constructors(self):
4365  """Return the number of constructors in the given Z3 datatype.
4366 
4367  >>> List = Datatype('List')
4368  >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4369  >>> List.declare('nil')
4370  >>> List = List.create()
4371  >>> # List is now a Z3 declaration
4372  >>> List.num_constructors()
4373  2
4374  """
4375  return int(Z3_get_datatype_sort_num_constructors(self.ctx_ref(), self.ast))
unsigned Z3_API Z3_get_datatype_sort_num_constructors(Z3_context c, Z3_sort t)
Return number of constructors for datatype.
def ctx_ref
Definition: z3py.py:304
def recognizer (   self,
  idx 
)
In Z3, each constructor has an associated recognizer predicate. 

If the constructor is named `name`, then the recognizer `is_name`.

>>> List = Datatype('List')
>>> List.declare('cons', ('car', IntSort()), ('cdr', List))
>>> List.declare('nil')
>>> List = List.create()
>>> # List is now a Z3 declaration
>>> List.num_constructors()
2
>>> List.recognizer(0)
is_cons
>>> List.recognizer(1)
is_nil
>>> simplify(List.is_nil(List.cons(10, List.nil)))
False
>>> simplify(List.is_cons(List.cons(10, List.nil)))
True
>>> l = Const('l', List)
>>> simplify(List.is_cons(l))
is_cons(l)

Definition at line 4395 of file z3py.py.

4396  def recognizer(self, idx):
4397  """In Z3, each constructor has an associated recognizer predicate.
4398 
4399  If the constructor is named `name`, then the recognizer `is_name`.
4400 
4401  >>> List = Datatype('List')
4402  >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4403  >>> List.declare('nil')
4404  >>> List = List.create()
4405  >>> # List is now a Z3 declaration
4406  >>> List.num_constructors()
4407  2
4408  >>> List.recognizer(0)
4409  is_cons
4410  >>> List.recognizer(1)
4411  is_nil
4412  >>> simplify(List.is_nil(List.cons(10, List.nil)))
4413  False
4414  >>> simplify(List.is_cons(List.cons(10, List.nil)))
4415  True
4416  >>> l = Const('l', List)
4417  >>> simplify(List.is_cons(l))
4418  is_cons(l)
4419  """
4420  if __debug__:
4421  _z3_assert(idx < self.num_constructors(), "Invalid recognizer index")
4422  return FuncDeclRef(Z3_get_datatype_sort_recognizer(self.ctx_ref(), self.ast, idx), self.ctx)
Function Declarations.
Definition: z3py.py:591
Z3_func_decl Z3_API Z3_get_datatype_sort_recognizer(Z3_context c, Z3_sort t, unsigned idx)
Return idx&#39;th recognizer.
def ctx_ref
Definition: z3py.py:304