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__
 
def __del__ (self)
 
def __str__ (self)
 
def __repr__ (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 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.

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

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

Definition at line 594 of file z3py.py.

594  def as_ast(self):
595  return Z3_func_decl_to_ast(self.ctx_ref(), self.ast)
596 
def ctx_ref(self)
Definition: z3py.py:305
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 as_ast(self)
Definition: z3py.py:594
def as_func_decl (   self)

Definition at line 600 of file z3py.py.

600  def as_func_decl(self):
601  return self.ast
602 
def as_func_decl(self)
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__().

623  def domain(self, i):
624  """Return the sort of the argument `i` of a function declaration. This method assumes that `0 <= i < self.arity()`.
625 
626  >>> f = Function('f', IntSort(), RealSort(), BoolSort())
627  >>> f.domain(0)
628  Int
629  >>> f.domain(1)
630  Real
631  """
632  if __debug__:
633  _z3_assert(i < self.arity(), "Index out of bounds")
634  return _to_sort_ref(Z3_get_domain(self.ctx_ref(), self.ast, i), self.ctx)
635 
def domain(self, i)
Definition: z3py.py:623
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(self)
Definition: z3py.py:305
def arity(self)
Definition: z3py.py:614
def get_id (   self)

Definition at line 597 of file z3py.py.

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

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

603  def name(self):
604  """Return the name of the function declaration `self`.
605 
606  >>> f = Function('f', IntSort(), IntSort())
607  >>> f.name()
608  'f'
609  >>> isinstance(f.name(), str)
610  True
611  """
612  return _symbol2py(self.ctx, Z3_get_decl_name(self.ctx_ref(), self.ast))
613 
def name(self)
Definition: z3py.py:603
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(self)
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__().

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