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

Public Member Functions

def __init__ (self, v=None, ctx=None)
 
def __deepcopy__ (self, memo={})
 
def __del__ (self)
 
def __len__ (self)
 
def __getitem__ (self, i)
 
def __setitem__ (self, i, v)
 
def push (self, v)
 
def resize (self, sz)
 
def __contains__ (self, item)
 
def translate (self, other_ctx)
 
def __copy__ (self)
 
def __deepcopy__ (self)
 
def __repr__ (self)
 
def sexpr (self)
 
- Public Member Functions inherited from Z3PPObject
def use_pp (self)
 

Data Fields

 vector
 
 ctx
 

Detailed Description

A collection (vector) of ASTs.

Definition at line 5392 of file z3py.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  v = None,
  ctx = None 
)

Definition at line 5395 of file z3py.py.

5395  def __init__(self, v=None, ctx=None):
5396  self.vector = None
5397  if v is None:
5398  self.ctx = _get_ctx(ctx)
5399  self.vector = Z3_mk_ast_vector(self.ctx.ref())
5400  else:
5401  self.vector = v
5402  assert ctx is not None
5403  self.ctx = ctx
5404  Z3_ast_vector_inc_ref(self.ctx.ref(), self.vector)
5405 
void Z3_API Z3_ast_vector_inc_ref(Z3_context c, Z3_ast_vector v)
Increment the reference counter of the given AST vector.
Z3_ast_vector Z3_API Z3_mk_ast_vector(Z3_context c)
Return an empty AST vector.

◆ __del__()

def __del__ (   self)

Definition at line 5409 of file z3py.py.

5409  def __del__(self):
5410  if self.vector is not None and self.ctx.ref() is not None:
5411  Z3_ast_vector_dec_ref(self.ctx.ref(), self.vector)
5412 
void Z3_API Z3_ast_vector_dec_ref(Z3_context c, Z3_ast_vector v)
Decrement the reference counter of the given AST vector.

Member Function Documentation

◆ __contains__()

def __contains__ (   self,
  item 
)
Return `True` if the vector contains `item`.

>>> x = Int('x')
>>> A = AstVector()
>>> x in A
False
>>> A.push(x)
>>> x in A
True
>>> (x+1) in A
False
>>> A.push(x+1)
>>> (x+1) in A
True
>>> A
[x, x + 1]

Definition at line 5491 of file z3py.py.

5491  def __contains__(self, item):
5492  """Return `True` if the vector contains `item`.
5493 
5494  >>> x = Int('x')
5495  >>> A = AstVector()
5496  >>> x in A
5497  False
5498  >>> A.push(x)
5499  >>> x in A
5500  True
5501  >>> (x+1) in A
5502  False
5503  >>> A.push(x+1)
5504  >>> (x+1) in A
5505  True
5506  >>> A
5507  [x, x + 1]
5508  """
5509  for elem in self:
5510  if elem.eq(item):
5511  return True
5512  return False
5513 

◆ __copy__()

def __copy__ (   self)

Definition at line 5527 of file z3py.py.

5527  def __copy__(self):
5528  return self.translate(self.ctx)
5529 

◆ __deepcopy__() [1/2]

def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 5406 of file z3py.py.

5406  def __deepcopy__(self, memo={}):
5407  return AstVector(self.vector, self.ctx)
5408 

Referenced by AstVector.__deepcopy__().

◆ __deepcopy__() [2/2]

def __deepcopy__ (   self)

Definition at line 5530 of file z3py.py.

5530  def __deepcopy__(self):
5531  return self.translate(self.ctx)
5532 

◆ __getitem__()

def __getitem__ (   self,
  i 
)
Return the AST at position `i`.

>>> A = AstVector()
>>> A.push(Int('x') + 1)
>>> A.push(Int('y'))
>>> A[0]
x + 1
>>> A[1]
y

Definition at line 5426 of file z3py.py.

5426  def __getitem__(self, i):
5427  """Return the AST at position `i`.
5428 
5429  >>> A = AstVector()
5430  >>> A.push(Int('x') + 1)
5431  >>> A.push(Int('y'))
5432  >>> A[0]
5433  x + 1
5434  >>> A[1]
5435  y
5436  """
5437 
5438  if isinstance(i, int):
5439  if i < 0:
5440  i += self.__len__()
5441 
5442  if i >= self.__len__():
5443  raise IndexError
5444  return _to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, i), self.ctx)
5445 
5446  elif isinstance(i, slice):
5447  return [_to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, ii), self.ctx) for ii in range(*i.indices(self.__len__()))]
5448 
5449 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3244
Z3_ast Z3_API Z3_ast_vector_get(Z3_context c, Z3_ast_vector v, unsigned i)
Return the AST at position i in the AST vector v.

◆ __len__()

def __len__ (   self)
Return the size of the vector `self`.

>>> A = AstVector()
>>> len(A)
0
>>> A.push(Int('x'))
>>> A.push(Int('x'))
>>> len(A)
2

