Z3
Public Member Functions | Data Fields
ModelRef Class Reference
+ Inheritance diagram for ModelRef:

Public Member Functions

def __init__ (self, m, ctx)
 
def __del__ (self)
 
def __repr__ (self)
 
def sexpr (self)
 
def eval
 
def evaluate
 
def __len__ (self)
 
def get_interp (self, decl)
 
def num_sorts (self)
 
def get_sort (self, idx)
 
def sorts (self)
 
def get_universe (self, s)
 
def __getitem__ (self, idx)
 
def decls (self)
 
def update_value (self, x, value)
 
def translate (self, target)
 
def project (self, vars, fml)
 
def project_with_witness (self, vars, fml)
 
def __copy__ (self)
 
def __deepcopy__
 
- Public Member Functions inherited from Z3PPObject
def use_pp (self)
 

Data Fields

 model
 
 ctx
 

Detailed Description

Model/Solution of a satisfiability problem (aka system of constraints).

Definition at line 6600 of file z3py.py.

Constructor & Destructor Documentation

def __init__ (   self,
  m,
  ctx 
)

Definition at line 6603 of file z3py.py.

6603  def __init__(self, m, ctx):
6604  assert ctx is not None
6605  self.model = m
6606  self.ctx = ctx
6607  Z3_model_inc_ref(self.ctx.ref(), self.model)
6608 
def __init__(self, m, ctx)
Definition: z3py.py:6603
void Z3_API Z3_model_inc_ref(Z3_context c, Z3_model m)
Increment the reference counter of the given model.
def __del__ (   self)

Definition at line 6609 of file z3py.py.

6609  def __del__(self):
6610  if self.ctx.ref() is not None and Z3_model_dec_ref is not None:
6611  Z3_model_dec_ref(self.ctx.ref(), self.model)
6612 
def __del__(self)
Definition: z3py.py:6609
void Z3_API Z3_model_dec_ref(Z3_context c, Z3_model m)
Decrement the reference counter of the given model.

Member Function Documentation

def __copy__ (   self)

Definition at line 6941 of file z3py.py.

6941  def __copy__(self):
6942  return self.translate(self.ctx)
6943 
def __copy__(self)
Definition: z3py.py:6941
def translate(self, target)
Definition: z3py.py:6909
def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 6944 of file z3py.py.

6944  def __deepcopy__(self, memo={}):
6945  return self.translate(self.ctx)
6946 
6947 
def __deepcopy__
Definition: z3py.py:6944
def translate(self, target)
Definition: z3py.py:6909
def __getitem__ (   self,
  idx 
)
If `idx` is an integer, then the declaration at position `idx` in the model `self` is returned.
If `idx` is a declaration, then the actual interpretation is returned.

The elements can be retrieved using position or the actual declaration.

>>> f = Function('f', IntSort(), IntSort())
>>> x = Int('x')
>>> s = Solver()
>>> s.add(x > 0, x < 2, f(x) == 0)
>>> s.check()
sat
>>> m = s.model()
>>> len(m)
2
>>> m[0]
x
>>> m[1]
f
>>> m[x]
1
>>> m[f]
[else -> 0]
>>> for d in m: print("%s -> %s" % (d, m[d]))
x -> 1
f -> [else -> 0]

Definition at line 6821 of file z3py.py.

