Z3
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Public Member Functions
FuncDeclRef Class Reference

Function Declarations. More...

+ Inheritance diagram for FuncDeclRef:

Public Member Functions

def as_ast
 
def get_id
 
def as_func_decl
 
def name
 
def arity
 
def domain
 
def range
 
def kind
 
def __call__
 
- Public Member Functions inherited from AstRef
def __init__
 
def __del__
 
def __str__
 
def __repr__
 
def sexpr
 
def as_ast
 
def get_id
 
def ctx_ref
 
def eq
 
def translate
 
def hash
 
- Public Member Functions inherited from Z3PPObject
def use_pp
 

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

Member Function Documentation

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

658  def __call__(self, *args):
659  """Create a Z3 application expression using the function `self`, and the given arguments.
660 
661  The arguments must be Z3 expressions. This method assumes that
662  the sorts of the elements in `args` match the sorts of the
663  domain. Limited coersion is supported. For example, if
664  args[0] is a Python integer, and the function expects a Z3
665  integer, then the argument is automatically converted into a
666  Z3 integer.
667 
668  >>> f = Function('f', IntSort(), RealSort(), BoolSort())
669  >>> x = Int('x')
670  >>> y = Real('y')
671  >>> f(x, y)
672  f(x, y)
673  >>> f(x, x)
674  f(x, ToReal(x))
675  """
676  args = _get_args(args)
677  num = len(args)
678  if __debug__:
679  _z3_assert(num == self.arity(), "Incorrect number of arguments to %s" % self)
680  _args = (Ast * num)()
681  saved = []
682  for i in range(num):
683  # self.domain(i).cast(args[i]) may create a new Z3 expression,
684  # then we must save in 'saved' to prevent it from being garbage collected.
685  tmp = self.domain(i).cast(args[i])
686  saved.append(tmp)
687  _args[i] = tmp.as_ast()
688  return _to_expr_ref(Z3_mk_app(self.ctx_ref(), self.ast, len(args), _args), self.ctx)
def __call__
Definition: z3py.py:657
def ctx_ref
Definition: z3py.py:305
Z3_ast Z3_API Z3_mk_app(__in Z3_context c, __in Z3_func_decl d, __in unsigned num_args, __in_ecount(num_args) Z3_ast const args[])
Create a constant or function application.
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 614 of file z3py.py.

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

615  def arity(self):
616  """Return the number of arguments of a function declaration. If `self` is a constant, then `self.arity()` is 0.
617 
618  >>> f = Function('f', IntSort(), RealSort(), BoolSort())
619  >>> f.arity()
620  2
621  """
622  return int(Z3_get_arity(self.ctx_ref(), self.ast))
unsigned Z3_API Z3_get_arity(__in Z3_context c, __in Z3_func_decl d)
Alias for Z3_get_domain_size.
def ctx_ref
Definition: z3py.py:305
def as_ast (   self)

Definition at line 594 of file z3py.py.

595  def as_ast(self):
596  return Z3_func_decl_to_ast(self.ctx_ref(), self.ast)
Z3_ast Z3_API Z3_func_decl_to_ast(__in Z3_context c, __in Z3_func_decl f)
Convert a Z3_func_decl into Z3_ast. This is just type casting.
def ctx_ref
Definition: z3py.py:305
def as_func_decl (   self)

Definition at line 600 of file z3py.py.

601  def as_func_decl(self):
602  return self.ast
def as_func_decl
Definition: z3py.py:600
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 623 of file z3py.py.

Referenced by FuncDeclRef.__call__(), and ArrayRef.__getitem__().

624  def domain(self, i):
625  """Return the sort of the argument `i` of a function declaration. This method assumes that `0 <= i < self.arity()`.
626 
627  >>> f = Function('f', IntSort(), RealSort(), BoolSort())
628  >>> f.domain(0)
629  Int
630  >>> f.domain(1)
631  Real
632  """
633  if __debug__:
634  _z3_assert(i < self.arity(), "Index out of bounds")
635  return _to_sort_ref(Z3_get_domain(self.ctx_ref(), self.ast, i), self.ctx)
Z3_sort Z3_API Z3_get_domain(__in Z3_context c, __in Z3_func_decl d, __in unsigned i)
Return the sort of the i-th parameter of the given function declaration.
def ctx_ref
Definition: z3py.py:305
def get_id (   self)

Definition at line 597 of file z3py.py.

598  def get_id(self):
599  return Z3_get_ast_id(self.ctx_ref(), self.as_ast())
unsigned Z3_API Z3_get_ast_id(__in Z3_context c, Z3_ast t)
Return a unique identifier for t.
def as_ast
Definition: z3py.py:296
def ctx_ref
Definition: z3py.py:305
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 645 of file z3py.py.

646  def kind(self):
647  """Return the internal kind of a function declaration. It can be used to identify Z3 built-in functions such as addition, multiplication, etc.
648 
649  >>> x = Int('x')
650  >>> d = (x + 1).decl()
651  >>> d.kind() == Z3_OP_ADD
652  True
653  >>> d.kind() == Z3_OP_MUL
654  False
655  """
656  return Z3_get_decl_kind(self.ctx_ref(), self.ast)
Z3_decl_kind Z3_API Z3_get_decl_kind(__in Z3_context c, __in Z3_func_decl d)
Return declaration kind corresponding to declaration.
def ctx_ref
Definition: z3py.py:305
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 603 of file z3py.py.

604  def name(self):
605  """Return the name of the function declaration `self`.
606 
607  >>> f = Function('f', IntSort(), IntSort())
608  >>> f.name()
609  'f'
610  >>> isinstance(f.name(), str)
611  True
612  """
613  return _symbol2py(self.ctx, Z3_get_decl_name(self.ctx_ref(), self.ast))
Z3_symbol Z3_API Z3_get_decl_name(__in Z3_context c, __in Z3_func_decl d)
Return the constant declaration name as a symbol.
def ctx_ref
Definition: z3py.py:305
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 636 of file z3py.py.

Referenced by FuncDeclRef.__call__().

637  def range(self):
638  """Return the sort of the range of a function declaration. For constants, this is the sort of the constant.
639 
640  >>> f = Function('f', IntSort(), RealSort(), BoolSort())
641  >>> f.range()
642  Bool
643  """
644  return _to_sort_ref(Z3_get_range(self.ctx_ref(), self.ast), self.ctx)
Z3_sort Z3_API Z3_get_range(__in Z3_context c, __in Z3_func_decl d)
Return the range of the given declaration.
def ctx_ref
Definition: z3py.py:305