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

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
entry,
ctx )

Definition at line 6376 of file z3py.py.

6376 def __init__(self, entry, ctx):
6377 self.entry = entry
6378 self.ctx = ctx
6379 Z3_func_entry_inc_ref(self.ctx.ref(), self.entry)
6380
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 6384 of file z3py.py.

6384 def __del__(self):
6385 if self.ctx.ref() is not None and Z3_func_entry_dec_ref is not None:
6386 Z3_func_entry_dec_ref(self.ctx.ref(), self.entry)
6387
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 6381 of file z3py.py.

6381 def __deepcopy__(self, memo={}):
6382 return FuncEntry(self.entry, self.ctx)
6383

◆ __repr__()

__repr__ ( self)

Definition at line 6478 of file z3py.py.

6478 def __repr__(self):
6479 return repr(self.as_list())
6480
6481

◆ 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 6406 of file z3py.py.

6406 def arg_value(self, idx):
6407 """Return the value of argument `idx`.
6408
6409 >>> f = Function('f', IntSort(), IntSort(), IntSort())
6410 >>> s = Solver()
6411 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6412 >>> s.check()
6413 sat
6414 >>> m = s.model()
6415 >>> f_i = m[f]
6416 >>> f_i.num_entries()
6417 1
6418 >>> e = f_i.entry(0)
6419 >>> e
6420 [1, 2, 20]
6421 >>> e.num_args()
6422 2
6423 >>> e.arg_value(0)
6424 1
6425 >>> e.arg_value(1)
6426 2
6427 >>> try:
6428 ... e.arg_value(2)
6429 ... except IndexError:
6430 ... print("index error")
6431 index error
6432 """
6433 if idx >= self.num_args():
6434 raise IndexError
6435 return _to_expr_ref(Z3_func_entry_get_arg(self.ctx.ref(), self.entry, idx), self.ctx)
6436
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 6459 of file z3py.py.

6459 def as_list(self):
6460 """Return entry `self` as a Python list.
6461 >>> f = Function('f', IntSort(), IntSort(), IntSort())
6462 >>> s = Solver()
6463 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6464 >>> s.check()
6465 sat
6466 >>> m = s.model()
6467 >>> f_i = m[f]
6468 >>> f_i.num_entries()
6469 1
6470 >>> e = f_i.entry(0)
6471 >>> e.as_list()
6472 [1, 2, 20]
6473 """
6474 args = [self.arg_value(i) for i in range(self.num_args())]
6475 args.append(self.value())
6476 return args
6477

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

6388 def num_args(self):
6389 """Return the number of arguments in the given entry.
6390
6391 >>> f = Function('f', IntSort(), IntSort(), IntSort())
6392 >>> s = Solver()
6393 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6394 >>> s.check()
6395 sat
6396 >>> m = s.model()
6397 >>> f_i = m[f]
6398 >>> f_i.num_entries()
6399 1
6400 >>> e = f_i.entry(0)
6401 >>> e.num_args()
6402 2
6403 """
6404 return int(Z3_func_entry_get_num_args(self.ctx.ref(), self.entry))
6405
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 6437 of file z3py.py.

6437 def value(self):
6438 """Return the value of the function at point `self`.
6439
6440 >>> f = Function('f', IntSort(), IntSort(), IntSort())
6441 >>> s = Solver()
6442 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6443 >>> s.check()
6444 sat
6445 >>> m = s.model()
6446 >>> f_i = m[f]
6447 >>> f_i.num_entries()
6448 1
6449 >>> e = f_i.entry(0)
6450 >>> e
6451 [1, 2, 20]
6452 >>> e.num_args()
6453 2
6454 >>> e.value()
6455 20
6456 """
6457 return _to_expr_ref(Z3_func_entry_get_value(self.ctx.ref(), self.entry), self.ctx)
6458
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 6377 of file z3py.py.

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