Definition at line 5413 of file z3py.py.

5413  def __len__(self):
5414  """Return the size of the vector `self`.
5415 
5416  >>> A = AstVector()
5417  >>> len(A)
5418  0
5419  >>> A.push(Int('x'))
5420  >>> A.push(Int('x'))
5421  >>> len(A)
5422  2
5423  """
5424  return int(Z3_ast_vector_size(self.ctx.ref(), self.vector))
5425 
unsigned Z3_API Z3_ast_vector_size(Z3_context c, Z3_ast_vector v)
Return the size of the given AST vector.

Referenced by AstVector.__getitem__(), and AstVector.__setitem__().

◆ __repr__()

def __repr__ (   self)

Definition at line 5533 of file z3py.py.

5533  def __repr__(self):
5534  return obj_to_string(self)
5535 

◆ __setitem__()

def __setitem__ (   self,
  i,
  v 
)
Update AST at position `i`.

>>> A = AstVector()
>>> A.push(Int('x') + 1)
>>> A.push(Int('y'))
>>> A[0]
x + 1
>>> A[0] = Int('x')
>>> A[0]
x

Definition at line 5450 of file z3py.py.

5450  def __setitem__(self, i, v):
5451  """Update AST at position `i`.
5452 
5453  >>> A = AstVector()
5454  >>> A.push(Int('x') + 1)
5455  >>> A.push(Int('y'))
5456  >>> A[0]
5457  x + 1
5458  >>> A[0] = Int('x')
5459  >>> A[0]
5460  x
5461  """
5462  if i >= self.__len__():
5463  raise IndexError
5464  Z3_ast_vector_set(self.ctx.ref(), self.vector, i, v.as_ast())
5465 
void Z3_API Z3_ast_vector_set(Z3_context c, Z3_ast_vector v, unsigned i, Z3_ast a)
Update position i of the AST vector v with the AST a.

◆ push()

def push (   self,
  v 
)
Add `v` in the end of the vector.

>>> A = AstVector()
>>> len(A)
0
>>> A.push(Int('x'))
>>> len(A)
1

Definition at line 5466 of file z3py.py.

5466  def push(self, v):
5467  """Add `v` in the end of the vector.
5468 
5469  >>> A = AstVector()
5470  >>> len(A)
5471  0
5472  >>> A.push(Int('x'))
5473  >>> len(A)
5474  1
5475  """
5476  Z3_ast_vector_push(self.ctx.ref(), self.vector, v.as_ast())
5477 
void Z3_API Z3_ast_vector_push(Z3_context c, Z3_ast_vector v, Z3_ast a)
Add the AST a in the end of the AST vector v. The size of v is increased by one.

◆ resize()

def resize (   self,
  sz 
)
Resize the vector to `sz` elements.

>>> A = AstVector()
>>> A.resize(10)
>>> len(A)
10
>>> for i in range(10): A[i] = Int('x')
>>> A[5]
x

Definition at line 5478 of file z3py.py.

5478  def resize(self, sz):
5479  """Resize the vector to `sz` elements.
5480 
5481  >>> A = AstVector()
5482  >>> A.resize(10)
5483  >>> len(A)
5484  10
5485  >>> for i in range(10): A[i] = Int('x')
5486  >>> A[5]
5487  x
5488  """
5489  Z3_ast_vector_resize(self.ctx.ref(), self.vector, sz)
5490 
void Z3_API Z3_ast_vector_resize(Z3_context c, Z3_ast_vector v, unsigned n)
Resize the AST vector v.

◆ sexpr()

def sexpr (   self)
Return a textual representation of the s-expression representing the vector.

Definition at line 5536 of file z3py.py.

5536  def sexpr(self):
5537  """Return a textual representation of the s-expression representing the vector."""
5538  return Z3_ast_vector_to_string(self.ctx.ref(), self.vector)
5539 
Z3_string Z3_API Z3_ast_vector_to_string(Z3_context c, Z3_ast_vector v)
Convert AST vector into a string.

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

◆ translate()

def translate (   self,
  other_ctx 
)
Copy vector `self` to context `other_ctx`.

>>> x = Int('x')
>>> A = AstVector()
>>> A.push(x)
>>> c2 = Context()
>>> B = A.translate(c2)
>>> B
[x]

Definition at line 5514 of file z3py.py.

5514  def translate(self, other_ctx):
5515  """Copy vector `self` to context `other_ctx`.
5516 
5517  >>> x = Int('x')
5518  >>> A = AstVector()
5519  >>> A.push(x)
5520  >>> c2 = Context()
5521  >>> B = A.translate(c2)
5522  >>> B
5523  [x]
5524  """
5525  return AstVector(Z3_ast_vector_translate(self.ctx.ref(), self.vector, other_ctx.ref()), other_ctx)
5526 
Z3_ast_vector Z3_API Z3_ast_vector_translate(Z3_context s, Z3_ast_vector v, Z3_context t)
Translate the AST vector v from context s into an AST vector in context t.