6821  def __getitem__(self, idx):
6822  """If `idx` is an integer, then the declaration at position `idx` in the model `self` is returned.
6823  If `idx` is a declaration, then the actual interpretation is returned.
6824 
6825  The elements can be retrieved using position or the actual declaration.
6826 
6827  >>> f = Function('f', IntSort(), IntSort())
6828  >>> x = Int('x')
6829  >>> s = Solver()
6830  >>> s.add(x > 0, x < 2, f(x) == 0)
6831  >>> s.check()
6832  sat
6833  >>> m = s.model()
6834  >>> len(m)
6835  2
6836  >>> m[0]
6837  x
6838  >>> m[1]
6839  f
6840  >>> m[x]
6841  1
6842  >>> m[f]
6843  [else -> 0]
6844  >>> for d in m: print("%s -> %s" % (d, m[d]))
6845  x -> 1
6846  f -> [else -> 0]
6847  """
6848  if _is_int(idx):
6849  if idx < 0:
6850  idx += len(self)
6851  if idx < 0 or idx >= len(self):
6852  raise IndexError
6853  num_consts = Z3_model_get_num_consts(self.ctx.ref(), self.model)
6854  if (idx < num_consts):
6855  return FuncDeclRef(Z3_model_get_const_decl(self.ctx.ref(), self.model, idx), self.ctx)
6856  else:
6857  return FuncDeclRef(Z3_model_get_func_decl(self.ctx.ref(), self.model, idx - num_consts), self.ctx)
6858  if isinstance(idx, FuncDeclRef):
6859  return self.get_interp(idx)
6860  if is_const(idx):
6861  return self.get_interp(idx.decl())
6862  if isinstance(idx, SortRef):
6863  return self.get_universe(idx)
6864  if z3_debug():
6865  _z3_assert(False, "Integer, Z3 declaration, or Z3 constant expected. Use model.eval instead for complicated expressions")
6866  return None
6867 
Function Declarations.
Definition: z3py.py:775
Z3_func_decl Z3_API Z3_model_get_func_decl(Z3_context c, Z3_model m, unsigned i)
Return the declaration of the i-th function in the given model.
Z3_func_decl Z3_API Z3_model_get_const_decl(Z3_context c, Z3_model m, unsigned i)
Return the i-th constant in the given model.
def get_universe(self, s)
Definition: z3py.py:6801
def is_const(a)
Definition: z3py.py:1394
def __getitem__(self, idx)
Definition: z3py.py:6821
unsigned Z3_API Z3_model_get_num_consts(Z3_context c, Z3_model m)
Return the number of constants assigned by the given model.
def z3_debug()
Definition: z3py.py:70
def get_interp(self, decl)
Definition: z3py.py:6694
def __len__ (   self)
Return the number of constant and function declarations in the model `self`.

>>> f = Function('f', IntSort(), IntSort())
>>> x = Int('x')
>>> s = Solver()
>>> s.add(x > 0, f(x) != x)
>>> s.check()
sat
>>> m = s.model()
>>> len(m)
2

Definition at line 6677 of file z3py.py.

6677  def __len__(self):
6678  """Return the number of constant and function declarations in the model `self`.
6679 
6680  >>> f = Function('f', IntSort(), IntSort())
6681  >>> x = Int('x')
6682  >>> s = Solver()
6683  >>> s.add(x > 0, f(x) != x)
6684  >>> s.check()
6685  sat
6686  >>> m = s.model()
6687  >>> len(m)
6688  2
6689  """
6690  num_consts = int(Z3_model_get_num_consts(self.ctx.ref(), self.model))
6691  num_funcs = int(Z3_model_get_num_funcs(self.ctx.ref(), self.model))
6692  return num_consts + num_funcs
6693 
def __len__(self)
Definition: z3py.py:6677
unsigned Z3_API Z3_model_get_num_consts(Z3_context c, Z3_model m)
Return the number of constants assigned by the given model.
unsigned Z3_API Z3_model_get_num_funcs(Z3_context c, Z3_model m)
Return the number of function interpretations in the given model.
def __repr__ (   self)

Definition at line 6613 of file z3py.py.

6613  def __repr__(self):
6614  return obj_to_string(self)
6615 
def __repr__(self)
Definition: z3py.py:6613
def decls (   self)
Return a list with all symbols that have an interpretation in the model `self`.
>>> f = Function('f', IntSort(), IntSort())
>>> x = Int('x')
>>> s = Solver()
>>> s.add(x > 0, x < 2, f(x) == 0)
>>> s.check()
sat
>>> m = s.model()
>>> m.decls()
[x, f]

