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__
 
def __del__ (self)
 
def __deepcopy__
 
def __str__ (self)
 
def __repr__ (self)
 
def __eq__ (self, other)
 
def __hash__ (self)
 
def __nonzero__ (self)
 
def __bool__ (self)
 
def sexpr (self)
 
def as_ast (self)
 
def get_id (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 960 of file z3py.py.

Member Function Documentation

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

Definition at line 1000 of file z3py.py.

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

1000  def __eq__(self, other):
1001  """Return a Z3 expression that represents the constraint `self == other`.
1002 
1003  If `other` is `None`, then this method simply returns `False`.
1004 
1005  >>> a = Int('a')
1006  >>> b = Int('b')
1007  >>> a == b
1008  a == b
1009  >>> a is None
1010  False
1011  """
1012  if other is None:
1013  return False
1014  a, b = _coerce_exprs(self, other)
1015  return BoolRef(Z3_mk_eq(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
1016 
def __eq__(self, other)
Definition: z3py.py:1000
def ctx_ref(self)
Definition: z3py.py:399
Z3_ast Z3_API Z3_mk_eq(Z3_context c, Z3_ast l, Z3_ast r)
Create an AST node representing l = r.
def __hash__ (   self)
Hash code. 

Definition at line 1017 of file z3py.py.

1017  def __hash__(self):
1018  """ Hash code. """
1019  return AstRef.__hash__(self)
1020 
def __hash__(self)
Definition: z3py.py:1017
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 1021 of file z3py.py.

1021  def __ne__(self, other):
1022  """Return a Z3 expression that represents the constraint `self != other`.
1023 
1024  If `other` is `None`, then this method simply returns `True`.
1025 
1026  >>> a = Int('a')
1027  >>> b = Int('b')
1028  >>> a != b
1029  a != b
1030  >>> a is not None
1031  True
1032  """
1033  if other is None:
1034  return True
1035  a, b = _coerce_exprs(self, other)
1036  _args, sz = _to_ast_array((a, b))
1037  return BoolRef(Z3_mk_distinct(self.ctx_ref(), 2, _args), self.ctx)
1038 
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]).
def __ne__(self, other)
Definition: z3py.py:1021
def ctx_ref(self)
Definition: z3py.py:399
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 1073 of file z3py.py.

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

1073  def arg(self, idx):
1074  """Return argument `idx` of the application `self`.
1075 
1076  This method assumes that `self` is a function application with at least `idx+1` arguments.
1077 
1078  >>> a = Int('a')
1079  >>> b = Int('b')
1080  >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort())
1081  >>> t = f(a, b, 0)
1082  >>> t.arg(0)
1083  a
1084  >>> t.arg(1)
1085  b
1086  >>> t.arg(2)
1087  0
1088  """
1089  if z3_debug():
1090  _z3_assert(is_app(self), "Z3 application expected")
1091  _z3_assert(idx < self.num_args(), "Invalid argument index")
1092  return _to_expr_ref(Z3_get_app_arg(self.ctx_ref(), self.as_ast(), idx), self.ctx)
1093 
def as_ast(self)
Definition: z3py.py:391
def is_app(a)
Definition: z3py.py:1235
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.
def num_args(self)
Definition: z3py.py:1057
def z3_debug()
Definition: z3py.py:64
def arg(self, idx)
Definition: z3py.py:1073
def ctx_ref(self)
Definition: z3py.py:399
def as_ast (   self)

Definition at line 971 of file z3py.py.

971  def as_ast(self):
972  return self.ast
973 
def as_ast(self)
Definition: z3py.py:971
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]

Definition at line 1094 of file z3py.py.

1094  def children(self):
1095  """Return a list containing the children of the given expression
1096 
1097  >>> a = Int('a')
1098  >>> b = Int('b')
1099  >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort())
1100  >>> t = f(a, b, 0)
1101  >>> t.children()
1102  [a, b, 0]
1103  """
1104  if is_app(self):
1105  return [self.arg(i) for i in range(self.num_args())]
1106  else:
1107  return []
1108 
1109 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3794
def is_app(a)
Definition: z3py.py:1235
def num_args(self)
Definition: z3py.py:1057
def arg(self, idx)
Definition: z3py.py:1073
def children(self)
Definition: z3py.py:1094
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 1042 of file z3py.py.

