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__ (self, ast, ctx=None)
 
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 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.

4423  def accessor(self, i, j):
4424  """In Z3, each constructor has 0 or more accessor. The number of accessors is equal to the arity of the constructor.
4425 
4426  >>> List = Datatype('List')
4427  >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4428  >>> List.declare('nil')
4429  >>> List = List.create()
4430  >>> List.num_constructors()
4431  2
4432  >>> List.constructor(0)
4433  cons
4434  >>> num_accs = List.constructor(0).arity()
4435  >>> num_accs
4436  2
4437  >>> List.accessor(0, 0)
4438  car
4439  >>> List.accessor(0, 1)
4440  cdr
4441  >>> List.constructor(1)
4442  nil
4443  >>> num_accs = List.constructor(1).arity()
4444  >>> num_accs
4445  0
4446  """
4447  if __debug__:
4448  _z3_assert(i < self.num_constructors(), "Invalid constructor index")
4449  _z3_assert(j < self.constructor(i).arity(), "Invalid accessor index")
4450  return FuncDeclRef(Z3_get_datatype_sort_constructor_accessor(self.ctx_ref(), self.ast, i, j), self.ctx)
4451 
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 accessor(self, i, j)
Definition: z3py.py:4423
def num_constructors(self)
Definition: z3py.py:4363
def constructor(self, idx)
Definition: z3py.py:4376
def ctx_ref(self)
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().

4376  def constructor(self, idx):
4377  """Return a constructor of the datatype `self`.
4378 
4379  >>> List = Datatype('List')
4380  >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4381  >>> List.declare('nil')
4382  >>> List = List.create()
4383  >>> # List is now a Z3 declaration
4384  >>> List.num_constructors()
4385  2
4386  >>> List.constructor(0)
4387  cons
4388  >>> List.constructor(1)
4389  nil
4390  """
4391  if __debug__:
4392  _z3_assert(idx < self.num_constructors(), "Invalid constructor index")
4393  return FuncDeclRef(Z3_get_datatype_sort_constructor(self.ctx_ref(), self.ast, idx), self.ctx)
4394 
Function Declarations.
Definition: z3py.py:591
def num_constructors(self)
Definition: z3py.py:4363
def constructor(self, idx)
Definition: z3py.py:4376
def ctx_ref(self)
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().

4363  def num_constructors(self):
4364  """Return the number of constructors in the given Z3 datatype.
4365 
4366  >>> List = Datatype('List')
4367  >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4368  >>> List.declare('nil')
4369  >>> List = List.create()
4370  >>> # List is now a Z3 declaration
4371  >>> List.num_constructors()
4372  2
4373  """
4374  return int(Z3_get_datatype_sort_num_constructors(self.ctx_ref(), self.ast))
4375 
def num_constructors(self)
Definition: z3py.py:4363
unsigned Z3_API Z3_get_datatype_sort_num_constructors(Z3_context c, Z3_sort t)
Return number of constructors for datatype.
def ctx_ref(self)
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.

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