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

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  f,
  ctx 
)

Definition at line 5774 of file z3py.py.

5774  def __init__(self, f, ctx):
5775  self.f = f
5776  self.ctx = ctx
5777  if self.f is not None:
5778  Z3_func_interp_inc_ref(self.ctx.ref(), self.f)
5779 
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 5783 of file z3py.py.

5783  def __del__(self):
5784  if self.f is not None and self.ctx.ref() is not None:
5785  Z3_func_interp_dec_ref(self.ctx.ref(), self.f)
5786 
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 5865 of file z3py.py.

5865  def __copy__(self):
5866  return self.translate(self.ctx)
5867 

◆ __deepcopy__() [1/2]

def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 5780 of file z3py.py.

5780  def __deepcopy__(self, memo={}):
5781  return FuncInterp(self.f, self.ctx)
5782 

◆ __deepcopy__() [2/2]

def __deepcopy__ (   self)

Definition at line 5868 of file z3py.py.

5868  def __deepcopy__(self):
5869  return self.translate(self.ctx)
5870 

◆ __repr__()

def __repr__ (   self)

Definition at line 5888 of file z3py.py.

5888  def __repr__(self):
5889  return obj_to_string(self)
5890 

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

5826  def arity(self):
5827  """Return the number of arguments for each entry in the function interpretation `self`.
5828 
5829  >>> f = Function('f', IntSort(), IntSort())
5830  >>> s = Solver()
5831  >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5832  >>> s.check()
5833  sat
5834  >>> m = s.model()
5835  >>> m[f].arity()
5836  1
5837  """
5838  return int(Z3_func_interp_get_arity(self.ctx.ref(), self.f))
5839 
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]
[2 -> 0, else -> 1]
>>> m[f].as_list()
[[2, 0], 1]

Definition at line 5871 of file z3py.py.

5871  def as_list(self):
5872  """Return the function interpretation as a Python list.
5873  >>> f = Function('f', IntSort(), IntSort())
5874  >>> s = Solver()
5875  >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5876  >>> s.check()
5877  sat
5878  >>> m = s.model()
5879  >>> m[f]
5880  [2 -> 0, else -> 1]
5881  >>> m[f].as_list()
5882  [[2, 0], 1]
5883  """
5884  r = [ self.entry(i).as_list() for i in range(self.num_entries())]
5885  r.append(self.else_value())
5886  return r
5887 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3244

◆ 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]
[2 -> 0, else -> 1]
>>> m[f].else_value()
1

Definition at line 5787 of file z3py.py.

5787  def else_value(self):
5788  """
5789  Return the `else` value for a function interpretation.
5790  Return None if Z3 did not specify the `else` value for
5791  this object.
5792 
5793  >>> f = Function('f', IntSort(), IntSort())
5794  >>> s = Solver()
5795  >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5796  >>> s.check()
5797  sat
5798  >>> m = s.model()
5799  >>> m[f]
5800  [2 -> 0, else -> 1]
5801  >>> m[f].else_value()
5802  1
5803  """
5804  r = Z3_func_interp_get_else(self.ctx.ref(), self.f)
5805  if r:
5806  return _to_expr_ref(r, self.ctx)
5807  else:
5808  return None
5809 
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]
[2 -> 0, else -> 1]
>>> m[f].num_entries()
1
>>> m[f].entry(0)
[2, 0]

Definition at line 5840 of file z3py.py.

5840  def entry(self, idx):
5841  """Return an entry at position `idx < self.num_entries()` in the function interpretation `self`.
5842 
5843  >>> f = Function('f', IntSort(), IntSort())
5844  >>> s = Solver()
5845  >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5846  >>> s.check()
5847  sat
5848  >>> m = s.model()
5849  >>> m[f]
5850  [2 -> 0, else -> 1]
5851  >>> m[f].num_entries()
5852  1
5853  >>> m[f].entry(0)
5854  [2, 0]
5855  """
5856  if idx >= self.num_entries():
5857  raise IndexError
5858  return FuncEntry(Z3_func_interp_get_entry(self.ctx.ref(), self.f, idx), self.ctx)
5859 
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]
[2 -> 0, else -> 1]
>>> m[f].num_entries()
1

Definition at line 5810 of file z3py.py.

Referenced by FuncInterp.entry().

5810  def num_entries(self):
5811  """Return the number of entries/points in the function interpretation `self`.
5812 
5813  >>> f = Function('f', IntSort(), IntSort())
5814  >>> s = Solver()
5815  >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5816  >>> s.check()
5817  sat
5818  >>> m = s.model()
5819  >>> m[f]
5820  [2 -> 0, else -> 1]
5821  >>> m[f].num_entries()
5822  1
5823  """
5824  return int(Z3_func_interp_get_num_entries(self.ctx.ref(), self.f))
5825 
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 5860 of file z3py.py.

5860  def translate(self, other_ctx):
5861  """Copy model 'self' to context 'other_ctx'.
5862  """
5863  return ModelRef(Z3_model_translate(self.ctx.ref(), self.model, other_ctx.ref()), other_ctx)
5864 
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 5776 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(), 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(), Optimize.unsat_core(), and Fixedpoint.update_rule().

◆ f

f