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 params (self)
 
def __call__ (self, args)
 
- Public Member Functions inherited from AstRef
def __init__ (self, ast, ctx=None)
 
def __del__ (self)
 
def __deepcopy__ (self, memo={})
 
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 622 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 716 of file z3py.py.

716  def __call__(self, *args):
717  """Create a Z3 application expression using the function `self`, and the given arguments.
718 
719  The arguments must be Z3 expressions. This method assumes that
720  the sorts of the elements in `args` match the sorts of the
721  domain. Limited coersion is supported. For example, if
722  args[0] is a Python integer, and the function expects a Z3
723  integer, then the argument is automatically converted into a
724  Z3 integer.
725 
726  >>> f = Function('f', IntSort(), RealSort(), BoolSort())
727  >>> x = Int('x')
728  >>> y = Real('y')
729  >>> f(x, y)
730  f(x, y)
731  >>> f(x, x)
732  f(x, ToReal(x))
733  """
734  args = _get_args(args)
735  num = len(args)
736  if __debug__:
737  _z3_assert(num == self.arity(), "Incorrect number of arguments to %s" % self)
738  _args = (Ast * num)()
739  saved = []
740  for i in range(num):
741  # self.domain(i).cast(args[i]) may create a new Z3 expression,
742  # then we must save in 'saved' to prevent it from being garbage collected.
743  tmp = self.domain(i).cast(args[i])
744  saved.append(tmp)
745  _args[i] = tmp.as_ast()
746  return _to_expr_ref(Z3_mk_app(self.ctx_ref(), self.ast, len(args), _args), self.ctx)
747 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:2813
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 649 of file z3py.py.

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

649  def arity(self):
650  """Return the number of arguments of a function declaration. If `self` is a constant, then `self.arity()` is 0.
651 
652  >>> f = Function('f', IntSort(), RealSort(), BoolSort())
653  >>> f.arity()
654  2
655  """
656  return int(Z3_get_arity(self.ctx_ref(), self.ast))
657 
unsigned Z3_API Z3_get_arity(Z3_context c, Z3_func_decl d)
Alias for Z3_get_domain_size.

§ as_ast()

def as_ast (   self)

Definition at line 629 of file z3py.py.

629  def as_ast(self):
630  return Z3_func_decl_to_ast(self.ctx_ref(), self.ast)
631 
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.

§ as_func_decl()

def as_func_decl (   self)

Definition at line 635 of file z3py.py.

635  def as_func_decl(self):
636  return self.ast
637 

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

Referenced by FuncDeclRef.__call__().

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

§ get_id()

def get_id (   self)

Definition at line 632 of file z3py.py.

632  def get_id(self):
633  return Z3_get_ast_id(self.ctx_ref(), self.as_ast())
634 
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.

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

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

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

638  def name(self):
639  """Return the name of the function declaration `self`.
640 
641  >>> f = Function('f', IntSort(), IntSort())
642  >>> f.name()
643  'f'
644  >>> isinstance(f.name(), str)
645  True
646  """
647  return _symbol2py(self.ctx, Z3_get_decl_name(self.ctx_ref(), self.ast))
648 
Z3_symbol Z3_API Z3_get_decl_name(Z3_context c, Z3_func_decl d)
Return the constant declaration name as a symbol.

§ params()

def params (   self)

Definition at line 692 of file z3py.py.

692  def params(self):
693  ctx = self.ctx
694  n = Z3_get_decl_num_parameters(self.ctx_ref(), self.ast)
695  result = [ None for i in range(n) ]
696  for i in range(n):
697  k = Z3_get_decl_parameter_kind(self.ctx_ref(), self.ast, i)
698  if k == Z3_PARAMETER_INT:
699  result[i] = Z3_get_decl_int_parameter(self.ctx_ref(), self.ast, i)
700  elif k == Z3_PARAMETER_DOUBLE:
701  result[i] = Z3_get_decl_double_parameter(self.ctx_ref(), self.ast, i)
702  elif k == Z3_PARAMETER_RATIONAL:
703  result[i] = Z3_get_decl_rational_parameter(self.ctx_ref(), self.ast, i)
704  elif k == Z3_PARAMETER_SYMBOL:
705  result[i] = Z3_get_decl_symbol_parameter(self.ctx_ref(), self.ast, i)
706  elif k == Z3_PARAMETER_SORT:
707  result[i] = SortRef(Z3_get_decl_sort_parameter(self.ctx_ref(), self.ast, i), ctx)
708  elif k == Z3_PARAMETER_AST:
709  result[i] = ExprRef(Z3_get_decl_ast_parameter(self.ctx_ref(), self.ast, i), ctx)
710  elif k == Z3_PARAMETER_FUNC_DECL:
711  result[i] = FuncDeclRef(Z3_get_decl_func_decl_parameter(self.ctx_ref(), self.ast, i), ctx)
712  else:
713  assert(False)
714  return result
715 
Z3_string Z3_API Z3_get_decl_rational_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the rational value, as a string, associated with a rational parameter.
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:2813
unsigned Z3_API Z3_get_decl_num_parameters(Z3_context c, Z3_func_decl d)
Return the number of parameters associated with a declaration.
Z3_parameter_kind Z3_API Z3_get_decl_parameter_kind(Z3_context c, Z3_func_decl d, unsigned idx)
Return the parameter type associated with a declaration.
Z3_symbol Z3_API Z3_get_decl_symbol_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the double value associated with an double parameter.
Z3_func_decl Z3_API Z3_get_decl_func_decl_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the expresson value associated with an expression parameter.
double Z3_API Z3_get_decl_double_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the double value associated with an double parameter.
Z3_ast Z3_API Z3_get_decl_ast_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the expresson value associated with an expression parameter.
int Z3_API Z3_get_decl_int_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the integer value associated with an integer parameter.
Z3_sort Z3_API Z3_get_decl_sort_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the sort value associated with a sort parameter.

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

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

671  def range(self):
672  """Return the sort of the range of a function declaration. For constants, this is the sort of the constant.
673 
674  >>> f = Function('f', IntSort(), RealSort(), BoolSort())
675  >>> f.range()
676  Bool
677  """
678  return _to_sort_ref(Z3_get_range(self.ctx_ref(), self.ast), self.ctx)
679 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:2813
Z3_sort Z3_API Z3_get_range(Z3_context c, Z3_func_decl d)
Return the range of the given declaration.