Z3
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 591 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 661 of file z3py.py.

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

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

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

Definition at line 598 of file z3py.py.

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

Definition at line 604 of file z3py.py.

605  def as_func_decl(self):
606  return self.ast
def as_func_decl
Definition: z3py.py:604
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 627 of file z3py.py.

Referenced by FuncDeclRef.__call__().

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

Definition at line 601 of file z3py.py.

602  def get_id(self):
603  return Z3_get_ast_id(self.ctx_ref(), self.as_ast())
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 as_ast
Definition: z3py.py:296
def ctx_ref
Definition: z3py.py:304
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 649 of file z3py.py.

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

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

Referenced by FuncDeclRef.__call__().

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