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, memo={})
 
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 5820 of file z3py.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  f,
  ctx 
)

Definition at line 5823 of file z3py.py.

5823  def __init__(self, f, ctx):
5824  self.f = f
5825  self.ctx = ctx
5826  if self.f is not None:
5827  Z3_func_interp_inc_ref(self.ctx.ref(), self.f)
5828 
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 5832 of file z3py.py.

5832  def __del__(self):
5833  if self.f is not None and self.ctx.ref() is not None:
5834  Z3_func_interp_dec_ref(self.ctx.ref(), self.f)
5835 
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 5914 of file z3py.py.

5914  def __copy__(self):
5915  return self.translate(self.ctx)
5916 

◆ __deepcopy__() [1/2]

def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 5829 of file z3py.py.

5829  def __deepcopy__(self, memo={}):
5830  return FuncInterp(self.f, self.ctx)
5831 

◆ __deepcopy__() [2/2]

def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 5917 of file z3py.py.

5917  def __deepcopy__(self, memo={}):
5918  return self.translate(self.ctx)
5919 

◆ __repr__()

def __repr__ (   self)

Definition at line 5937 of file z3py.py.

5937  def __repr__(self):
5938  return obj_to_string(self)
5939 

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

5875  def arity(self):
5876  """Return the number of arguments for each entry in the function interpretation `self`.
5877 
5878  >>> f = Function('f', IntSort(), IntSort())
5879  >>> s = Solver()
5880  >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5881  >>> s.check()
5882  sat
5883  >>> m = s.model()
5884  >>> m[f].arity()
5885  1
5886  """
5887  return int(Z3_func_interp_get_arity(self.ctx.ref(), self.f))
5888 
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 5920 of file z3py.py.

5920  def as_list(self):
5921  """Return the function interpretation as a Python list.
5922  >>> f = Function('f', IntSort(), IntSort())
5923  >>> s = Solver()
5924  >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5925  >>> s.check()
5926  sat
5927  >>> m = s.model()
5928  >>> m[f]
5929  [2 -> 0, else -> 1]
5930  >>> m[f].as_list()
5931  [[2, 0], 1]
5932  """
5933  r = [ self.entry(i).as_list() for i in range(self.num_entries())]
5934  r.append(self.else_value())
5935  return r
5936 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3358

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

5836  def else_value(self):
5837  """
5838  Return the `else` value for a function interpretation.
5839  Return None if Z3 did not specify the `else` value for
5840  this object.
5841 
5842  >>> f = Function('f', IntSort(), IntSort())
5843  >>> s = Solver()
5844  >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5845  >>> s.check()
5846  sat
5847  >>> m = s.model()
5848  >>> m[f]
5849  [2 -> 0, else -> 1]
5850  >>> m[f].else_value()
5851  1
5852  """
5853  r = Z3_func_interp_get_else(self.ctx.ref(), self.f)
5854  if r:
5855  return _to_expr_ref(r, self.ctx)
5856  else:
5857  return None
5858 
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 5889 of file z3py.py.

5889  def entry(self, idx):
5890  """Return an entry at position `idx < self.num_entries()` in the function interpretation `self`.
5891 
5892  >>> f = Function('f', IntSort(), IntSort())
5893  >>> s = Solver()
5894  >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5895  >>> s.check()
5896  sat
5897  >>> m = s.model()
5898  >>> m[f]
5899  [2 -> 0, else -> 1]
5900  >>> m[f].num_entries()
5901  1
5902  >>> m[f].entry(0)
5903  [2, 0]
5904  """
5905  if idx >= self.num_entries():
5906  raise IndexError
5907  return FuncEntry(Z3_func_interp_get_entry(self.ctx.ref(), self.f, idx), self.ctx)
5908 
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 5859 of file z3py.py.

Referenced by FuncInterp.entry().

5859  def num_entries(self):
5860  """Return the number of entries/points in the function interpretation `self`.
5861 
5862  >>> f = Function('f', IntSort(), IntSort())
5863  >>> s = Solver()
5864  >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5865  >>> s.check()
5866  sat
5867  >>> m = s.model()
5868  >>> m[f]
5869  [2 -> 0, else -> 1]
5870  >>> m[f].num_entries()
5871  1
5872  """
5873  return int(Z3_func_interp_get_num_entries(self.ctx.ref(), self.f))
5874 
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 5909 of file z3py.py.

5909  def translate(self, other_ctx):
5910  """Copy model 'self' to context 'other_ctx'.
5911  """
5912  return ModelRef(Z3_model_translate(self.ctx.ref(), self.model, other_ctx.ref()), other_ctx)
5913 
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 5825 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(), Optimize.assert_and_track(), 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(), Optimize.pop(), 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