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

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  f,
  ctx 
)

Definition at line 5780 of file z3py.py.

5780  def __init__(self, f, ctx):
5781  self.f = f
5782  self.ctx = ctx
5783  if self.f is not None:
5784  Z3_func_interp_inc_ref(self.ctx.ref(), self.f)
5785 
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 5789 of file z3py.py.

5789  def __del__(self):
5790  if self.f is not None and self.ctx.ref() is not None:
5791  Z3_func_interp_dec_ref(self.ctx.ref(), self.f)
5792 
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 5871 of file z3py.py.

5871  def __copy__(self):
5872  return self.translate(self.ctx)
5873 

◆ __deepcopy__() [1/2]

def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 5786 of file z3py.py.

5786  def __deepcopy__(self, memo={}):
5787  return FuncInterp(self.f, self.ctx)
5788 

◆ __deepcopy__() [2/2]

def __deepcopy__ (   self)

Definition at line 5874 of file z3py.py.

5874  def __deepcopy__(self):
5875  return self.translate(self.ctx)
5876 

◆ __repr__()

def __repr__ (   self)

Definition at line 5894 of file z3py.py.

5894  def __repr__(self):
5895  return obj_to_string(self)
5896 

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

5832  def arity(self):
5833  """Return the number of arguments for each entry in the function interpretation `self`.
5834 
5835  >>> f = Function('f', IntSort(), IntSort())
5836  >>> s = Solver()
5837  >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5838  >>> s.check()
5839  sat
5840  >>> m = s.model()
5841  >>> m[f].arity()
5842  1
5843  """
5844  return int(Z3_func_interp_get_arity(self.ctx.ref(), self.f))
5845 
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 5877 of file z3py.py.

5877  def as_list(self):
5878  """Return the function interpretation as a Python list.
5879  >>> f = Function('f', IntSort(), IntSort())
5880  >>> s = Solver()
5881  >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5882  >>> s.check()
5883  sat
5884  >>> m = s.model()
5885  >>> m[f]
5886  [2 -> 0, else -> 1]
5887  >>> m[f].as_list()
5888  [[2, 0], 1]
5889  """
5890  r = [ self.entry(i).as_list() for i in range(self.num_entries())]
5891  r.append(self.else_value())
5892  return r
5893 
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 5793 of file z3py.py.

5793  def else_value(self):
5794  """
5795  Return the `else` value for a function interpretation.
5796  Return None if Z3 did not specify the `else` value for
5797  this object.
5798 
5799  >>> f = Function('f', IntSort(), IntSort())
5800  >>> s = Solver()
5801  >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5802  >>> s.check()
5803  sat
5804  >>> m = s.model()
5805  >>> m[f]
5806  [2 -> 0, else -> 1]
5807  >>> m[f].else_value()
5808  1
5809  """
5810  r = Z3_func_interp_get_else(self.ctx.ref(), self.f)
5811  if r:
5812  return _to_expr_ref(r, self.ctx)
5813  else:
5814  return None
5815 
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 5846 of file z3py.py.

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

Referenced by FuncInterp.entry().

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

5866  def translate(self, other_ctx):
5867  """Copy model 'self' to context 'other_ctx'.
5868  """
5869  return ModelRef(Z3_model_translate(self.ctx.ref(), self.model, other_ctx.ref()), other_ctx)
5870 
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 5782 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