Definition at line 6868 of file z3py.py.

6868  def decls(self):
6869  """Return a list with all symbols that have an interpretation in the model `self`.
6870  >>> f = Function('f', IntSort(), IntSort())
6871  >>> x = Int('x')
6872  >>> s = Solver()
6873  >>> s.add(x > 0, x < 2, f(x) == 0)
6874  >>> s.check()
6875  sat
6876  >>> m = s.model()
6877  >>> m.decls()
6878  [x, f]
6879  """
6880  r = []
6881  for i in range(Z3_model_get_num_consts(self.ctx.ref(), self.model)):
6882  r.append(FuncDeclRef(Z3_model_get_const_decl(self.ctx.ref(), self.model, i), self.ctx))
6883  for i in range(Z3_model_get_num_funcs(self.ctx.ref(), self.model)):
6884  r.append(FuncDeclRef(Z3_model_get_func_decl(self.ctx.ref(), self.model, i), self.ctx))
6885  return r
6886 
Function Declarations.
Definition: z3py.py:775
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:4343
Z3_func_decl Z3_API Z3_model_get_func_decl(Z3_context c, Z3_model m, unsigned i)
Return the declaration of the i-th function in the given model.
Z3_func_decl Z3_API Z3_model_get_const_decl(Z3_context c, Z3_model m, unsigned i)
Return the i-th constant in the given model.
unsigned Z3_API Z3_model_get_num_consts(Z3_context c, Z3_model m)
Return the number of constants assigned by the given model.
unsigned Z3_API Z3_model_get_num_funcs(Z3_context c, Z3_model m)
Return the number of function interpretations in the given model.
def decls(self)
Definition: z3py.py:6868
def eval (   self,
  t,
  model_completion = False 
)
Evaluate the expression `t` in the model `self`.
If `model_completion` is enabled, then a default interpretation is automatically added
for symbols that do not have an interpretation in the model `self`.

>>> x = Int('x')
>>> s = Solver()
>>> s.add(x > 0, x < 2)
>>> s.check()
sat
>>> m = s.model()
>>> m.eval(x + 1)
2
>>> m.eval(x == 1)
True
>>> y = Int('y')
>>> m.eval(y + x)
1 + y
>>> m.eval(y)
y
>>> m.eval(y, model_completion=True)
0
>>> # Now, m contains an interpretation for y
>>> m.eval(y + x)
1

Definition at line 6620 of file z3py.py.

6620  def eval(self, t, model_completion=False):
6621  """Evaluate the expression `t` in the model `self`.
6622  If `model_completion` is enabled, then a default interpretation is automatically added
6623  for symbols that do not have an interpretation in the model `self`.
6624 
6625  >>> x = Int('x')
6626  >>> s = Solver()
6627  >>> s.add(x > 0, x < 2)
6628  >>> s.check()
6629  sat
6630  >>> m = s.model()
6631  >>> m.eval(x + 1)
6632  2
6633  >>> m.eval(x == 1)
6634  True
6635  >>> y = Int('y')
6636  >>> m.eval(y + x)
6637  1 + y
6638  >>> m.eval(y)
6639  y
6640  >>> m.eval(y, model_completion=True)
6641  0
6642  >>> # Now, m contains an interpretation for y
6643  >>> m.eval(y + x)
6644  1
6645  """
6646  r = (Ast * 1)()
6647  if Z3_model_eval(self.ctx.ref(), self.model, t.as_ast(), model_completion, r):
6648  return _to_expr_ref(r[0], self.ctx)
6649  raise Z3Exception("failed to evaluate expression in the model")
6650 
bool Z3_API Z3_model_eval(Z3_context c, Z3_model m, Z3_ast t, bool model_completion, Z3_ast *v)
Evaluate the AST node t in the given model. Return true if succeeded, and store the result in v...
def eval
Definition: z3py.py:6620
def evaluate (   self,
  t,
  model_completion = False 
)
Alias for `eval`.

