Z3
Loading...
Searching...
No Matches
FuncEntry Class Reference

Public Member Functions

 __init__ (self, entry, ctx)
 __deepcopy__ (self, memo={})
 __del__ (self)
 num_args (self)
 arg_value (self, idx)
 value (self)
 as_list (self)
 __repr__ (self)

Data Fields

 entry = entry
 ctx = ctx

Detailed Description

Store the value of the interpretation of a function in a particular point.

Definition at line 6895 of file z3py.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
entry,
ctx )

Definition at line 6898 of file z3py.py.

6898 def __init__(self, entry, ctx):
6899 self.entry = entry
6900 self.ctx = ctx
6901 Z3_func_entry_inc_ref(self.ctx.ref(), self.entry)
6902
void Z3_API Z3_func_entry_inc_ref(Z3_context c, Z3_func_entry e)
Increment the reference counter of the given Z3_func_entry object.

◆ __del__()

__del__ ( self)

Definition at line 6906 of file z3py.py.

6906 def __del__(self):
6907 if self.ctx.ref() is not None and Z3_func_entry_dec_ref is not None:
6908 Z3_func_entry_dec_ref(self.ctx.ref(), self.entry)
6909
void Z3_API Z3_func_entry_dec_ref(Z3_context c, Z3_func_entry e)
Decrement the reference counter of the given Z3_func_entry object.

Member Function Documentation

◆ __deepcopy__()

__deepcopy__ ( self,
memo = {} )

Definition at line 6903 of file z3py.py.

6903 def __deepcopy__(self, memo={}):
6904 return FuncEntry(self.entry, self.ctx)
6905

◆ __repr__()

__repr__ ( self)

Definition at line 7000 of file z3py.py.

7000 def __repr__(self):
7001 return repr(self.as_list())
7002
7003

◆ arg_value()

arg_value ( self,
idx )
Return the value of argument `idx`.

>>> f = Function('f', IntSort(), IntSort(), IntSort())
>>> s = Solver()
>>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
>>> s.check()
sat
>>> m = s.model()
>>> f_i = m[f]
>>> f_i.num_entries()
1
>>> e = f_i.entry(0)
>>> e
[1, 2, 20]
>>> e.num_args()
2
>>> e.arg_value(0)
1
>>> e.arg_value(1)
2
>>> try:
...   e.arg_value(2)
... except IndexError:
...   print("index error")
index error

Definition at line 6928 of file z3py.py.

6928 def arg_value(self, idx):
6929 """Return the value of argument `idx`.
6930
6931 >>> f = Function('f', IntSort(), IntSort(), IntSort())
6932 >>> s = Solver()
6933 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6934 >>> s.check()
6935 sat
6936 >>> m = s.model()
6937 >>> f_i = m[f]
6938 >>> f_i.num_entries()
6939 1
6940 >>> e = f_i.entry(0)
6941 >>> e
6942 [1, 2, 20]
6943 >>> e.num_args()
6944 2
6945 >>> e.arg_value(0)
6946 1
6947 >>> e.arg_value(1)
6948 2
6949 >>> try:
6950 ... e.arg_value(2)
6951 ... except IndexError:
6952 ... print("index error")
6953 index error
6954 """
6955 if idx >= self.num_args():
6956 raise IndexError
6957 return _to_expr_ref(Z3_func_entry_get_arg(self.ctx.ref(), self.entry, idx), self.ctx)
6958
Z3_ast Z3_API Z3_func_entry_get_arg(Z3_context c, Z3_func_entry e, unsigned i)
Return an argument of a Z3_func_entry object.

Referenced by as_list().

◆ as_list()

as_list ( self)
Return entry `self` as a Python list.
>>> f = Function('f', IntSort(), IntSort(), IntSort())
>>> s = Solver()
>>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
>>> s.check()
sat
>>> m = s.model()
>>> f_i = m[f]
>>> f_i.num_entries()
1
>>> e = f_i.entry(0)
>>> e.as_list()
[1, 2, 20]

Definition at line 6981 of file z3py.py.

6981 def as_list(self):
6982 """Return entry `self` as a Python list.
6983 >>> f = Function('f', IntSort(), IntSort(), IntSort())
6984 >>> s = Solver()
6985 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6986 >>> s.check()
6987 sat
6988 >>> m = s.model()
6989 >>> f_i = m[f]
6990 >>> f_i.num_entries()
6991 1
6992 >>> e = f_i.entry(0)
6993 >>> e.as_list()
6994 [1, 2, 20]
6995 """
6996 args = [self.arg_value(i) for i in range(self.num_args())]
6997 args.append(self.value())
6998 return args
6999

Referenced by __repr__().

◆ num_args()

num_args ( self)
Return the number of arguments in the given entry.

>>> f = Function('f', IntSort(), IntSort(), IntSort())
>>> s = Solver()
>>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
>>> s.check()
sat
>>> m = s.model()
>>> f_i = m[f]
>>> f_i.num_entries()
1
>>> e = f_i.entry(0)
>>> e.num_args()
2

Definition at line 6910 of file z3py.py.

6910 def num_args(self):
6911 """Return the number of arguments in the given entry.
6912
6913 >>> f = Function('f', IntSort(), IntSort(), IntSort())
6914 >>> s = Solver()
6915 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6916 >>> s.check()
6917 sat
6918 >>> m = s.model()
6919 >>> f_i = m[f]
6920 >>> f_i.num_entries()
6921 1
6922 >>> e = f_i.entry(0)
6923 >>> e.num_args()
6924 2
6925 """
6926 return int(Z3_func_entry_get_num_args(self.ctx.ref(), self.entry))
6927
unsigned Z3_API Z3_func_entry_get_num_args(Z3_context c, Z3_func_entry e)
Return the number of arguments in a Z3_func_entry object.

Referenced by AstRef.__bool__(), arg_value(), and as_list().

◆ value()

value ( self)
Return the value of the function at point `self`.

>>> f = Function('f', IntSort(), IntSort(), IntSort())
>>> s = Solver()
>>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
>>> s.check()
sat
>>> m = s.model()
>>> f_i = m[f]
>>> f_i.num_entries()
1
>>> e = f_i.entry(0)
>>> e
[1, 2, 20]
>>> e.num_args()
2
>>> e.value()
20

Definition at line 6959 of file z3py.py.

6959 def value(self):
6960 """Return the value of the function at point `self`.
6961
6962 >>> f = Function('f', IntSort(), IntSort(), IntSort())
6963 >>> s = Solver()
6964 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6965 >>> s.check()
6966 sat
6967 >>> m = s.model()
6968 >>> f_i = m[f]
6969 >>> f_i.num_entries()
6970 1
6971 >>> e = f_i.entry(0)
6972 >>> e
6973 [1, 2, 20]
6974 >>> e.num_args()
6975 2
6976 >>> e.value()
6977 20
6978 """
6979 return _to_expr_ref(Z3_func_entry_get_value(self.ctx.ref(), self.entry), self.ctx)
6980
Z3_ast Z3_API Z3_func_entry_get_value(Z3_context c, Z3_func_entry e)
Return the value of this point.

Referenced by as_list().

Field Documentation

◆ ctx

◆ entry

entry = entry

Definition at line 6899 of file z3py.py.

Referenced by __deepcopy__(), __del__(), arg_value(), FuncInterp.as_list(), num_args(), and value().