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

Public Member Functions

 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

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

Definition at line 590 of file z3py.py.

Member Function Documentation

◆ __eq__()

__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

Definition at line 650 of file z3py.py.

650 def __eq__(self, other):
651 """Return `True` if `self` and `other` are the same Z3 sort.
652
653 >>> p = Bool('p')
654 >>> p.sort() == BoolSort()
655 True
656 >>> p.sort() == IntSort()
657 False
658 """
659 if other is None:
660 return False
661 return Z3_is_eq_sort(self.ctx_ref(), self.ast, other.ast)
662
bool Z3_API Z3_is_eq_sort(Z3_context c, Z3_sort s1, Z3_sort s2)
compare sorts.

Referenced by CheckSatResult.__ne__().

◆ __gt__()

__gt__ ( self,
other )
Create the function space Array(self, other)

Definition at line 674 of file z3py.py.

674 def __gt__(self, other):
675 """Create the function space Array(self, other)"""
676 return ArraySort(self, other)
677

◆ __hash__()

__hash__ ( self)
Hash code. 

Definition at line 678 of file z3py.py.

678 def __hash__(self):
679 """ Hash code. """
680 return AstRef.__hash__(self)
681
682

◆ __ne__()

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

663 def __ne__(self, other):
664 """Return `True` if `self` and `other` are not the same Z3 sort.
665
666 >>> p = Bool('p')
667 >>> p.sort() != BoolSort()
668 False
669 >>> p.sort() != IntSort()
670 True
671 """
672 return not Z3_is_eq_sort(self.ctx_ref(), self.ast, other.ast)
673

◆ as_ast()

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

Reimplemented from AstRef.

Definition at line 593 of file z3py.py.

593 def as_ast(self):
594 # Z3_sort_to_ast is only a pointer cast, so do it here instead of calling into Z3.
595 return Ast.from_buffer_copy(self.ast)
596

◆ cast()

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 ArithSortRef, BitVecSortRef, BoolSortRef, ComplexSortRef, FiniteFieldSortRef, FiniteSetSortRef, FPSortRef, and TypeVarRef.

Definition at line 625 of file z3py.py.

625 def cast(self, val):
626 """Try to cast `val` as an element of sort `self`.
627
628 This method is used in Z3Py to convert Python objects such as integers,
629 floats, longs and strings into Z3 expressions.
630
631 >>> x = Int('x')
632 >>> RealSort().cast(x)
633 ToReal(x)
634 """
635 if z3_debug():
636 _z3_assert(is_expr(val), "Z3 expression expected")
637 _z3_assert(self.eq(val.sort()), "Sort mismatch")
638 return val
639

◆ get_id()

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

Reimplemented from AstRef.

Definition at line 597 of file z3py.py.

597 def get_id(self):
598 return Z3_get_ast_id(self.ctx_ref(), self.as_ast())
599
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....

◆ kind()

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

600 def kind(self):
601 """Return the Z3 internal kind of a sort.
602 This method can be used to test if `self` is one of the Z3 builtin sorts.
603
604 >>> b = BoolSort()
605 >>> b.kind() == Z3_BOOL_SORT
606 True
607 >>> b.kind() == Z3_INT_SORT
608 False
609 >>> A = ArraySort(IntSort(), IntSort())
610 >>> A.kind() == Z3_ARRAY_SORT
611 True
612 >>> A.kind() == Z3_INT_SORT
613 False
614 """
615 return _sort_kind(self.ctx, self.ast)
616

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

◆ name()

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

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

Definition at line 640 of file z3py.py.

640 def name(self):
641 """Return the name (string) of sort `self`.
642
643 >>> BoolSort().name()
644 'Bool'
645 >>> ArraySort(IntSort(), IntSort()).name()
646 'Array'
647 """
648 return _symbol2py(self.ctx, Z3_get_sort_name(self.ctx_ref(), self.ast))
649
Z3_symbol Z3_API Z3_get_sort_name(Z3_context c, Z3_sort d)
Return the sort name as a symbol.

◆ subsort()

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

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

Reimplemented in ArithSortRef, BitVecSortRef, BoolSortRef, ComplexSortRef, FiniteSetSortRef, and TypeVarRef.

Definition at line 617 of file z3py.py.

617 def subsort(self, other):
618 """Return `True` if `self` is a subsort of `other`.
619
620 >>> IntSort().subsort(RealSort())
621 True
622 """
623 return False
624