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

5451 def accessor(self, i, j):
5452 """In Z3, each constructor has 0 or more accessor.
5453 The number of accessors is equal to the arity of the constructor.
5454
5455 >>> List = Datatype('List')
5456 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5457 >>> List.declare('nil')
5458 >>> List = List.create()
5459 >>> List.num_constructors()
5460 2
5461 >>> List.constructor(0)
5462 cons
5463 >>> num_accs = List.constructor(0).arity()
5464 >>> num_accs
5465 2
5466 >>> List.accessor(0, 0)
5467 car
5468 >>> List.accessor(0, 1)
5469 cdr
5470 >>> List.constructor(1)
5471 nil
5472 >>> num_accs = List.constructor(1).arity()
5473 >>> num_accs
5474 0
5475 """
5476 if z3_debug():
5477 _z3_assert(i < self.num_constructors(), "Invalid constructor index")
5478 _z3_assert(j < self.constructor(i).arity(), "Invalid accessor index")
5479 return FuncDeclRef(
5480 Z3_get_datatype_sort_constructor_accessor(self.ctx_ref(), self.ast, i, j),
5481 ctx=self.ctx,
5482 )
5483
5484
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 5404 of file z3py.py.

5404 def constructor(self, idx):
5405 """Return a constructor of the datatype `self`.
5406
5407 >>> List = Datatype('List')
5408 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5409 >>> List.declare('nil')
5410 >>> List = List.create()
5411 >>> # List is now a Z3 declaration
5412 >>> List.num_constructors()
5413 2
5414 >>> List.constructor(0)
5415 cons
5416 >>> List.constructor(1)
5417 nil
5418 """
5419 if z3_debug():
5420 _z3_assert(idx < self.num_constructors(), "Invalid constructor index")
5421 return FuncDeclRef(Z3_get_datatype_sort_constructor(self.ctx_ref(), self.ast, idx), self.ctx)
5422
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 5391 of file z3py.py.

5391 def num_constructors(self):
5392 """Return the number of constructors in the given Z3 datatype.
5393
5394 >>> List = Datatype('List')
5395 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5396 >>> List.declare('nil')
5397 >>> List = List.create()
5398 >>> # List is now a Z3 declaration
5399 >>> List.num_constructors()
5400 2
5401 """
5402 return int(Z3_get_datatype_sort_num_constructors(self.ctx_ref(), self.ast))
5403
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 5423 of file z3py.py.

5423 def recognizer(self, idx):
5424 """In Z3, each constructor has an associated recognizer predicate.
5425
5426 If the constructor is named `name`, then the recognizer `is_name`.
5427
5428 >>> List = Datatype('List')
5429 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5430 >>> List.declare('nil')
5431 >>> List = List.create()
5432 >>> # List is now a Z3 declaration
5433 >>> List.num_constructors()
5434 2
5435 >>> List.recognizer(0)
5436 is(cons)
5437 >>> List.recognizer(1)
5438 is(nil)
5439 >>> simplify(List.is_nil(List.cons(10, List.nil)))
5440 False
5441 >>> simplify(List.is_cons(List.cons(10, List.nil)))
5442 True
5443 >>> l = Const('l', List)
5444 >>> simplify(List.is_cons(l))
5445 is(cons, l)
5446 """
5447 if z3_debug():
5448 _z3_assert(idx < self.num_constructors(), "Invalid recognizer index")
5449 return FuncDeclRef(Z3_get_datatype_sort_recognizer(self.ctx_ref(), self.ast, idx), self.ctx)
5450
Z3_func_decl Z3_API Z3_get_datatype_sort_recognizer(Z3_context c, Z3_sort t, unsigned idx)
Return idx'th recognizer.