Z3
Public Member Functions | Data Fields
FuncInterp Class Reference
+ Inheritance diagram for FuncInterp:

Public Member Functions

def __init__ (self, f, ctx)
 
def __deepcopy__ (self, memo={})
 
def __del__ (self)
 
def else_value (self)
 
def num_entries (self)
 
def arity (self)
 
def entry (self, idx)
 
def as_list (self)
 
def __repr__ (self)
 
- Public Member Functions inherited from Z3PPObject
def use_pp (self)
 

Data Fields

 f
 
 ctx
 

Detailed Description

Stores the interpretation of a function in a Z3 model.

Definition at line 5460 of file z3py.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  f,
  ctx 
)

Definition at line 5463 of file z3py.py.

5463  def __init__(self, f, ctx):
5464  self.f = f
5465  self.ctx = ctx
5466  if self.f is not None:
5467  Z3_func_interp_inc_ref(self.ctx.ref(), self.f)
5468 
void Z3_API Z3_func_interp_inc_ref(Z3_context c, Z3_func_interp f)
Increment the reference counter of the given Z3_func_interp object.

◆ __del__()

def __del__ (   self)

Definition at line 5472 of file z3py.py.

5472  def __del__(self):
5473  if self.f is not None and self.ctx.ref() is not None:
5474  Z3_func_interp_dec_ref(self.ctx.ref(), self.f)
5475 
void Z3_API Z3_func_interp_dec_ref(Z3_context c, Z3_func_interp f)
Decrement the reference counter of the given Z3_func_interp object.

Member Function Documentation

◆ __deepcopy__()

def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 5469 of file z3py.py.

5469  def __deepcopy__(self, memo={}):
5470  return FuncInterp(self.f, self.ctx)
5471 

◆ __repr__()

def __repr__ (   self)

Definition at line 5570 of file z3py.py.

5570  def __repr__(self):
5571  return obj_to_string(self)
5572 

◆ arity()

def arity (   self)
Return the number of arguments for each entry in the function interpretation `self`.

>>> f = Function('f', IntSort(), IntSort())
>>> s = Solver()
>>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
>>> s.check()
sat
>>> m = s.model()
>>> m[f].arity()
1

Definition at line 5515 of file z3py.py.

5515  def arity(self):
5516  """Return the number of arguments for each entry in the function interpretation `self`.
5517 
5518  >>> f = Function('f', IntSort(), IntSort())
5519  >>> s = Solver()
5520  >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5521  >>> s.check()
5522  sat
5523  >>> m = s.model()
5524  >>> m[f].arity()
5525  1
5526  """
5527  return int(Z3_func_interp_get_arity(self.ctx.ref(), self.f))
5528 
unsigned Z3_API Z3_func_interp_get_arity(Z3_context c, Z3_func_interp f)
Return the arity (number of arguments) of the given function interpretation.

◆ as_list()

def as_list (   self)
Return the function interpretation as a Python list.
>>> f = Function('f', IntSort(), IntSort())
>>> s = Solver()
>>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
>>> s.check()
sat
>>> m = s.model()
>>> m[f]
[0 -> 1, 1 -> 1, 2 -> 0, else -> 1]
>>> m[f].as_list()
[[0, 1], [1, 1], [2, 0], 1]

Definition at line 5553 of file z3py.py.

5553  def as_list(self):
5554  """Return the function interpretation as a Python list.
5555  >>> f = Function('f', IntSort(), IntSort())
5556  >>> s = Solver()
5557  >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5558  >>> s.check()
5559  sat
5560  >>> m = s.model()
5561  >>> m[f]
5562  [0 -> 1, 1 -> 1, 2 -> 0, else -> 1]
5563  >>> m[f].as_list()
5564  [[0, 1], [1, 1], [2, 0], 1]
5565  """
5566  r = [ self.entry(i).as_list() for i in range(self.num_entries())]
5567  r.append(self.else_value())
5568  return r
5569 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:2813

◆ else_value()

def else_value (   self)
Return the `else` value for a function interpretation.
Return None if Z3 did not specify the `else` value for
this object.

>>> f = Function('f', IntSort(), IntSort())
>>> s = Solver()
>>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
>>> s.check()
sat
>>> m = s.model()
>>> m[f]
[0 -> 1, 1 -> 1, 2 -> 0, else -> 1]
>>> m[f].else_value()
1

Definition at line 5476 of file z3py.py.

5476  def else_value(self):
5477  """
5478  Return the `else` value for a function interpretation.
5479  Return None if Z3 did not specify the `else` value for
5480  this object.
5481 
5482  >>> f = Function('f', IntSort(), IntSort())
5483  >>> s = Solver()
5484  >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5485  >>> s.check()
5486  sat
5487  >>> m = s.model()
5488  >>> m[f]
5489  [0 -> 1, 1 -> 1, 2 -> 0, else -> 1]
5490  >>> m[f].else_value()
5491  1
5492  """
5493  r = Z3_func_interp_get_else(self.ctx.ref(), self.f)
5494  if r:
5495  return _to_expr_ref(r, self.ctx)
5496  else:
5497  return None
5498 
Z3_ast Z3_API Z3_func_interp_get_else(Z3_context c, Z3_func_interp f)
Return the 'else' value of the given function interpretation.

