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 kind (self)
 
def num_args (self)
 
def arg (self, idx)
 
def children (self)
 
def from_string (self, s)
 
def serialize (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)
 
def py_value (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 997 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 1037 of file z3py.py.

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

1037  def __eq__(self, other):
1038  """Return a Z3 expression that represents the constraint `self == other`.
1039 
1040  If `other` is `None`, then this method simply returns `False`.
1041 
1042  >>> a = Int('a')
1043  >>> b = Int('b')
1044  >>> a == b
1045  a == b
1046  >>> a is None
1047  False
1048  """
1049  if other is None:
1050  return False
1051  a, b = _coerce_exprs(self, other)
1052  return BoolRef(Z3_mk_eq(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
1053 
def __eq__(self, other)
Definition: z3py.py:1037
def ctx_ref(self)
Definition: z3py.py:410
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 1054 of file z3py.py.

1054  def __hash__(self):
1055  """ Hash code. """
1056  return AstRef.__hash__(self)
1057 
def __hash__(self)
Definition: z3py.py:1054
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 1058 of file z3py.py.

1058  def __ne__(self, other):
1059  """Return a Z3 expression that represents the constraint `self != other`.
1060 
1061  If `other` is `None`, then this method simply returns `True`.
1062 
1063  >>> a = Int('a')
1064  >>> b = Int('b')
1065  >>> a != b
1066  a != b
1067  >>> a is not None
1068  True
1069  """
1070  if other is None:
1071  return True
1072  a, b = _coerce_exprs(self, other)
1073  _args, sz = _to_ast_array((a, b))
1074  return BoolRef(Z3_mk_distinct(self.ctx_ref(), 2, _args), self.ctx)
1075 
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:1058
def ctx_ref(self)
Definition: z3py.py:410
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 1117 of file z3py.py.

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

1117  def arg(self, idx):
1118  """Return argument `idx` of the application `self`.
1119 
1120  This method assumes that `self` is a function application with at least `idx+1` arguments.
1121 
1122  >>> a = Int('a')
1123  >>> b = Int('b')
1124  >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort())
1125  >>> t = f(a, b, 0)
1126  >>> t.arg(0)
1127  a
1128  >>> t.arg(1)
1129  b
1130  >>> t.arg(2)
1131  0
1132  """
1133  if z3_debug():
1134  _z3_assert(is_app(self), "Z3 application expected")
1135  _z3_assert(idx < self.num_args(), "Invalid argument index")
1136  return _to_expr_ref(Z3_get_app_arg(self.ctx_ref(), self.as_ast(), idx), self.ctx)
1137 
def as_ast(self)
Definition: z3py.py:402
def is_app(a)
Definition: z3py.py:1308
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:1101
def z3_debug()
Definition: z3py.py:70
def arg(self, idx)
Definition: z3py.py:1117
def ctx_ref(self)
Definition: z3py.py:410
def as_ast (   self)

Definition at line 1008 of file z3py.py.

1008  def as_ast(self):
1009  return self.ast
1010 
def as_ast(self)
Definition: z3py.py:1008
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 1138 of file z3py.py.

1138  def children(self):
1139  """Return a list containing the children of the given expression
1140 
1141  >>> a = Int('a')
1142  >>> b = Int('b')
1143  >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort())
1144  >>> t = f(a, b, 0)
1145  >>> t.children()
1146  [a, b, 0]
1147  """
1148  if is_app(self):
1149  return [self.arg(i) for i in range(self.num_args())]
1150  else:
1151  return []
1152 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:4136
def is_app(a)
Definition: z3py.py:1308
def num_args(self)
Definition: z3py.py:1101
def arg(self, idx)
Definition: z3py.py:1117
def children(self)
Definition: z3py.py:1138
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 1079 of file z3py.py.

Referenced by ExprRef.params().

1079  def decl(self):
1080  """Return the Z3 function declaration associated with a Z3 application.
1081 
1082  >>> f = Function('f', IntSort(), IntSort())
1083  >>> a = Int('a')
1084  >>> t = f(a)
1085  >>> eq(t.decl(), f)
1086  True
1087  >>> (a + 1).decl()
1088  +
1089  """
1090  if z3_debug():
1091  _z3_assert(is_app(self), "Z3 application expected")
1092  return FuncDeclRef(Z3_get_app_decl(self.ctx_ref(), self.as_ast()), self.ctx)
1093 
Function Declarations.
Definition: z3py.py:754
def as_ast(self)
Definition: z3py.py:402
def is_app(a)
Definition: z3py.py:1308
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:1079
def z3_debug()
Definition: z3py.py:70
def ctx_ref(self)
Definition: z3py.py:410
def from_string (   self,
  s 
)

Definition at line 1153 of file z3py.py.

1153  def from_string(self, s):
1154  pass
1155 
def from_string(self, s)
Definition: z3py.py:1153
def get_id (   self)

Definition at line 1011 of file z3py.py.

1011  def get_id(self):
1012  return Z3_get_ast_id(self.ctx_ref(), self.as_ast())
1013 
def as_ast(self)
Definition: z3py.py:402
def get_id(self)
Definition: z3py.py:1011
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:410
def kind (   self)
Return the Z3 internal kind of a function application.

Definition at line 1094 of file z3py.py.

Referenced by ExprRef.sort_kind().

1094  def kind(self):
1095  """Return the Z3 internal kind of a function application."""
1096  if z3_debug():
1097  _z3_assert(is_app(self), "Z3 application expected")
1098  return Z3_get_decl_kind(self.ctx_ref(), Z3_get_app_decl(self.ctx_ref(), self.ast))
1099 
1100 
Z3_decl_kind Z3_API Z3_get_decl_kind(Z3_context c, Z3_func_decl d)
Return declaration kind corresponding to declaration.
def is_app(a)
Definition: z3py.py:1308
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 z3_debug()
Definition: z3py.py:70
def kind(self)
Definition: z3py.py:1094
def ctx_ref(self)
Definition: z3py.py:410
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 1101 of file z3py.py.

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

1101  def num_args(self):
1102  """Return the number of arguments of a Z3 application.
1103 
1104  >>> a = Int('a')
1105  >>> b = Int('b')
1106  >>> (a + b).num_args()
1107  2
1108  >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort())
1109  >>> t = f(a, b, 0)
1110  >>> t.num_args()
1111  3
1112  """
1113  if z3_debug():
1114  _z3_assert(is_app(self), "Z3 application expected")
1115  return int(Z3_get_app_num_args(self.ctx_ref(), self.as_ast()))
1116 
def as_ast(self)
Definition: z3py.py:402
def is_app(a)
Definition: z3py.py:1308
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:1101
def z3_debug()
Definition: z3py.py:70
def ctx_ref(self)
Definition: z3py.py:410
def params (   self)

Definition at line 1076 of file z3py.py.

1076  def params(self):
1077  return self.decl().params()
1078 
def decl(self)
Definition: z3py.py:1079
def params(self)
Definition: z3py.py:1076
def serialize (   self)

Definition at line 1156 of file z3py.py.

1156  def serialize(self):
1157  s = Solver()
1158  f = Function('F', self.sort(), BoolSort(self.ctx))
1159  s.add(f(self))
1160  return s.sexpr()
1161 
def BoolSort
Definition: z3py.py:1762
def Function(name, sig)
Definition: z3py.py:899
def serialize(self)
Definition: z3py.py:1156
def sort(self)
Definition: z3py.py:1014
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 1014 of file z3py.py.

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

1014  def sort(self):
1015  """Return the sort of expression `self`.
1016 
1017  >>> x = Int('x')
1018  >>> (x + 1).sort()
1019  Int
1020  >>> y = Real('y')
1021  >>> (x + y).sort()
1022  Real
1023  """
1024  return _sort(self.ctx, self.as_ast())
1025 
def as_ast(self)
Definition: z3py.py:402
def sort(self)
Definition: z3py.py:1014
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 1026 of file z3py.py.

1026  def sort_kind(self):
1027  """Shorthand for `self.sort().kind()`.
1028 
1029  >>> a = Array('a', IntSort(), IntSort())
1030  >>> a.sort_kind() == Z3_ARRAY_SORT
1031  True
1032  >>> a.sort_kind() == Z3_INT_SORT
1033  False
1034  """
1035  return self.sort().kind()
1036 
def sort_kind(self)
Definition: z3py.py:1026
def sort(self)
Definition: z3py.py:1014
def kind(self)
Definition: z3py.py:1094