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

5485 def accessor(self, i, j):
5486 """In Z3, each constructor has 0 or more accessor.
5487 The number of accessors is equal to the arity of the constructor.
5488
5489 >>> List = Datatype('List')
5490 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5491 >>> List.declare('nil')
5492 >>> List = List.create()
5493 >>> List.num_constructors()
5494 2
5495 >>> List.constructor(0)
5496 cons
5497 >>> num_accs = List.constructor(0).arity()
5498 >>> num_accs
5499 2
5500 >>> List.accessor(0, 0)
5501 car
5502 >>> List.accessor(0, 1)
5503 cdr
5504 >>> List.constructor(1)
5505 nil
5506 >>> num_accs = List.constructor(1).arity()
5507 >>> num_accs
5508 0
5509 """
5510 if z3_debug():
5511 _z3_assert(i < self.num_constructors(), "Invalid constructor index")
5512 _z3_assert(j < self.constructor(i).arity(), "Invalid accessor index")
5513 return FuncDeclRef(
5514 Z3_get_datatype_sort_constructor_accessor(self.ctx_ref(), self.ast, i, j),
5515 ctx=self.ctx,
5516 )
5517
5518
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 5438 of file z3py.py.

5438 def constructor(self, idx):
5439 """Return a constructor of the datatype `self`.
5440
5441 >>> List = Datatype('List')
5442 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5443 >>> List.declare('nil')
5444 >>> List = List.create()
5445 >>> # List is now a Z3 declaration
5446 >>> List.num_constructors()
5447 2
5448 >>> List.constructor(0)
5449 cons
5450 >>> List.constructor(1)
5451 nil
5452 """
5453 if z3_debug():
5454 _z3_assert(idx < self.num_constructors(), "Invalid constructor index")
5455 return FuncDeclRef(Z3_get_datatype_sort_constructor(self.ctx_ref(), self.ast, idx), self.ctx)
5456
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 5425 of file z3py.py.

5425 def num_constructors(self):
5426 """Return the number of constructors in the given Z3 datatype.
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 """
5436 return int(Z3_get_datatype_sort_num_constructors(self.ctx_ref(), self.ast))
5437
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 5457 of file z3py.py.

5457 def recognizer(self, idx):
5458 """In Z3, each constructor has an associated recognizer predicate.
5459
5460 If the constructor is named `name`, then the recognizer `is_name`.
5461
5462 >>> List = Datatype('List')
5463 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5464 >>> List.declare('nil')
5465 >>> List = List.create()
5466 >>> # List is now a Z3 declaration
5467 >>> List.num_constructors()
5468 2
5469 >>> List.recognizer(0)
5470 is(cons)
5471 >>> List.recognizer(1)
5472 is(nil)
5473 >>> simplify(List.is_nil(List.cons(10, List.nil)))
5474 False
5475 >>> simplify(List.is_cons(List.cons(10, List.nil)))
5476 True
5477 >>> l = Const('l', List)
5478 >>> simplify(List.is_cons(l))
5479 is(cons, l)
5480 """
5481 if z3_debug():
5482 _z3_assert(idx < self.num_constructors(), "Invalid recognizer index")
5483 return FuncDeclRef(Z3_get_datatype_sort_recognizer(self.ctx_ref(), self.ast, idx), self.ctx)
5484
Z3_func_decl Z3_API Z3_get_datatype_sort_recognizer(Z3_context c, Z3_sort t, unsigned idx)
Return idx'th recognizer.