Z3
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
Public Member Functions
ExprRef Class Reference

Expressions. More...

+ Inheritance diagram for ExprRef:

Public Member Functions

def as_ast
def get_id
def sort
def sort_kind
def __eq__
def __ne__
def decl
def num_args
def arg
def children

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 736 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 == None
False

Definition at line 775 of file z3py.py.

Referenced by Probe.__ne__().

00775 
00776     def __eq__(self, other):
00777         """Return a Z3 expression that represents the constraint `self == other`.
00778 
00779         If `other` is `None`, then this method simply returns `False`. 
00780 
00781         >>> a = Int('a')
00782         >>> b = Int('b')
00783         >>> a == b
00784         a == b
00785         >>> a == None
00786         False
00787         """
00788         if other == None:
00789             return False
00790         a, b = _coerce_exprs(self, other)
00791         return BoolRef(Z3_mk_eq(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)

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 != None
True

Reimplemented in FPRef.

Definition at line 792 of file z3py.py.

00792 
00793     def __ne__(self, other):
00794         """Return a Z3 expression that represents the constraint `self != other`.
00795         
00796         If `other` is `None`, then this method simply returns `True`. 
00797 
00798         >>> a = Int('a')
00799         >>> b = Int('b')
00800         >>> a != b
00801         a != b
00802         >>> a != None
00803         True
00804         """
00805         if other == None:
00806             return True
00807         a, b = _coerce_exprs(self, other)
00808         _args, sz = _to_ast_array((a, b))
00809         return BoolRef(Z3_mk_distinct(self.ctx_ref(), 2, _args), self.ctx)

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

Referenced by ExprRef.children().

00841 
00842     def arg(self, idx):
00843         """Return argument `idx` of the application `self`. 
00844 
00845         This method assumes that `self` is a function application with at least `idx+1` arguments.
00846 
00847         >>> a = Int('a')
00848         >>> b = Int('b')
00849         >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort())
00850         >>> t = f(a, b, 0)
00851         >>> t.arg(0)
00852         a
00853         >>> t.arg(1)
00854         b
00855         >>> t.arg(2)
00856         0
00857         """
00858         if __debug__:
00859             _z3_assert(is_app(self), "Z3 application expected")
00860             _z3_assert(idx < self.num_args(), "Invalid argument index")
00861         return _to_expr_ref(Z3_get_app_arg(self.ctx_ref(), self.as_ast(), idx), self.ctx)

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

Referenced by ExprRef.arg(), ExprRef.decl(), ExprRef.get_id(), ExprRef.num_args(), ExprRef.sort(), and BoolRef.sort().

00746 
00747     def as_ast(self):
00748         return self.ast

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

00862 
00863     def children(self):
00864         """Return a list containing the children of the given expression
00865 
00866         >>> a = Int('a')
00867         >>> b = Int('b')
00868         >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort())
00869         >>> t = f(a, b, 0)
00870         >>> t.children()
00871         [a, b, 0]
00872         """
00873         if is_app(self):
00874             return [self.arg(i) for i in range(self.num_args())]
00875         else:
00876             return []

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

00810 
00811     def decl(self):
00812         """Return the Z3 function declaration associated with a Z3 application.
00813         
00814         >>> f = Function('f', IntSort(), IntSort())
00815         >>> a = Int('a')
00816         >>> t = f(a)
00817         >>> eq(t.decl(), f)
00818         True
00819         >>> (a + 1).decl()
00820         +
00821         """
00822         if __debug__:
00823             _z3_assert(is_app(self), "Z3 application expected")
00824         return FuncDeclRef(Z3_get_app_decl(self.ctx_ref(), self.as_ast()), self.ctx)
    
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 749 of file z3py.py.

00749 
00750     def get_id(self):
00751         return Z3_get_ast_id(self.ctx_ref(), self.as_ast())

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

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

00825 
00826     def num_args(self):
00827         """Return the number of arguments of a Z3 application.
00828 
00829         >>> a = Int('a')
00830         >>> b = Int('b')
00831         >>> (a + b).num_args()
00832         2
00833         >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort())
00834         >>> t = f(a, b, 0)
00835         >>> t.num_args()
00836         3
00837         """
00838         if __debug__:
00839             _z3_assert(is_app(self), "Z3 application expected")
00840         return int(Z3_get_app_num_args(self.ctx_ref(), self.as_ast()))

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 FPRef, DatatypeRef, ArrayRef, BitVecRef, ArithRef, QuantifierRef, and BoolRef.

Definition at line 752 of file z3py.py.

Referenced by ArrayRef.domain(), ArrayRef.range(), and ExprRef.sort_kind().

00752 
00753     def sort(self):
00754         """Return the sort of expression `self`.
00755         
00756         >>> x = Int('x')
00757         >>> (x + 1).sort()
00758         Int
00759         >>> y = Real('y')
00760         >>> (x + y).sort()
00761         Real
00762         """
00763         return _sort(self.ctx, self.as_ast())

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

00764 
00765     def sort_kind(self):
00766         """Shorthand for `self.sort().kind()`.
00767         
00768         >>> a = Array('a', IntSort(), IntSort())
00769         >>> a.sort_kind() == Z3_ARRAY_SORT
00770         True
00771         >>> a.sort_kind() == Z3_INT_SORT
00772         False
00773         """
00774         return self.sort().kind()

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines