Z3
Public Member Functions
ExprRef Class Reference

Expressions. More...

+ Inheritance diagram for ExprRef:

Public Member Functions

def as_ast (self)
 
def get_id (self)
 
def sort (self)
 
def sort_kind (self)
 
def __eq__ (self, other)
 
def __hash__ (self)
 
def __ne__ (self, other)
 
def params (self)
 
def decl (self)
 
def num_args (self)
 
def arg (self, idx)
 
def children (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

Expressions.

Constraints, formulas and terms are expressions in Z3.

Expressions are ASTs. Every expression has a sort.
There are three main kinds of expressions:
function applications, quantifiers and bounded variables.
A constant is a function application with 0 arguments.
For quantifier free problems, all expressions are
function applications.

Definition at line 893 of file z3py.py.

Member Function Documentation

◆ __eq__()

def __eq__ (   self,
  other 
)
Return a Z3 expression that represents the constraint `self == other`.

If `other` is `None`, then this method simply returns `False`.

>>> a = Int('a')
>>> b = Int('b')
>>> a == b
a == b
>>> a is None
False

Reimplemented from AstRef.

Definition at line 932 of file z3py.py.

932  def __eq__(self, other):
933  """Return a Z3 expression that represents the constraint `self == other`.
934 
935  If `other` is `None`, then this method simply returns `False`.
936 
937  >>> a = Int('a')
938  >>> b = Int('b')
939  >>> a == b
940  a == b
941  >>> a is None
942  False
943  """
944  if other is None:
945  return False
946  a, b = _coerce_exprs(self, other)
947  return BoolRef(Z3_mk_eq(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
948 

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

◆ __hash__()

def __hash__ (   self)
Hash code. 

Reimplemented from AstRef.

Definition at line 949 of file z3py.py.

949  def __hash__(self):
950  """ Hash code. """
951  return AstRef.__hash__(self)
952 

◆ __ne__()

def __ne__ (   self,
  other 
)
Return a Z3 expression that represents the constraint `self != other`.

If `other` is `None`, then this method simply returns `True`.

>>> a = Int('a')
>>> b = Int('b')
>>> a != b
a != b
>>> a is not None
True

Definition at line 953 of file z3py.py.

953  def __ne__(self, other):
954  """Return a Z3 expression that represents the constraint `self != other`.
955 
956  If `other` is `None`, then this method simply returns `True`.
957 
958  >>> a = Int('a')
959  >>> b = Int('b')
960  >>> a != b
961  a != b
962  >>> a is not None
963  True
964  """
965  if other is None:
966  return True
967  a, b = _coerce_exprs(self, other)
968  _args, sz = _to_ast_array((a, b))
969  return BoolRef(Z3_mk_distinct(self.ctx_ref(), 2, _args), self.ctx)
970 

◆ arg()

def arg (   self,
  idx 
)
Return argument `idx` of the application `self`.

This method assumes that `self` is a function application with at least `idx+1` arguments.

>>> a = Int('a')
>>> b = Int('b')
>>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort())
>>> t = f(a, b, 0)
>>> t.arg(0)
a
>>> t.arg(1)
b
>>> t.arg(2)
0

Definition at line 1005 of file z3py.py.

1005  def arg(self, idx):
1006  """Return argument `idx` of the application `self`.
1007 
1008  This method assumes that `self` is a function application with at least `idx+1` arguments.
1009 
1010  >>> a = Int('a')
1011  >>> b = Int('b')
1012  >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort())
1013  >>> t = f(a, b, 0)
1014  >>> t.arg(0)
1015  a
1016  >>> t.arg(1)
1017  b
1018  >>> t.arg(2)
1019  0
1020  """
1021  if z3_debug():
1022  _z3_assert(is_app(self), "Z3 application expected")
1023  _z3_assert(idx < self.num_args(), "Invalid argument index")
1024  return _to_expr_ref(Z3_get_app_arg(self.ctx_ref(), self.as_ast(), idx), self.ctx)
1025 

Referenced by AstRef.__bool__(), and ExprRef.children().

◆ as_ast()

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

Reimplemented from AstRef.

Reimplemented in QuantifierRef, and PatternRef.

Definition at line 903 of file z3py.py.

903  def as_ast(self):
904  return self.ast
905 

◆ children()

def children (   self)
Return a list containing the children of the given expression

>>> a = Int('a')
>>> b = Int('b')
>>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort())
>>> t = f(a, b, 0)
>>> t.children()
[a, b, 0]

Reimplemented in QuantifierRef.

Definition at line 1026 of file z3py.py.

1026  def children(self):
1027  """Return a list containing the children of the given expression
1028 
1029  >>> a = Int('a')
1030  >>> b = Int('b')
1031  >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort())
1032  >>> t = f(a, b, 0)
1033  >>> t.children()
1034  [a, b, 0]
1035  """
1036  if is_app(self):
1037  return [self.arg(i) for i in range(self.num_args())]
1038  else:
1039  return []
1040 

◆ decl()

def decl (   self)
Return the Z3 function declaration associated with a Z3 application.

>>> f = Function('f', IntSort(), IntSort())
>>> a = Int('a')
>>> t = f(a)
>>> eq(t.decl(), f)
True
>>> (a + 1).decl()
+

Definition at line 974 of file z3py.py.

974  def decl(self):
975  """Return the Z3 function declaration associated with a Z3 application.
976 
977  >>> f = Function('f', IntSort(), IntSort())
978  >>> a = Int('a')
979  >>> t = f(a)
980  >>> eq(t.decl(), f)
981  True
982  >>> (a + 1).decl()
983  +
984  """
985  if z3_debug():
986  _z3_assert(is_app(self), "Z3 application expected")
987  return FuncDeclRef(Z3_get_app_decl(self.ctx_ref(), self.as_ast()), self.ctx)
988 

Referenced by ExprRef.params().

◆ get_id()

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

Reimplemented from AstRef.

Reimplemented in QuantifierRef, and PatternRef.

Definition at line 906 of file z3py.py.

906  def get_id(self):
907  return Z3_get_ast_id(self.ctx_ref(), self.as_ast())
908 

◆ num_args()

def num_args (   self)
Return the number of arguments of a Z3 application.

>>> a = Int('a')
>>> b = Int('b')
>>> (a + b).num_args()
2
>>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort())
>>> t = f(a, b, 0)
>>> t.num_args()
3

