Z3
Loading...
Searching...
No Matches
FuncInterp Class Reference
Inheritance diagram for FuncInterp:

Public Member Functions

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

Data Fields

 f = f
 ctx = ctx
 model

Additional Inherited Members

Protected Member Functions inherited from Z3PPObject
 _repr_html_ (self)

Detailed Description

Stores the interpretation of a function in a Z3 model.

Definition at line 6871 of file z3py.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
f,
ctx )

Definition at line 6874 of file z3py.py.

6874 def __init__(self, f, ctx):
6875 self.f = f
6876 self.ctx = ctx
6877 if self.f is not None:
6878 Z3_func_interp_inc_ref(self.ctx.ref(), self.f)
6879
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__()

__del__ ( self)

Definition at line 6880 of file z3py.py.

6880 def __del__(self):
6881 if self.f is not None and self.ctx.ref() is not None and Z3_func_interp_dec_ref is not None:
6882 Z3_func_interp_dec_ref(self.ctx.ref(), self.f)
6883
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__()

__copy__ ( self)

Definition at line 6962 of file z3py.py.

6962 def __copy__(self):
6963 return self.translate(self.ctx)
6964

◆ __deepcopy__()

__deepcopy__ ( self,
memo = {} )

Definition at line 6965 of file z3py.py.

6965 def __deepcopy__(self, memo={}):
6966 return self.translate(self.ctx)
6967

◆ __repr__()

__repr__ ( self)

Definition at line 6985 of file z3py.py.

6985 def __repr__(self):
6986 return obj_to_string(self)
6987
6988

◆ arity()

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

6923 def arity(self):
6924 """Return the number of arguments for each entry in the function interpretation `self`.
6925
6926 >>> f = Function('f', IntSort(), IntSort())
6927 >>> s = Solver()
6928 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
6929 >>> s.check()
6930 sat
6931 >>> m = s.model()
6932 >>> m[f].arity()
6933 1
6934 """
6935 return int(Z3_func_interp_get_arity(self.ctx.ref(), self.f))
6936
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()

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

6968 def as_list(self):
6969 """Return the function interpretation as a Python list.
6970 >>> f = Function('f', IntSort(), IntSort())
6971 >>> s = Solver()
6972 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
6973 >>> s.check()
6974 sat
6975 >>> m = s.model()
6976 >>> m[f]
6977 [2 -> 0, else -> 1]
6978 >>> m[f].as_list()
6979 [[2, 0], 1]
6980 """
6981 r = [self.entry(i).as_list() for i in range(self.num_entries())]
6982 r.append(self.else_value())
6983 return r
6984

Referenced by as_list().

◆ else_value()

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

6884 def else_value(self):
6885 """
6886 Return the `else` value for a function interpretation.
6887 Return None if Z3 did not specify the `else` value for
6888 this object.
6889
6890 >>> f = Function('f', IntSort(), IntSort())
6891 >>> s = Solver()
6892 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
6893 >>> s.check()
6894 sat
6895 >>> m = s.model()
6896 >>> m[f]
6897 [2 -> 0, else -> 1]
6898 >>> m[f].else_value()
6899 1
6900 """
6901 r = Z3_func_interp_get_else(self.ctx.ref(), self.f)
6902 if r:
6903 return _to_expr_ref(r, self.ctx)
6904 else:
6905 return None
6906
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.

Referenced by as_list().

◆ entry()

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

6937 def entry(self, idx):
6938 """Return an entry at position `idx < self.num_entries()` in the function interpretation `self`.
6939
6940 >>> f = Function('f', IntSort(), IntSort())
6941 >>> s = Solver()
6942 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
6943 >>> s.check()
6944 sat
6945 >>> m = s.model()
6946 >>> m[f]
6947 [2 -> 0, else -> 1]
6948 >>> m[f].num_entries()
6949 1
6950 >>> m[f].entry(0)
6951 [2, 0]
6952 """
6953 if idx >= self.num_entries():
6954 raise IndexError
6955 return FuncEntry(Z3_func_interp_get_entry(self.ctx.ref(), self.f, idx), self.ctx)
6956
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...

Referenced by as_list().

◆ num_entries()

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

6907 def num_entries(self):
6908 """Return the number of entries/points in the function interpretation `self`.
6909
6910 >>> f = Function('f', IntSort(), IntSort())
6911 >>> s = Solver()
6912 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
6913 >>> s.check()
6914 sat
6915 >>> m = s.model()
6916 >>> m[f]
6917 [2 -> 0, else -> 1]
6918 >>> m[f].num_entries()
6919 1
6920 """
6921 return int(Z3_func_interp_get_num_entries(self.ctx.ref(), self.f))
6922
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.

Referenced by as_list(), and entry().

◆ translate()

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

Definition at line 6957 of file z3py.py.

6957 def translate(self, other_ctx):
6958 """Copy model 'self' to context 'other_ctx'.
6959 """
6960 return ModelRef(Z3_model_translate(self.ctx.ref(), self.model, other_ctx.ref()), other_ctx)
6961
Z3_model Z3_API Z3_model_translate(Z3_context c, Z3_model m, Z3_context dst)
translate model from context c to context dst.

Referenced by __copy__(), ModelRef.__copy__(), __deepcopy__(), and ModelRef.__deepcopy__().

Field Documentation

◆ ctx

◆ f

f = f

Definition at line 6875 of file z3py.py.

Referenced by __del__(), arity(), else_value(), entry(), and num_entries().

◆ model