>>> x = Int('x')
>>> s = Solver()
>>> s.add(x > 0, x < 2)
>>> s.check()
sat
>>> m = s.model()
>>> m.evaluate(x + 1)
2
>>> m.evaluate(x == 1)
True
>>> y = Int('y')
>>> m.evaluate(y + x)
1 + y
>>> m.evaluate(y)
y
>>> m.evaluate(y, model_completion=True)
0
>>> # Now, m contains an interpretation for y
>>> m.evaluate(y + x)
1

Definition at line 6651 of file z3py.py.

6651  def evaluate(self, t, model_completion=False):
6652  """Alias for `eval`.
6653 
6654  >>> x = Int('x')
6655  >>> s = Solver()
6656  >>> s.add(x > 0, x < 2)
6657  >>> s.check()
6658  sat
6659  >>> m = s.model()
6660  >>> m.evaluate(x + 1)
6661  2
6662  >>> m.evaluate(x == 1)
6663  True
6664  >>> y = Int('y')
6665  >>> m.evaluate(y + x)
6666  1 + y
6667  >>> m.evaluate(y)
6668  y
6669  >>> m.evaluate(y, model_completion=True)
6670  0
6671  >>> # Now, m contains an interpretation for y
6672  >>> m.evaluate(y + x)
6673  1
6674  """
6675  return self.eval(t, model_completion)
6676 
def evaluate
Definition: z3py.py:6651
def eval
Definition: z3py.py:6620
def get_interp (   self,
  decl 
)
Return the interpretation for a given declaration or constant.

>>> f = Function('f', IntSort(), IntSort())
>>> x = Int('x')
>>> s = Solver()
>>> s.add(x > 0, x < 2, f(x) == 0)
>>> s.check()
sat
>>> m = s.model()
>>> m[x]
1
>>> m[f]
[else -> 0]

Definition at line 6694 of file z3py.py.

Referenced by ModelRef.__getitem__().

6694  def get_interp(self, decl):
6695  """Return the interpretation for a given declaration or constant.
6696 
6697  >>> f = Function('f', IntSort(), IntSort())
6698  >>> x = Int('x')
6699  >>> s = Solver()
6700  >>> s.add(x > 0, x < 2, f(x) == 0)
6701  >>> s.check()
6702  sat
6703  >>> m = s.model()
6704  >>> m[x]
6705  1
6706  >>> m[f]
6707  [else -> 0]
6708  """
6709  if z3_debug():
6710  _z3_assert(isinstance(decl, FuncDeclRef) or is_const(decl), "Z3 declaration expected")
6711  if is_const(decl):
6712  decl = decl.decl()
6713  try:
6714  if decl.arity() == 0:
6715  _r = Z3_model_get_const_interp(self.ctx.ref(), self.model, decl.ast)
6716  if _r.value is None:
6717  return None
6718  r = _to_expr_ref(_r, self.ctx)
6719  if is_as_array(r):
6720  fi = self.get_interp(get_as_array_func(r))
6721  if fi is None:
6722  return fi
6723  e = fi.else_value()
6724  if e is None:
6725  return fi
6726  if fi.arity() != 1:
6727  return fi
6728  srt = decl.range()
6729  dom = srt.domain()
6730  e = K(dom, e)
6731  i = 0
6732  sz = fi.num_entries()
6733  n = fi.arity()
6734  while i < sz:
6735  fe = fi.entry(i)
6736  e = Store(e, fe.arg_value(0), fe.value())
6737  i += 1
6738  return e
6739  else:
6740  return r
6741  else:
6742  return FuncInterp(Z3_model_get_func_interp(self.ctx.ref(), self.model, decl.ast), self.ctx)
6743  except Z3Exception:
6744  return None
6745 
def Store(a, args)
Definition: z3py.py:4980
def is_const(a)
Definition: z3py.py:1394
def get_as_array_func(n)
Definition: z3py.py:6961
Z3_func_interp Z3_API Z3_model_get_func_interp(Z3_context c, Z3_model m, Z3_func_decl f)
Return the interpretation of the function f in the model m. Return NULL, if the model does not assign...
Z3_ast Z3_API Z3_model_get_const_interp(Z3_context c, Z3_model m, Z3_func_decl a)
Return the interpretation (i.e., assignment) of constant a in the model m. Return NULL...
def z3_debug()
Definition: z3py.py:70
def get_interp(self, decl)
Definition: z3py.py:6694
def is_as_array(n)
Definition: z3py.py:6956
def K(dom, v)
Definition: z3py.py:5036
def get_sort (   self,
  idx 
)
Return the uninterpreted sort at position `idx` < self.num_sorts().

