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)
 
def __hash__ (self)
 
- Public Member Functions inherited from AstRef
def __init__ (self, ast, ctx=None)
 
def __del__ (self)
 
def __deepcopy__ (self, memo={})
 
def __str__ (self)
 
def __repr__ (self)
 
def __nonzero__ (self)
 
def __bool__ (self)
 
def sexpr (self)
 
def ctx_ref (self)
 
def eq (self, other)
 
def translate (self, target)
 
def __copy__ (self)
 
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 4897 of file z3py.py.

Member Function Documentation

◆ accessor()

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

4959  def accessor(self, i, j):
4960  """In Z3, each constructor has 0 or more accessor. The number of accessors is equal to the arity of the constructor.
4961 
4962  >>> List = Datatype('List')
4963  >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4964  >>> List.declare('nil')
4965  >>> List = List.create()
4966  >>> List.num_constructors()
4967  2
4968  >>> List.constructor(0)
4969  cons
4970  >>> num_accs = List.constructor(0).arity()
4971  >>> num_accs
4972  2
4973  >>> List.accessor(0, 0)
4974  car
4975  >>> List.accessor(0, 1)
4976  cdr
4977  >>> List.constructor(1)
4978  nil
4979  >>> num_accs = List.constructor(1).arity()
4980  >>> num_accs
4981  0
4982  """
4983  if z3_debug():
4984  _z3_assert(i < self.num_constructors(), "Invalid constructor index")
4985  _z3_assert(j < self.constructor(i).arity(), "Invalid accessor index")
4986  return FuncDeclRef(Z3_get_datatype_sort_constructor_accessor(self.ctx_ref(), self.ast, i, j), self.ctx)
4987 

◆ constructor()

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

4912  def constructor(self, idx):
4913  """Return a constructor of the datatype `self`.
4914 
4915  >>> List = Datatype('List')
4916  >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4917  >>> List.declare('nil')
4918  >>> List = List.create()
4919  >>> # List is now a Z3 declaration
4920  >>> List.num_constructors()
4921  2
4922  >>> List.constructor(0)
4923  cons
4924  >>> List.constructor(1)
4925  nil
4926  """
4927  if z3_debug():
4928  _z3_assert(idx < self.num_constructors(), "Invalid constructor index")
4929  return FuncDeclRef(Z3_get_datatype_sort_constructor(self.ctx_ref(), self.ast, idx), self.ctx)
4930 

Referenced by DatatypeSortRef.accessor().

◆ num_constructors()

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

4899  def num_constructors(self):
4900  """Return the number of constructors in the given Z3 datatype.
4901 
4902  >>> List = Datatype('List')
4903  >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4904  >>> List.declare('nil')
4905  >>> List = List.create()
4906  >>> # List is now a Z3 declaration
4907  >>> List.num_constructors()
4908  2
4909  """
4910  return int(Z3_get_datatype_sort_num_constructors(self.ctx_ref(), self.ast))
4911 

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

◆ recognizer()

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

4931  def recognizer(self, idx):
4932  """In Z3, each constructor has an associated recognizer predicate.
4933 
4934  If the constructor is named `name`, then the recognizer `is_name`.
4935 
4936  >>> List = Datatype('List')
4937  >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4938  >>> List.declare('nil')
4939  >>> List = List.create()
4940  >>> # List is now a Z3 declaration
4941  >>> List.num_constructors()
4942  2
4943  >>> List.recognizer(0)
4944  is(cons)
4945  >>> List.recognizer(1)
4946  is(nil)
4947  >>> simplify(List.is_nil(List.cons(10, List.nil)))
4948  False
4949  >>> simplify(List.is_cons(List.cons(10, List.nil)))
4950  True
4951  >>> l = Const('l', List)
4952  >>> simplify(List.is_cons(l))
4953  is(cons, l)
4954  """
4955  if z3_debug():
4956  _z3_assert(idx < self.num_constructors(), "Invalid recognizer index")
4957  return FuncDeclRef(Z3_get_datatype_sort_recognizer(self.ctx_ref(), self.ast, idx), self.ctx)
4958 
Z3_get_datatype_sort_num_constructors
unsigned Z3_API Z3_get_datatype_sort_num_constructors(Z3_context c, Z3_sort t)
Return number of constructors for datatype.
z3py.z3_debug
def z3_debug()
Definition: z3py.py:56
Z3_get_datatype_sort_constructor
Z3_func_decl Z3_API Z3_get_datatype_sort_constructor(Z3_context c, Z3_sort t, unsigned idx)
Return idx'th constructor.
Z3_get_datatype_sort_recognizer
Z3_func_decl Z3_API Z3_get_datatype_sort_recognizer(Z3_context c, Z3_sort t, unsigned idx)
Return idx'th recognizer.
Z3_get_datatype_sort_constructor_accessor
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'th accessor for the idx_c'th constructor.