Function Declarations.
More...
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 661 of file z3py.py.
◆ __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 coercion 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 755 of file z3py.py.
755 def __call__(self, *args):
756 """Create a Z3 application expression using the function `self`, and the given arguments.
758 The arguments must be Z3 expressions. This method assumes that
759 the sorts of the elements in `args` match the sorts of the
760 domain. Limited coercion is supported. For example, if
761 args[0] is a Python integer, and the function expects a Z3
762 integer, then the argument is automatically converted into a
765 >>> f = Function('f', IntSort(), RealSort(), BoolSort())
773 args = _get_args(args)
776 _z3_assert(num == self.arity(),
"Incorrect number of arguments to %s" % self)
777 _args = (Ast * num)()
782 tmp = self.domain(i).cast(args[i])
784 _args[i] = tmp.as_ast()
785 return _to_expr_ref(
Z3_mk_app(self.ctx_ref(), self.ast, len(args), _args), self.ctx)
◆ arity()
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 688 of file z3py.py.
689 """Return the number of arguments of a function declaration. If `self` is a constant, then `self.arity()` is 0.
691 >>> f = Function('f', IntSort(), RealSort(), BoolSort())
Referenced by FuncDeclRef.__call__(), and FuncDeclRef.domain().
◆ as_ast()
Return a pointer to the corresponding C Z3_ast object.
Reimplemented from AstRef.
Definition at line 668 of file z3py.py.
◆ as_func_decl()
Definition at line 674 of file z3py.py.
674 def as_func_decl(self):
◆ domain()
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 697 of file z3py.py.
698 """Return the sort of the argument `i` of a function declaration. This method assumes that `0 <= i < self.arity()`.
700 >>> f = Function('f', IntSort(), RealSort(), BoolSort())
707 _z3_assert(i < self.arity(),
"Index out of bounds")
708 return _to_sort_ref(
Z3_get_domain(self.ctx_ref(), self.ast, i), self.ctx)
Referenced by FuncDeclRef.__call__(), and ArrayRef.__getitem__().
◆ get_id()
Return unique identifier for object. It can be used for hash-tables and maps.
Reimplemented from AstRef.
Definition at line 671 of file z3py.py.
◆ kind()
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 719 of file z3py.py.
720 """Return the internal kind of a function declaration. It can be used to identify Z3 built-in functions such as addition, multiplication, etc.
723 >>> d = (x + 1).decl()
724 >>> d.kind() == Z3_OP_ADD
726 >>> d.kind() == Z3_OP_MUL
◆ name()
Return the name of the function declaration `self`.
>>> f = Function('f', IntSort(), IntSort())
>>> f.name()
'f'
>>> isinstance(f.name(), str)
True
Definition at line 677 of file z3py.py.
678 """Return the name of the function declaration `self`.
680 >>> f = Function('f', IntSort(), IntSort())
683 >>> isinstance(f.name(), str)
◆ params()
Definition at line 731 of file z3py.py.
734 result = [
None for i
in range(n) ]
737 if k == Z3_PARAMETER_INT:
739 elif k == Z3_PARAMETER_DOUBLE:
741 elif k == Z3_PARAMETER_RATIONAL:
743 elif k == Z3_PARAMETER_SYMBOL:
745 elif k == Z3_PARAMETER_SORT:
747 elif k == Z3_PARAMETER_AST:
749 elif k == Z3_PARAMETER_FUNC_DECL:
◆ range()
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 710 of file z3py.py.
711 """Return the sort of the range of a function declaration. For constants, this is the sort of the constant.
713 >>> f = Function('f', IntSort(), RealSort(), BoolSort())
717 return _to_sort_ref(
Z3_get_range(self.ctx_ref(), self.ast), self.ctx)
Referenced by FuncDeclRef.__call__(), and FuncDeclRef.params().
Z3_ast Z3_API Z3_get_decl_ast_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the expression value associated with an expression parameter.
expr range(expr const &lo, expr const &hi)
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_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.
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_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.
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.
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.
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.
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....
unsigned Z3_API Z3_get_decl_num_parameters(Z3_context c, Z3_func_decl d)
Return the number of parameters associated with a declaration.
unsigned Z3_API Z3_get_arity(Z3_context c, Z3_func_decl d)
Alias for Z3_get_domain_size.
Z3_sort Z3_API Z3_get_range(Z3_context c, Z3_func_decl d)
Return the range of the given declaration.
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_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_symbol Z3_API Z3_get_decl_name(Z3_context c, Z3_func_decl d)
Return the constant declaration name as a symbol.
Z3_decl_kind Z3_API Z3_get_decl_kind(Z3_context c, Z3_func_decl d)
Return declaration kind corresponding to declaration.
Z3_func_decl Z3_API Z3_get_decl_func_decl_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the expression value associated with an expression parameter.