◆ entry()

def entry (   self,
  idx 
)
Return an entry at position `idx < self.num_entries()` in the function interpretation `self`.

>>> f = Function('f', IntSort(), IntSort())
>>> s = Solver()
>>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
>>> s.check()
sat
>>> m = s.model()
>>> m[f]
[0 -> 1, 1 -> 1, 2 -> 0, else -> 1]
>>> m[f].num_entries()
3
>>> m[f].entry(0)
[0, 1]
>>> m[f].entry(1)
[1, 1]
>>> m[f].entry(2)
[2, 0]

Definition at line 5529 of file z3py.py.

5529  def entry(self, idx):
5530  """Return an entry at position `idx < self.num_entries()` in the function interpretation `self`.
5531 
5532  >>> f = Function('f', IntSort(), IntSort())
5533  >>> s = Solver()
5534  >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5535  >>> s.check()
5536  sat
5537  >>> m = s.model()
5538  >>> m[f]
5539  [0 -> 1, 1 -> 1, 2 -> 0, else -> 1]
5540  >>> m[f].num_entries()
5541  3
5542  >>> m[f].entry(0)
5543  [0, 1]
5544  >>> m[f].entry(1)
5545  [1, 1]
5546  >>> m[f].entry(2)
5547  [2, 0]
5548  """
5549  if idx >= self.num_entries():
5550  raise IndexError
5551  return FuncEntry(Z3_func_interp_get_entry(self.ctx.ref(), self.f, idx), self.ctx)
5552 
Z3_func_entry Z3_API Z3_func_interp_get_entry(Z3_context c, Z3_func_interp f, unsigned i)
Return a "point" of the given function intepretation. It represents the value of f in a particular po...

◆ num_entries()

def num_entries (   self)
Return the number of entries/points in the function interpretation `self`.

>>> f = Function('f', IntSort(), IntSort())
>>> s = Solver()
>>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
>>> s.check()
sat
>>> m = s.model()
>>> m[f]
[0 -> 1, 1 -> 1, 2 -> 0, else -> 1]
>>> m[f].num_entries()
3

Definition at line 5499 of file z3py.py.

Referenced by FuncInterp.entry().

5499  def num_entries(self):
5500  """Return the number of entries/points in the function interpretation `self`.
5501 
5502  >>> f = Function('f', IntSort(), IntSort())
5503  >>> s = Solver()
5504  >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5505  >>> s.check()
5506  sat
5507  >>> m = s.model()
5508  >>> m[f]
5509  [0 -> 1, 1 -> 1, 2 -> 0, else -> 1]
5510  >>> m[f].num_entries()
5511  3
5512  """
5513  return int(Z3_func_interp_get_num_entries(self.ctx.ref(), self.f))
5514 
unsigned Z3_API Z3_func_interp_get_num_entries(Z3_context c, Z3_func_interp f)
Return the number of entries in the given function interpretation.

Field Documentation

◆ ctx

ctx

Definition at line 5465 of file z3py.py.

Referenced by Probe.__call__(), Fixedpoint.__deepcopy__(), Optimize.__deepcopy__(), ApplyResult.__deepcopy__(), Tactic.__deepcopy__(), Probe.__deepcopy__(), Fixedpoint.__del__(), Optimize.__del__(), ApplyResult.__del__(), Tactic.__del__(), Probe.__del__(), Probe.__eq__(), Probe.__ge__(), ApplyResult.__getitem__(), Probe.__gt__(), Probe.__le__(), ApplyResult.__len__(), Probe.__lt__(), Probe.__ne__(), Fixedpoint.add_cover(), Fixedpoint.add_rule(), Optimize.add_soft(), Tactic.apply(), ApplyResult.as_expr(), Fixedpoint.assert_exprs(), Optimize.assert_exprs(), Optimize.assertions(), Optimize.check(), ApplyResult.convert_model(), Optimize.from_file(), Optimize.from_string(), Fixedpoint.get_answer(), Fixedpoint.get_assertions(), Fixedpoint.get_cover_delta(), Fixedpoint.get_ground_sat_answer(), Fixedpoint.get_num_levels(), Fixedpoint.get_rule_names_along_trace(), Fixedpoint.get_rules(), Fixedpoint.get_rules_along_trace(), Fixedpoint.help(), Optimize.help(), Tactic.help(), Optimize.maximize(), Optimize.minimize(), Optimize.model(), Optimize.objectives(), Fixedpoint.param_descrs(), Optimize.param_descrs(), Tactic.param_descrs(), Fixedpoint.parse_file(), Fixedpoint.parse_string(), Fixedpoint.pop(), Optimize.pop(), Fixedpoint.push(), Optimize.push(), Fixedpoint.query(), Fixedpoint.query_from_lvl(), Fixedpoint.reason_unknown(), Optimize.reason_unknown(), Fixedpoint.register_relation(), Fixedpoint.set(), Optimize.set(), Fixedpoint.set_predicate_representation(), Fixedpoint.sexpr(), Optimize.sexpr(), ApplyResult.sexpr(), Tactic.solver(), Fixedpoint.statistics(), Optimize.statistics(), Solver.to_smt2(), Fixedpoint.to_string(), and Fixedpoint.update_rule().

◆ f

f