Definition at line 989 of file z3py.py.

989  def num_args(self):
990  """Return the number of arguments of a Z3 application.
991 
992  >>> a = Int('a')
993  >>> b = Int('b')
994  >>> (a + b).num_args()
995  2
996  >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort())
997  >>> t = f(a, b, 0)
998  >>> t.num_args()
999  3
1000  """
1001  if z3_debug():
1002  _z3_assert(is_app(self), "Z3 application expected")
1003  return int(Z3_get_app_num_args(self.ctx_ref(), self.as_ast()))
1004 

Referenced by AstRef.__bool__(), ExprRef.arg(), FuncEntry.arg_value(), FuncEntry.as_list(), and ExprRef.children().

◆ params()

def params (   self)

Definition at line 971 of file z3py.py.

971  def params(self):
972  return self.decl().params()
973 

◆ sort()

def sort (   self)
Return the sort of expression `self`.

>>> x = Int('x')
>>> (x + 1).sort()
Int
>>> y = Real('y')
>>> (x + y).sort()
Real

Reimplemented in SeqRef, FPRef, FiniteDomainRef, DatatypeRef, ArrayRef, BitVecRef, ArithRef, QuantifierRef, and BoolRef.

Definition at line 909 of file z3py.py.

909  def sort(self):
910  """Return the sort of expression `self`.
911 
912  >>> x = Int('x')
913  >>> (x + 1).sort()
914  Int
915  >>> y = Real('y')
916  >>> (x + y).sort()
917  Real
918  """
919  return _sort(self.ctx, self.as_ast())
920 

Referenced by QuantifierRef.__getitem__(), FPNumRef.as_string(), ArrayRef.domain(), FPRef.ebits(), ArithRef.is_int(), ArithRef.is_real(), ArrayRef.range(), FPRef.sbits(), BitVecRef.size(), and ExprRef.sort_kind().

◆ sort_kind()

def sort_kind (   self)
Shorthand for `self.sort().kind()`.

>>> a = Array('a', IntSort(), IntSort())
>>> a.sort_kind() == Z3_ARRAY_SORT
True
>>> a.sort_kind() == Z3_INT_SORT
False

Definition at line 921 of file z3py.py.

921  def sort_kind(self):
922  """Shorthand for `self.sort().kind()`.
923 
924  >>> a = Array('a', IntSort(), IntSort())
925  >>> a.sort_kind() == Z3_ARRAY_SORT
926  True
927  >>> a.sort_kind() == Z3_INT_SORT
928  False
929  """
930  return self.sort().kind()
931 
z3::range
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3515
Z3_get_app_num_args
unsigned Z3_API Z3_get_app_num_args(Z3_context c, Z3_app a)
Return the number of argument of an application. If t is an constant, then the number of arguments is...
Z3_get_app_decl
Z3_func_decl Z3_API Z3_get_app_decl(Z3_context c, Z3_app a)
Return the declaration of a constant or function application.
Z3_mk_distinct
Z3_ast Z3_API Z3_mk_distinct(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing distinct(args[0], ..., args[num_args-1]).
z3py.is_app
def is_app(a)
Definition: z3py.py:1157
Z3_mk_eq
Z3_ast Z3_API Z3_mk_eq(Z3_context c, Z3_ast l, Z3_ast r)
Create an AST node representing l = r.
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....
z3py.z3_debug
def z3_debug()
Definition: z3py.py:56
Z3_get_app_arg
Z3_ast Z3_API Z3_get_app_arg(Z3_context c, Z3_app a, unsigned i)
Return the i-th argument of the given application.