>>> A = DeclareSort('A')
>>> B = DeclareSort('B')
>>> a1, a2 = Consts('a1 a2', A)
>>> b1, b2 = Consts('b1 b2', B)
>>> s = Solver()
>>> s.add(a1 != a2, b1 != b2)
>>> s.check()
sat
>>> m = s.model()
>>> m.num_sorts()
2
>>> m.get_sort(0)
A
>>> m.get_sort(1)
B

Definition at line 6761 of file z3py.py.

6761  def get_sort(self, idx):
6762  """Return the uninterpreted sort at position `idx` < self.num_sorts().
6763 
6764  >>> A = DeclareSort('A')
6765  >>> B = DeclareSort('B')
6766  >>> a1, a2 = Consts('a1 a2', A)
6767  >>> b1, b2 = Consts('b1 b2', B)
6768  >>> s = Solver()
6769  >>> s.add(a1 != a2, b1 != b2)
6770  >>> s.check()
6771  sat
6772  >>> m = s.model()
6773  >>> m.num_sorts()
6774  2
6775  >>> m.get_sort(0)
6776  A
6777  >>> m.get_sort(1)
6778  B
6779  """
6780  if idx >= self.num_sorts():
6781  raise IndexError
6782  return _to_sort_ref(Z3_model_get_sort(self.ctx.ref(), self.model, idx), self.ctx)
6783 
Z3_sort Z3_API Z3_model_get_sort(Z3_context c, Z3_model m, unsigned i)
Return a uninterpreted sort that m assigns an interpretation.
def num_sorts(self)
Definition: z3py.py:6746
def get_sort(self, idx)
Definition: z3py.py:6761
def get_universe (   self,
  s 
)
Return the interpretation for the uninterpreted sort `s` in the model `self`.

>>> A = DeclareSort('A')
>>> a, b = Consts('a b', A)
>>> s = Solver()
>>> s.add(a != b)
>>> s.check()
sat
>>> m = s.model()
>>> m.get_universe(A)
[A!val!1, A!val!0]

Definition at line 6801 of file z3py.py.

Referenced by ModelRef.__getitem__().

6801  def get_universe(self, s):
6802  """Return the interpretation for the uninterpreted sort `s` in the model `self`.
6803 
6804  >>> A = DeclareSort('A')
6805  >>> a, b = Consts('a b', A)
6806  >>> s = Solver()
6807  >>> s.add(a != b)
6808  >>> s.check()
6809  sat
6810  >>> m = s.model()
6811  >>> m.get_universe(A)
6812  [A!val!1, A!val!0]
6813  """
6814  if z3_debug():
6815  _z3_assert(isinstance(s, SortRef), "Z3 sort expected")
6816  try:
6817  return AstVector(Z3_model_get_sort_universe(self.ctx.ref(), self.model, s.ast), self.ctx)
6818  except Z3Exception:
6819  return None
6820 
Z3_ast_vector Z3_API Z3_model_get_sort_universe(Z3_context c, Z3_model m, Z3_sort s)
Return the finite set of distinct values that represent the interpretation for sort s...
def get_universe(self, s)
Definition: z3py.py:6801
def z3_debug()
Definition: z3py.py:70
def num_sorts (   self)
Return the number of uninterpreted sorts that contain an interpretation in the model `self`.