Referenced by ExprRef.params().

1042  def decl(self):
1043  """Return the Z3 function declaration associated with a Z3 application.
1044 
1045  >>> f = Function('f', IntSort(), IntSort())
1046  >>> a = Int('a')
1047  >>> t = f(a)
1048  >>> eq(t.decl(), f)
1049  True
1050  >>> (a + 1).decl()
1051  +
1052  """
1053  if z3_debug():
1054  _z3_assert(is_app(self), "Z3 application expected")
1055  return FuncDeclRef(Z3_get_app_decl(self.ctx_ref(), self.as_ast()), self.ctx)
1056 
Function Declarations.
Definition: z3py.py:717
def as_ast(self)
Definition: z3py.py:391
def is_app(a)
Definition: z3py.py:1235
Z3_func_decl Z3_API Z3_get_app_decl(Z3_context c, Z3_app a)
Return the declaration of a constant or function application.
def decl(self)
Definition: z3py.py:1042
def z3_debug()
Definition: z3py.py:64
def ctx_ref(self)
Definition: z3py.py:399
def get_id (   self)

Definition at line 974 of file z3py.py.

974  def get_id(self):
975  return Z3_get_ast_id(self.ctx_ref(), self.as_ast())
976 
def as_ast(self)
Definition: z3py.py:391
def get_id(self)
Definition: z3py.py:974
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. Thus, two ast nodes created by the same context and having the same children and same function symbols have the same identifiers. Ast nodes created in the same context, but having different children or different functions have different identifiers. Variables and quantifiers are also assigned different identifiers according to their structure.
def ctx_ref(self)
Definition: z3py.py:399
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 1057 of file z3py.py.

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

1057  def num_args(self):
1058  """Return the number of arguments of a Z3 application.
1059 
1060  >>> a = Int('a')
1061  >>> b = Int('b')
1062  >>> (a + b).num_args()
1063  2
1064  >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort())
1065  >>> t = f(a, b, 0)
1066  >>> t.num_args()
1067  3
1068  """
1069  if z3_debug():
1070  _z3_assert(is_app(self), "Z3 application expected")
1071  return int(Z3_get_app_num_args(self.ctx_ref(), self.as_ast()))
1072 
def as_ast(self)
Definition: z3py.py:391
def is_app(a)
Definition: z3py.py:1235
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...
def num_args(self)
Definition: z3py.py:1057
def z3_debug()
Definition: z3py.py:64
def ctx_ref(self)
Definition: z3py.py:399
def params (   self)

Definition at line 1039 of file z3py.py.

1039  def params(self):
1040  return self.decl().params()
1041 
def decl(self)
Definition: z3py.py:1042
def params(self)
Definition: z3py.py:1039
def sort (   self)
Return the sort of expression `self`.

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

Definition at line 977 of file z3py.py.

Referenced by ArrayRef.domain(), ArithRef.is_int(), ArithRef.is_real(), ArrayRef.range(), BitVecRef.size(), and ExprRef.sort_kind().

977  def sort(self):
978  """Return the sort of expression `self`.
979 
980  >>> x = Int('x')
981  >>> (x + 1).sort()
982  Int
983  >>> y = Real('y')
984  >>> (x + y).sort()
985  Real
986  """
987  return _sort(self.ctx, self.as_ast())
988 
def as_ast(self)
Definition: z3py.py:391
def sort(self)
Definition: z3py.py:977
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 989 of file z3py.py.

989  def sort_kind(self):
990  """Shorthand for `self.sort().kind()`.
991 
992  >>> a = Array('a', IntSort(), IntSort())
993  >>> a.sort_kind() == Z3_ARRAY_SORT
994  True
995  >>> a.sort_kind() == Z3_INT_SORT
996  False
997  """
998  return self.sort().kind()
999 
def sort_kind(self)
Definition: z3py.py:989
def sort(self)
Definition: z3py.py:977