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 translate (self, other_ctx)
 
def __copy__ (self)
 
def __deepcopy__ (self)
 
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 5503 of file z3py.py.

Constructor & Destructor Documentation

§ __init__()

def __init__ (   self,
  f,
  ctx 
)

Definition at line 5506 of file z3py.py.

5506  def __init__(self, f, ctx):
5507  self.f = f
5508  self.ctx = ctx
5509  if self.f is not None:
5510  Z3_func_interp_inc_ref(self.ctx.ref(), self.f)
5511 
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 5515 of file z3py.py.

5515  def __del__(self):
5516  if self.f is not None and self.ctx.ref() is not None:
5517  Z3_func_interp_dec_ref(self.ctx.ref(), self.f)
5518 
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

§ __copy__()

def __copy__ (   self)

Definition at line 5601 of file z3py.py.

5601  def __copy__(self):
5602  return self.translate(self.ctx)
5603 

§ __deepcopy__() [1/2]

def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 5512 of file z3py.py.

5512  def __deepcopy__(self, memo={}):
5513  return FuncInterp(self.f, self.ctx)
5514 

§ __deepcopy__() [2/2]

def __deepcopy__ (   self)

Definition at line 5604 of file z3py.py.

5604  def __deepcopy__(self):
5605  return self.translate(self.ctx)
5606 

§ __repr__()

def __repr__ (   self)

Definition at line 5624 of file z3py.py.

5624  def __repr__(self):
5625  return obj_to_string(self)
5626 

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

5558  def arity(self):
5559  """Return the number of arguments for each entry in the function interpretation `self`.
5560 
5561  >>> f = Function('f', IntSort(), IntSort())
5562  >>> s = Solver()
5563  >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5564  >>> s.check()
5565  sat
5566  >>> m = s.model()
5567  >>> m[f].arity()
5568  1
5569  """
5570  return int(Z3_func_interp_get_arity(self.ctx.ref(), self.f))
5571 
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 5607 of file z3py.py.

5607  def as_list(self):
5608  """Return the function interpretation as a Python list.
5609  >>> f = Function('f', IntSort(), IntSort())
5610  >>> s = Solver()
5611  >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5612  >>> s.check()
5613  sat
5614  >>> m = s.model()
5615  >>> m[f]
5616  [0 -> 1, 1 -> 1, 2 -> 0, else -> 1]
5617  >>> m[f].as_list()
5618  [[0, 1], [1, 1], [2, 0], 1]
5619  """
5620  r = [ self.entry(i).as_list() for i in range(self.num_entries())]
5621  r.append(self.else_value())
5622  return r
5623 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:2868

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

5519  def else_value(self):
5520  """
5521  Return the `else` value for a function interpretation.
5522  Return None if Z3 did not specify the `else` value for
5523  this object.
5524 
5525  >>> f = Function('f', IntSort(), IntSort())
5526  >>> s = Solver()
5527  >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5528  >>> s.check()
5529  sat
5530  >>> m = s.model()
5531  >>> m[f]
5532  [0 -> 1, 1 -> 1, 2 -> 0, else -> 1]
5533  >>> m[f].else_value()
5534  1
5535  """
5536  r = Z3_func_interp_get_else(self.ctx.ref(), self.f)
5537  if r:
5538  return _to_expr_ref(r, self.ctx)
5539  else:
5540  return None
5541 
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 5572 of file z3py.py.

5572  def entry(self, idx):
5573  """Return an entry at position `idx < self.num_entries()` in the function interpretation `self`.
5574 
5575  >>> f = Function('f', IntSort(), IntSort())
5576  >>> s = Solver()
5577  >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5578  >>> s.check()
5579  sat
5580  >>> m = s.model()
5581  >>> m[f]
5582  [0 -> 1, 1 -> 1, 2 -> 0, else -> 1]
5583  >>> m[f].num_entries()
5584  3
5585  >>> m[f].entry(0)
5586  [0, 1]
5587  >>> m[f].entry(1)
5588  [1, 1]
5589  >>> m[f].entry(2)
5590  [2, 0]
5591  """
5592  if idx >= self.num_entries():
5593  raise IndexError
5594  return FuncEntry(Z3_func_interp_get_entry(self.ctx.ref(), self.f, idx), self.ctx)
5595 
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 interpretation. It represents the value of f in a particular p...

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

Referenced by FuncInterp.entry().

5542  def num_entries(self):
5543  """Return the number of entries/points in the function interpretation `self`.
5544 
5545  >>> f = Function('f', IntSort(), IntSort())
5546  >>> s = Solver()
5547  >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5548  >>> s.check()
5549  sat
5550  >>> m = s.model()
5551  >>> m[f]
5552  [0 -> 1, 1 -> 1, 2 -> 0, else -> 1]
5553  >>> m[f].num_entries()
5554  3
5555  """
5556  return int(Z3_func_interp_get_num_entries(self.ctx.ref(), self.f))
5557 
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.

§ translate()

def translate (   self,
  other_ctx 
)
Copy model 'self' to context 'other_ctx'.

Definition at line 5596 of file z3py.py.

5596  def translate(self, other_ctx):
5597  """Copy model 'self' to context 'other_ctx'.
5598  """
5599  return ModelRef(Z3_model_translate(self.ctx.ref(), self.model, other_ctx.ref()), other_ctx)
5600 
Z3_model Z3_API Z3_model_translate(Z3_context c, Z3_model m, Z3_context dst)
translate model from context c to context dst.

Field Documentation

§ ctx

ctx

Definition at line 5508 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