>>> A = DeclareSort('A')
>>> a, b = Consts('a b', A)
>>> s = Solver()
>>> s.add(a != b)
>>> s.check()
sat
>>> m = s.model()
>>> m.num_sorts()
1

Definition at line 6746 of file z3py.py.

Referenced by ModelRef.get_sort().

6746  def num_sorts(self):
6747  """Return the number of uninterpreted sorts that contain an interpretation in the model `self`.
6748 
6749  >>> A = DeclareSort('A')
6750  >>> a, b = Consts('a b', A)
6751  >>> s = Solver()
6752  >>> s.add(a != b)
6753  >>> s.check()
6754  sat
6755  >>> m = s.model()
6756  >>> m.num_sorts()
6757  1
6758  """
6759  return int(Z3_model_get_num_sorts(self.ctx.ref(), self.model))
6760 
unsigned Z3_API Z3_model_get_num_sorts(Z3_context c, Z3_model m)
Return the number of uninterpreted sorts that m assigns an interpretation to.
def num_sorts(self)
Definition: z3py.py:6746
def project (   self,
  vars,
  fml 
)
Perform model-based projection on fml with respect to vars.
Assume that the model satisfies fml. Then compute a projection fml_p, such
that vars do not occur free in fml_p, fml_p is true in the model and
fml_p => exists vars . fml

Definition at line 6917 of file z3py.py.

6917  def project(self, vars, fml):
6918  """Perform model-based projection on fml with respect to vars.
6919  Assume that the model satisfies fml. Then compute a projection fml_p, such
6920  that vars do not occur free in fml_p, fml_p is true in the model and
6921  fml_p => exists vars . fml
6922  """
6923  ctx = self.ctx.ref()
6924  _vars = (Ast * len(vars))()
6925  for i in range(len(vars)):
6926  _vars[i] = vars[i].as_ast()
6927  return _to_expr_ref(Z3_qe_model_project(ctx, self.model, len(vars), _vars, fml.ast), self.ctx)
6928 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:4343
def project(self, vars, fml)
Definition: z3py.py:6917
def project_with_witness (   self,
  vars,
  fml 
)
Perform model-based projection, but also include realizer terms for the projected variables

Definition at line 6929 of file z3py.py.

6929  def project_with_witness(self, vars, fml):
6930  """Perform model-based projection, but also include realizer terms for the projected variables"""
6931  ctx = self.ctx.ref()
6932  _vars = (Ast * len(vars))()
6933  for i in range(len(vars)):
6934  _vars[i] = vars[i].as_ast()
6935  defs = AstMap()
6936  result = Z3_qe_model_project_with_witness(ctx, self.model, len(vars), _vars, fml.ast, defs.map)
6937  result = _to_expr_ref(result, self.ctx)
6938  return result, defs
6939 
6940 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:4343
def project_with_witness(self, vars, fml)
Definition: z3py.py:6929
def sexpr (   self)
Return a textual representation of the s-expression representing the model.

Definition at line 6616 of file z3py.py.

Referenced by Fixedpoint.__repr__(), and Optimize.__repr__().

6616  def sexpr(self):
6617  """Return a textual representation of the s-expression representing the model."""
6618  return Z3_model_to_string(self.ctx.ref(), self.model)
6619 
def sexpr(self)
Definition: z3py.py:6616
Z3_string Z3_API Z3_model_to_string(Z3_context c, Z3_model m)
Convert the given model into a string.
def sorts (   self)
Return all uninterpreted sorts that have an interpretation in the model `self`.

>>> A = DeclareSort('A')
>>> B = DeclareSort('B')
>>> a1, a2 = Consts('a1 a2', A)
>>> b1, b2 = Consts('b1 b2', B)
>>> s = Solver()
>>> s.add(a1 != a2, b1 != b2)
>>> s.check()
sat
>>> m = s.model()
>>> m.sorts()
[A, B]

