Z3
Public Member Functions
SortRef Class Reference
+ Inheritance diagram for SortRef:

Public Member Functions

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

A Sort is essentially a type. Every Z3 expression has a sort. A sort is an AST node.

Definition at line 511 of file z3py.py.

Member Function Documentation

◆ __eq__()

def __eq__ (   self,
  other 
)
Return `True` if `self` and `other` are the same Z3 sort.

>>> p = Bool('p')
>>> p.sort() == BoolSort()
True
>>> p.sort() == IntSort()
False

Reimplemented from AstRef.

Definition at line 568 of file z3py.py.

568  def __eq__(self, other):
569  """Return `True` if `self` and `other` are the same Z3 sort.
570 
571  >>> p = Bool('p')
572  >>> p.sort() == BoolSort()
573  True
574  >>> p.sort() == IntSort()
575  False
576  """
577  if other is None:
578  return False
579  return Z3_is_eq_sort(self.ctx_ref(), self.ast, other.ast)
580 

Referenced by CheckSatResult.__ne__(), and Probe.__ne__().

◆ __hash__()

def __hash__ (   self)
Hash code. 

Reimplemented from AstRef.

Definition at line 592 of file z3py.py.

592  def __hash__(self):
593  """ Hash code. """
594  return AstRef.__hash__(self)
595 

◆ __ne__()

def __ne__ (   self,
  other 
)
Return `True` if `self` and `other` are not the same Z3 sort.

>>> p = Bool('p')
>>> p.sort() != BoolSort()
False
>>> p.sort() != IntSort()
True

Definition at line 581 of file z3py.py.

581  def __ne__(self, other):
582  """Return `True` if `self` and `other` are not the same Z3 sort.
583 
584  >>> p = Bool('p')
585  >>> p.sort() != BoolSort()
586  False
587  >>> p.sort() != IntSort()
588  True
589  """
590  return not Z3_is_eq_sort(self.ctx_ref(), self.ast, other.ast)
591 

◆ as_ast()

def as_ast (   self)
Return a pointer to the corresponding C Z3_ast object.

Reimplemented from AstRef.

Definition at line 513 of file z3py.py.

513  def as_ast(self):
514  return Z3_sort_to_ast(self.ctx_ref(), self.ast)
515 

◆ cast()

def cast (   self,
  val 
)
Try to cast `val` as an element of sort `self`.

This method is used in Z3Py to convert Python objects such as integers,
floats, longs and strings into Z3 expressions.

>>> x = Int('x')
>>> RealSort().cast(x)
ToReal(x)

Reimplemented in FPSortRef, BitVecSortRef, ArithSortRef, and BoolSortRef.

Definition at line 543 of file z3py.py.

543  def cast(self, val):
544  """Try to cast `val` as an element of sort `self`.
545 
546  This method is used in Z3Py to convert Python objects such as integers,
547  floats, longs and strings into Z3 expressions.
548 
549  >>> x = Int('x')
550  >>> RealSort().cast(x)
551  ToReal(x)
552  """
553  if z3_debug():
554  _z3_assert(is_expr(val), "Z3 expression expected")
555  _z3_assert(self.eq(val.sort()), "Sort mismatch")
556  return val
557 

◆ get_id()

def get_id (   self)
Return unique identifier for object. It can be used for hash-tables and maps.

Reimplemented from AstRef.

Definition at line 516 of file z3py.py.

516  def get_id(self):
517  return Z3_get_ast_id(self.ctx_ref(), self.as_ast())
518 

◆ kind()

def kind (   self)
Return the Z3 internal kind of a sort. This method can be used to test if `self` is one of the Z3 builtin sorts.

>>> b = BoolSort()
>>> b.kind() == Z3_BOOL_SORT
True
>>> b.kind() == Z3_INT_SORT
False
>>> A = ArraySort(IntSort(), IntSort())
>>> A.kind() == Z3_ARRAY_SORT
True
>>> A.kind() == Z3_INT_SORT
False

Definition at line 519 of file z3py.py.

519  def kind(self):
520  """Return the Z3 internal kind of a sort. This method can be used to test if `self` is one of the Z3 builtin sorts.
521 
522  >>> b = BoolSort()
523  >>> b.kind() == Z3_BOOL_SORT
524  True
525  >>> b.kind() == Z3_INT_SORT
526  False
527  >>> A = ArraySort(IntSort(), IntSort())
528  >>> A.kind() == Z3_ARRAY_SORT
529  True
530  >>> A.kind() == Z3_INT_SORT
531  False
532  """
533  return _sort_kind(self.ctx, self.ast)
534 

Referenced by ArithSortRef.is_int(), and ArithSortRef.is_real().

◆ name()

def name (   self)
Return the name (string) of sort `self`.

>>> BoolSort().name()
'Bool'
>>> ArraySort(IntSort(), IntSort()).name()
'Array'

Definition at line 558 of file z3py.py.

558  def name(self):
559  """Return the name (string) of sort `self`.
560 
561  >>> BoolSort().name()
562  'Bool'
563  >>> ArraySort(IntSort(), IntSort()).name()
564  'Array'
565  """
566  return _symbol2py(self.ctx, Z3_get_sort_name(self.ctx_ref(), self.ast))
567 

◆ subsort()

def subsort (   self,
  other 
)
Return `True` if `self` is a subsort of `other`.

>>> IntSort().subsort(RealSort())
True

Reimplemented in BitVecSortRef, ArithSortRef, and BoolSortRef.

Definition at line 535 of file z3py.py.

535  def subsort(self, other):
536  """Return `True` if `self` is a subsort of `other`.
537 
538  >>> IntSort().subsort(RealSort())
539  True
540  """
541  return False
542 
Z3_sort_to_ast
Z3_ast Z3_API Z3_sort_to_ast(Z3_context c, Z3_sort s)
Convert a Z3_sort into Z3_ast. This is just type casting.
Z3_get_ast_id
unsigned Z3_API Z3_get_ast_id(Z3_context c, Z3_ast t)
Return a unique identifier for t. The identifier is unique up to structural equality....
Z3_is_eq_sort
bool Z3_API Z3_is_eq_sort(Z3_context c, Z3_sort s1, Z3_sort s2)
compare sorts.
z3py.z3_debug
def z3_debug()
Definition: z3py.py:56
Z3_get_sort_name
Z3_symbol Z3_API Z3_get_sort_name(Z3_context c, Z3_sort d)
Return the sort name as a symbol.
z3py.is_expr
def is_expr(a)
Definition: z3py.py:1135