Z3
Loading...
Searching...
No Matches
DatatypeSortRef Class Reference
Inheritance diagram for DatatypeSortRef:

Public Member Functions

 num_constructors (self)
 constructor (self, idx)
 recognizer (self, idx)
 accessor (self, i, j)
Public Member Functions inherited from SortRef
 as_ast (self)
 get_id (self)
 kind (self)
 subsort (self, other)
 cast (self, val)
 name (self)
 __eq__ (self, other)
 __ne__ (self, other)
 __gt__ (self, other)
 __hash__ (self)
Public Member Functions inherited from AstRef
 __init__ (self, ast, ctx=None)
 __del__ (self)
 __deepcopy__ (self, memo={})
 __str__ (self)
 __repr__ (self)
 __eq__ (self, other)
 __hash__ (self)
 __nonzero__ (self)
 __bool__ (self)
 sexpr (self)
 ctx_ref (self)
 eq (self, other)
 translate (self, target)
 __copy__ (self)
 hash (self)
 py_value (self)
Public Member Functions inherited from Z3PPObject
 use_pp (self)

Additional Inherited Members

Data Fields inherited from AstRef
 ast = ast
 ctx = _get_ctx(ctx)
Protected Member Functions inherited from Z3PPObject
 _repr_html_ (self)

Detailed Description

Datatype sorts.

Definition at line 5937 of file z3py.py.

Member Function Documentation

◆ accessor()

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

6000 def accessor(self, i, j):
6001 """In Z3, each constructor has 0 or more accessor.
6002 The number of accessors is equal to the arity of the constructor.
6003
6004 >>> List = Datatype('List')
6005 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
6006 >>> List.declare('nil')
6007 >>> List = List.create()
6008 >>> List.num_constructors()
6009 2
6010 >>> List.constructor(0)
6011 cons
6012 >>> num_accs = List.constructor(0).arity()
6013 >>> num_accs
6014 2
6015 >>> List.accessor(0, 0)
6016 car
6017 >>> List.accessor(0, 1)
6018 cdr
6019 >>> List.constructor(1)
6020 nil
6021 >>> num_accs = List.constructor(1).arity()
6022 >>> num_accs
6023 0
6024 """
6025 if z3_debug():
6026 _z3_assert(i < self.num_constructors(), "Invalid constructor index")
6027 _z3_assert(j < self.constructor(i).arity(), "Invalid accessor index")
6028 return FuncDeclRef(
6029 Z3_get_datatype_sort_constructor_accessor(self.ctx_ref(), self.ast, i, j),
6030 ctx=self.ctx,
6031 )
6032
6033
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.

◆ constructor()

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

5953 def constructor(self, idx):
5954 """Return a constructor of the datatype `self`.
5955
5956 >>> List = Datatype('List')
5957 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5958 >>> List.declare('nil')
5959 >>> List = List.create()
5960 >>> # List is now a Z3 declaration
5961 >>> List.num_constructors()
5962 2
5963 >>> List.constructor(0)
5964 cons
5965 >>> List.constructor(1)
5966 nil
5967 """
5968 if z3_debug():
5969 _z3_assert(idx < self.num_constructors(), "Invalid constructor index")
5970 return FuncDeclRef(Z3_get_datatype_sort_constructor(self.ctx_ref(), self.ast, idx), self.ctx)
5971
Z3_func_decl Z3_API Z3_get_datatype_sort_constructor(Z3_context c, Z3_sort t, unsigned idx)
Return idx'th constructor.

Referenced by accessor().

◆ num_constructors()

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

5940 def num_constructors(self):
5941 """Return the number of constructors in the given Z3 datatype.
5942
5943 >>> List = Datatype('List')
5944 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5945 >>> List.declare('nil')
5946 >>> List = List.create()
5947 >>> # List is now a Z3 declaration
5948 >>> List.num_constructors()
5949 2
5950 """
5951 return int(Z3_get_datatype_sort_num_constructors(self.ctx_ref(), self.ast))
5952
unsigned Z3_API Z3_get_datatype_sort_num_constructors(Z3_context c, Z3_sort t)
Return number of constructors for datatype.

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

◆ recognizer()

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

5972 def recognizer(self, idx):
5973 """In Z3, each constructor has an associated recognizer predicate.
5974
5975 If the constructor is named `name`, then the recognizer `is_name`.
5976
5977 >>> List = Datatype('List')
5978 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5979 >>> List.declare('nil')
5980 >>> List = List.create()
5981 >>> # List is now a Z3 declaration
5982 >>> List.num_constructors()
5983 2
5984 >>> List.recognizer(0)
5985 is(cons)
5986 >>> List.recognizer(1)
5987 is(nil)
5988 >>> simplify(List.is_nil(List.cons(10, List.nil)))
5989 False
5990 >>> simplify(List.is_cons(List.cons(10, List.nil)))
5991 True
5992 >>> l = Const('l', List)
5993 >>> simplify(List.is_cons(l))
5994 is(cons, l)
5995 """
5996 if z3_debug():
5997 _z3_assert(idx < self.num_constructors(), "Invalid recognizer index")
5998 return FuncDeclRef(Z3_get_datatype_sort_recognizer(self.ctx_ref(), self.ast, idx), self.ctx)
5999
Z3_func_decl Z3_API Z3_get_datatype_sort_recognizer(Z3_context c, Z3_sort t, unsigned idx)
Return idx'th recognizer.