Definition at line 6784 of file z3py.py.

6784  def sorts(self):
6785  """Return all uninterpreted sorts that have an interpretation in the model `self`.
6786 
6787  >>> A = DeclareSort('A')
6788  >>> B = DeclareSort('B')
6789  >>> a1, a2 = Consts('a1 a2', A)
6790  >>> b1, b2 = Consts('b1 b2', B)
6791  >>> s = Solver()
6792  >>> s.add(a1 != a2, b1 != b2)
6793  >>> s.check()
6794  sat
6795  >>> m = s.model()
6796  >>> m.sorts()
6797  [A, B]
6798  """
6799  return [self.get_sort(i) for i in range(self.num_sorts())]
6800 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:4343
def sorts(self)
Definition: z3py.py:6784
def num_sorts(self)
Definition: z3py.py:6746
def get_sort(self, idx)
Definition: z3py.py:6761
def translate (   self,
  target 
)
Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.

Definition at line 6909 of file z3py.py.

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

6909  def translate(self, target):
6910  """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
6911  """
6912  if z3_debug():
6913  _z3_assert(isinstance(target, Context), "argument must be a Z3 context")
6914  model = Z3_model_translate(self.ctx.ref(), self.model, target.ref())
6915  return ModelRef(model, target)
6916 
Z3_model Z3_API Z3_model_translate(Z3_context c, Z3_model m, Z3_context dst)
translate model from context c to context dst.
def z3_debug()
Definition: z3py.py:70
def translate(self, target)
Definition: z3py.py:6909
def update_value (   self,
  x,
  value 
)
Update the interpretation of a constant

Definition at line 6887 of file z3py.py.

6887  def update_value(self, x, value):
6888  """Update the interpretation of a constant"""
6889  if is_expr(x):
6890  x = x.decl()
6891  if is_func_decl(x) and x.arity() != 0 and isinstance(value, FuncInterp):
6892  fi1 = value.f
6893  fi2 = Z3_add_func_interp(x.ctx_ref(), self.model, x.ast, value.else_value().ast);
6894  fi2 = FuncInterp(fi2, x.ctx)
6895  for i in range(value.num_entries()):
6896  e = value.entry(i)
6897  n = Z3_func_entry_get_num_args(x.ctx_ref(), e.entry)
6898  v = AstVector()
6899  for j in range(n):
6900  v.push(e.arg_value(j))
6901  val = Z3_func_entry_get_value(x.ctx_ref(), e.entry)
6902  Z3_func_interp_add_entry(x.ctx_ref(), fi2.f, v.vector, val)
6903  return
6904  if not is_func_decl(x) or x.arity() != 0:
6905  raise Z3Exception("Expecting 0-ary function or constant expression")
6906  value = _py2expr(value)
6907  Z3_add_const_interp(x.ctx_ref(), self.model, x.ast, value.ast)
6908 
void Z3_API Z3_add_const_interp(Z3_context c, Z3_model m, Z3_func_decl f, Z3_ast a)
Add a constant interpretation.
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:4343
Z3_func_interp Z3_API Z3_add_func_interp(Z3_context c, Z3_model m, Z3_func_decl f, Z3_ast default_value)
Create a fresh func_interp object, add it to a model for a specified function. It has reference count...
def update_value(self, x, value)
Definition: z3py.py:6887
Z3_ast Z3_API Z3_func_entry_get_value(Z3_context c, Z3_func_entry e)
Return the value of this point.
unsigned Z3_API Z3_func_entry_get_num_args(Z3_context c, Z3_func_entry e)
Return the number of arguments in a Z3_func_entry object.
void Z3_API Z3_func_interp_add_entry(Z3_context c, Z3_func_interp fi, Z3_ast_vector args, Z3_ast value)
add a function entry to a function interpretation.
def is_expr(a)
Definition: z3py.py:1345
def is_func_decl(a)
Definition: z3py.py:907

Field Documentation

ctx
model