Z3
Public Member Functions
DatatypeSortRef Class Reference
+ Inheritance diagram for DatatypeSortRef:

Public Member Functions

def num_constructors (self)
 
def constructor (self, idx)
 
def recognizer (self, idx)
 
def accessor (self, i, j)
 
- Public Member Functions inherited from SortRef
def as_ast (self)
 
def get_id (self)
 
def kind (self)
 
def subsort (self, other)
 
def cast (self, val)
 
def name (self)
 
def __eq__ (self, other)
 
def __ne__ (self, other)
 
- Public Member Functions inherited from AstRef
def __init__
 
def __del__ (self)
 
def __str__ (self)
 
def __repr__ (self)
 
def sexpr (self)
 
def as_ast (self)
 
def get_id (self)
 
def ctx_ref (self)
 
def eq (self, other)
 
def translate (self, target)
 
def hash (self)
 
- Public Member Functions inherited from Z3PPObject
def use_pp (self)
 

Additional Inherited Members

- Data Fields inherited from AstRef
 ast
 
 ctx
 

Detailed Description

Datatype sorts.

Definition at line 4324 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 4386 of file z3py.py.

4386  def accessor(self, i, j):
4387  """In Z3, each constructor has 0 or more accessor. The number of accessors is equal to the arity of the constructor.
4388 
4389  >>> List = Datatype('List')
4390  >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4391  >>> List.declare('nil')
4392  >>> List = List.create()
4393  >>> List.num_constructors()
4394  2
4395  >>> List.constructor(0)
4396  cons
4397  >>> num_accs = List.constructor(0).arity()
4398  >>> num_accs
4399  2
4400  >>> List.accessor(0, 0)
4401  car
4402  >>> List.accessor(0, 1)
4403  cdr
4404  >>> List.constructor(1)
4405  nil
4406  >>> num_accs = List.constructor(1).arity()
4407  >>> num_accs
4408  0
4409  """
4410  if __debug__:
4411  _z3_assert(i < self.num_constructors(), "Invalid constructor index")
4412  _z3_assert(j < self.constructor(i).arity(), "Invalid accessor index")
4413  return FuncDeclRef(Z3_get_datatype_sort_constructor_accessor(self.ctx_ref(), self.ast, i, j), self.ctx)
4414 
Function Declarations.
Definition: z3py.py:591
Z3_func_decl Z3_API Z3_get_datatype_sort_constructor_accessor(__in Z3_context c, __in Z3_sort t, unsigned idx_c, unsigned idx_a)
Return idx_a'th accessor for the idx_c'th constructor.
def accessor(self, i, j)
Definition: z3py.py:4386
def num_constructors(self)
Definition: z3py.py:4326
def constructor(self, idx)
Definition: z3py.py:4339
def ctx_ref(self)
Definition: z3py.py:305
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 4339 of file z3py.py.

Referenced by DatatypeSortRef.accessor().

4339  def constructor(self, idx):
4340  """Return a constructor of the datatype `self`.
4341 
4342  >>> List = Datatype('List')
4343  >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4344  >>> List.declare('nil')
4345  >>> List = List.create()
4346  >>> # List is now a Z3 declaration
4347  >>> List.num_constructors()
4348  2
4349  >>> List.constructor(0)
4350  cons
4351  >>> List.constructor(1)
4352  nil
4353  """
4354  if __debug__:
4355  _z3_assert(idx < self.num_constructors(), "Invalid constructor index")
4356  return FuncDeclRef(Z3_get_datatype_sort_constructor(self.ctx_ref(), self.ast, idx), self.ctx)
4357 
Function Declarations.
Definition: z3py.py:591
Z3_func_decl Z3_API Z3_get_datatype_sort_constructor(__in Z3_context c, __in Z3_sort t, unsigned idx)
Return idx'th constructor.
def num_constructors(self)
Definition: z3py.py:4326
def constructor(self, idx)
Definition: z3py.py:4339
def ctx_ref(self)
Definition: z3py.py:305
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 4326 of file z3py.py.

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

4326  def num_constructors(self):
4327  """Return the number of constructors in the given Z3 datatype.
4328 
4329  >>> List = Datatype('List')
4330  >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4331  >>> List.declare('nil')
4332  >>> List = List.create()
4333  >>> # List is now a Z3 declaration
4334  >>> List.num_constructors()
4335  2
4336  """
4337  return int(Z3_get_datatype_sort_num_constructors(self.ctx_ref(), self.ast))
4338 
def num_constructors(self)
Definition: z3py.py:4326
def ctx_ref(self)
Definition: z3py.py:305
unsigned Z3_API Z3_get_datatype_sort_num_constructors(__in Z3_context c, __in Z3_sort t)
Return number of constructors for datatype.
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 4358 of file z3py.py.

4358  def recognizer(self, idx):
4359  """In Z3, each constructor has an associated recognizer predicate.
4360 
4361  If the constructor is named `name`, then the recognizer `is_name`.
4362 
4363  >>> List = Datatype('List')
4364  >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4365  >>> List.declare('nil')
4366  >>> List = List.create()
4367  >>> # List is now a Z3 declaration
4368  >>> List.num_constructors()
4369  2
4370  >>> List.recognizer(0)
4371  is_cons
4372  >>> List.recognizer(1)
4373  is_nil
4374  >>> simplify(List.is_nil(List.cons(10, List.nil)))
4375  False
4376  >>> simplify(List.is_cons(List.cons(10, List.nil)))
4377  True
4378  >>> l = Const('l', List)
4379  >>> simplify(List.is_cons(l))
4380  is_cons(l)
4381  """
4382  if __debug__:
4383  _z3_assert(idx < self.num_constructors(), "Invalid recognizer index")
4384  return FuncDeclRef(Z3_get_datatype_sort_recognizer(self.ctx_ref(), self.ast, idx), self.ctx)
4385 
Function Declarations.
Definition: z3py.py:591
Z3_func_decl Z3_API Z3_get_datatype_sort_recognizer(__in Z3_context c, __in Z3_sort t, unsigned idx)
Return idx'th recognizer.
def num_constructors(self)
Definition: z3py.py:4326
def ctx_ref(self)
Definition: z3py.py:305
def recognizer(self, idx)
Definition: z3py.py:4358