Referenced by AstVector.__copy__(), FuncInterp.__copy__(), ModelRef.__copy__(), Solver.__copy__(), AstVector.__deepcopy__(), FuncInterp.__deepcopy__(), ModelRef.__deepcopy__(), and Solver.__deepcopy__().

Field Documentation

◆ ctx

ctx

Definition at line 5398 of file z3py.py.

Referenced by Probe.__call__(), AstMap.__contains__(), AstVector.__copy__(), FuncInterp.__copy__(), ModelRef.__copy__(), Solver.__copy__(), AstVector.__deepcopy__(), AstMap.__deepcopy__(), FuncEntry.__deepcopy__(), FuncInterp.__deepcopy__(), ModelRef.__deepcopy__(), Statistics.__deepcopy__(), Solver.__deepcopy__(), Fixedpoint.__deepcopy__(), Optimize.__deepcopy__(), ApplyResult.__deepcopy__(), Tactic.__deepcopy__(), Probe.__deepcopy__(), AstVector.__del__(), AstMap.__del__(), FuncEntry.__del__(), FuncInterp.__del__(), ModelRef.__del__(), Statistics.__del__(), Solver.__del__(), Fixedpoint.__del__(), Optimize.__del__(), ApplyResult.__del__(), Tactic.__del__(), Probe.__del__(), Probe.__eq__(), Probe.__ge__(), AstVector.__getitem__(), AstMap.__getitem__(), ModelRef.__getitem__(), Statistics.__getitem__(), ApplyResult.__getitem__(), Probe.__gt__(), Probe.__le__(), AstVector.__len__(), AstMap.__len__(), ModelRef.__len__(), Statistics.__len__(), ApplyResult.__len__(), Probe.__lt__(), Probe.__ne__(), AstMap.__repr__(), Statistics.__repr__(), AstVector.__setitem__(), AstMap.__setitem__(), Fixedpoint.add_cover(), Fixedpoint.add_rule(), Optimize.add_soft(), Tactic.apply(), FuncEntry.arg_value(), FuncInterp.arity(), ApplyResult.as_expr(), Solver.assert_and_track(), Solver.assert_exprs(), Fixedpoint.assert_exprs(), Optimize.assert_exprs(), Solver.assertions(), Optimize.assertions(), Solver.check(), Optimize.check(), Solver.consequences(), ModelRef.decls(), FuncInterp.else_value(), FuncInterp.entry(), AstMap.erase(), ModelRef.eval(), Solver.from_file(), Optimize.from_file(), Solver.from_string(), Optimize.from_string(), Fixedpoint.get_answer(), Fixedpoint.get_assertions(), Fixedpoint.get_cover_delta(), Fixedpoint.get_ground_sat_answer(), ModelRef.get_interp(), Statistics.get_key_value(), Fixedpoint.get_num_levels(), Fixedpoint.get_rule_names_along_trace(), Fixedpoint.get_rules(), Fixedpoint.get_rules_along_trace(), ModelRef.get_sort(), ModelRef.get_universe(), Solver.help(), Fixedpoint.help(), Optimize.help(), Tactic.help(), AstMap.keys(), Statistics.keys(), Optimize.maximize(), Optimize.minimize(), Solver.model(), Optimize.model(), Solver.non_units(), FuncEntry.num_args(), FuncInterp.num_entries(), Solver.num_scopes(), ModelRef.num_sorts(), Optimize.objectives(), Solver.param_descrs(), Fixedpoint.param_descrs(), Optimize.param_descrs(), Tactic.param_descrs(), Fixedpoint.parse_file(), Fixedpoint.parse_string(), Solver.pop(), Fixedpoint.pop(), Optimize.pop(), Solver.proof(), AstVector.push(), Solver.push(), Fixedpoint.push(), Optimize.push(), Fixedpoint.query(), Fixedpoint.query_from_lvl(), Solver.reason_unknown(), Fixedpoint.reason_unknown(), Optimize.reason_unknown(), Fixedpoint.register_relation(), AstMap.reset(), Solver.reset(), AstVector.resize(), Solver.set(), Fixedpoint.set(), Optimize.set(), Fixedpoint.set_predicate_representation(), AstVector.sexpr(), ModelRef.sexpr(), Solver.sexpr(), Fixedpoint.sexpr(), Optimize.sexpr(), ApplyResult.sexpr(), Tactic.solver(), Solver.statistics(), Fixedpoint.statistics(), Optimize.statistics(), Solver.to_smt2(), Fixedpoint.to_string(), AstVector.translate(), FuncInterp.translate(), ModelRef.translate(), Solver.translate(), Solver.units(), Solver.unsat_core(), Optimize.unsat_core(), Fixedpoint.update_rule(), and FuncEntry.value().

◆ vector

vector