Z3
Public Member Functions
FuncDeclRef Class Reference

Function Declarations. More...

+ Inheritance diagram for FuncDeclRef:

Public Member Functions

def as_ast (self)
 
def get_id (self)
 
def as_func_decl (self)
 
def name (self)
 
def arity (self)
 
def domain (self, i)
 
def range (self)
 
def kind (self)
 
def __call__ (self, args)
 
- Public Member Functions inherited from AstRef
def __init__ (self, ast, ctx=None)
 
def __del__ (self)
 
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 hash (self)
 
- Public Member Functions inherited from Z3PPObject
def use_pp (self)
 

Additional Inherited Members

- Data Fields inherited from AstRef
 ast
 
 ctx
 

Detailed Description

Function Declarations.

Function declaration. Every constant and function have an associated declaration.

The declaration assigns a name, a sort (i.e., type), and for function
the sort (i.e., type) of each of its arguments. Note that, in Z3,
a constant is a function with 0 arguments.

Definition at line 624 of file z3py.py.

Member Function Documentation

§ __call__()

def __call__ (   self,
  args 
)
Create a Z3 application expression using the function `self`, and the given arguments.

The arguments must be Z3 expressions. This method assumes that
the sorts of the elements in `args` match the sorts of the
domain. Limited coersion is supported.  For example, if
args[0] is a Python integer, and the function expects a Z3
integer, then the argument is automatically converted into a
Z3 integer.

>>> f = Function('f', IntSort(), RealSort(), BoolSort())
>>> x = Int('x')
>>> y = Real('y')
>>> f(x, y)
f(x, y)
>>> f(x, x)
f(x, ToReal(x))

Definition at line 694 of file z3py.py.

694  def __call__(self, *args):
695  """Create a Z3 application expression using the function `self`, and the given arguments.
696 
697  The arguments must be Z3 expressions. This method assumes that
698  the sorts of the elements in `args` match the sorts of the
699  domain. Limited coersion is supported. For example, if
700  args[0] is a Python integer, and the function expects a Z3
701  integer, then the argument is automatically converted into a
702  Z3 integer.
703 
704  >>> f = Function('f', IntSort(), RealSort(), BoolSort())
705  >>> x = Int('x')
706  >>> y = Real('y')
707  >>> f(x, y)
708  f(x, y)
709  >>> f(x, x)
710  f(x, ToReal(x))
711  """
712  args = _get_args(args)
713  num = len(args)
714  if __debug__:
715  _z3_assert(num == self.arity(), "Incorrect number of arguments to %s" % self)
716  _args = (Ast * num)()
717  saved = []
718  for i in range(num):
719  # self.domain(i).cast(args[i]) may create a new Z3 expression,
720  # then we must save in 'saved' to prevent it from being garbage collected.
721  tmp = self.domain(i).cast(args[i])
722  saved.append(tmp)
723  _args[i] = tmp.as_ast()
724  return _to_expr_ref(Z3_mk_app(self.ctx_ref(), self.ast, len(args), _args), self.ctx)
725 
Z3_ast Z3_API Z3_mk_app(Z3_context c, Z3_func_decl d, unsigned num_args, Z3_ast const args[])
Create a constant or function application.

§ arity()

def arity (   self)
Return the number of arguments of a function declaration. If `self` is a constant, then `self.arity()` is 0.

>>> f = Function('f', IntSort(), RealSort(), BoolSort())
>>> f.arity()
2

Definition at line 651 of file z3py.py.

Referenced by FuncDeclRef.__call__(), and FuncDeclRef.domain().

651  def arity(self):
652  """Return the number of arguments of a function declaration. If `self` is a constant, then `self.arity()` is 0.
653 
654  >>> f = Function('f', IntSort(), RealSort(), BoolSort())
655  >>> f.arity()
656  2
657  """
658  return int(Z3_get_arity(self.ctx_ref(), self.ast))
659 

§ as_ast()

def as_ast (   self)

Definition at line 631 of file z3py.py.

631  def as_ast(self):
632  return Z3_func_decl_to_ast(self.ctx_ref(), self.ast)
633 

§ as_func_decl()

def as_func_decl (   self)

Definition at line 637 of file z3py.py.

637  def as_func_decl(self):
638  return self.ast
639 

§ domain()

def domain (   self,
  i 
)
Return the sort of the argument `i` of a function declaration. This method assumes that `0 <= i < self.arity()`.

>>> f = Function('f', IntSort(), RealSort(), BoolSort())
>>> f.domain(0)
Int
>>> f.domain(1)
Real

Definition at line 660 of file z3py.py.

Referenced by FuncDeclRef.__call__().

660  def domain(self, i):
661  """Return the sort of the argument `i` of a function declaration. This method assumes that `0 <= i < self.arity()`.
662 
663  >>> f = Function('f', IntSort(), RealSort(), BoolSort())
664  >>> f.domain(0)
665  Int
666  >>> f.domain(1)
667  Real
668  """
669  if __debug__:
670  _z3_assert(i < self.arity(), "Index out of bounds")
671  return _to_sort_ref(Z3_get_domain(self.ctx_ref(), self.ast, i), self.ctx)
672 

§ get_id()

def get_id (   self)

Definition at line 634 of file z3py.py.

634  def get_id(self):
635  return Z3_get_ast_id(self.ctx_ref(), self.as_ast())
636 

§ kind()

def kind (   self)
Return the internal kind of a function declaration. It can be used to identify Z3 built-in functions such as addition, multiplication, etc.

>>> x = Int('x')
>>> d = (x + 1).decl()
>>> d.kind() == Z3_OP_ADD
True
>>> d.kind() == Z3_OP_MUL
False

Definition at line 682 of file z3py.py.

682  def kind(self):
683  """Return the internal kind of a function declaration. It can be used to identify Z3 built-in functions such as addition, multiplication, etc.
684 
685  >>> x = Int('x')
686  >>> d = (x + 1).decl()
687  >>> d.kind() == Z3_OP_ADD
688  True
689  >>> d.kind() == Z3_OP_MUL
690  False
691  """
692  return Z3_get_decl_kind(self.ctx_ref(), self.ast)
693 

§ name()

def name (   self)
Return the name of the function declaration `self`.

>>> f = Function('f', IntSort(), IntSort())
>>> f.name()
'f'
>>> isinstance(f.name(), str)
True

Definition at line 640 of file z3py.py.

640  def name(self):
641  """Return the name of the function declaration `self`.
642 
643  >>> f = Function('f', IntSort(), IntSort())
644  >>> f.name()
645  'f'
646  >>> isinstance(f.name(), str)
647  True
648  """
649  return _symbol2py(self.ctx, Z3_get_decl_name(self.ctx_ref(), self.ast))
650 

§ range()

def range (   self)
Return the sort of the range of a function declaration. For constants, this is the sort of the constant.

>>> f = Function('f', IntSort(), RealSort(), BoolSort())
>>> f.range()
Bool

Definition at line 673 of file z3py.py.

Referenced by FuncDeclRef.__call__().

673  def range(self):
674  """Return the sort of the range of a function declaration. For constants, this is the sort of the constant.
675 
676  >>> f = Function('f', IntSort(), RealSort(), BoolSort())
677  >>> f.range()
678  Bool
679  """
680  return _to_sort_ref(Z3_get_range(self.ctx_ref(), self.ast), self.ctx)
681