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

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 5389 of file z3py.py.

5389  def __init__(self, v=None, ctx=None):
5390  self.vector = None
5391  if v is None:
5392  self.ctx = _get_ctx(ctx)
5393  self.vector = Z3_mk_ast_vector(self.ctx.ref())
5394  else:
5395  self.vector = v
5396  assert ctx is not None
5397  self.ctx = ctx
5398  Z3_ast_vector_inc_ref(self.ctx.ref(), self.vector)
5399 
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 5403 of file z3py.py.

5403  def __del__(self):
5404  if self.vector is not None and self.ctx.ref() is not None:
5405  Z3_ast_vector_dec_ref(self.ctx.ref(), self.vector)
5406 
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 5485 of file z3py.py.

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

◆ __copy__()

def __copy__ (   self)

Definition at line 5521 of file z3py.py.

5521  def __copy__(self):
5522  return self.translate(self.ctx)
5523 

◆ __deepcopy__() [1/2]

def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 5400 of file z3py.py.

5400  def __deepcopy__(self, memo={}):
5401  return AstVector(self.vector, self.ctx)
5402 

◆ __deepcopy__() [2/2]

def __deepcopy__ (   self)

Definition at line 5524 of file z3py.py.

5524  def __deepcopy__(self):
5525  return self.translate(self.ctx)
5526 

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

5420  def __getitem__(self, i):
5421  """Return the AST at position `i`.
5422 
5423  >>> A = AstVector()
5424  >>> A.push(Int('x') + 1)
5425  >>> A.push(Int('y'))
5426  >>> A[0]
5427  x + 1
5428  >>> A[1]
5429  y
5430  """
5431 
5432  if isinstance(i, int):
5433  if i < 0:
5434  i += self.__len__()
5435 
5436  if i >= self.__len__():
5437  raise IndexError
5438  return _to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, i), self.ctx)
5439 
5440  elif isinstance(i, slice):
5441  return [_to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, ii), self.ctx) for ii in range(*i.indices(self.__len__()))]
5442 
5443 
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 5407 of file z3py.py.

5407  def __len__(self):
5408  """Return the size of the vector `self`.
5409 
5410  >>> A = AstVector()
5411  >>> len(A)
5412  0
5413  >>> A.push(Int('x'))
5414  >>> A.push(Int('x'))
5415  >>> len(A)
5416  2
5417  """
5418  return int(Z3_ast_vector_size(self.ctx.ref(), self.vector))
5419 
unsigned Z3_API Z3_ast_vector_size(Z3_context c, Z3_ast_vector v)
Return the size of the given AST vector.

◆ __repr__()

def __repr__ (   self)

Definition at line 5527 of file z3py.py.

5527  def __repr__(self):
5528  return obj_to_string(self)
5529 

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

5444  def __setitem__(self, i, v):
5445  """Update AST at position `i`.
5446 
5447  >>> A = AstVector()
5448  >>> A.push(Int('x') + 1)
5449  >>> A.push(Int('y'))
5450  >>> A[0]
5451  x + 1
5452  >>> A[0] = Int('x')
5453  >>> A[0]
5454  x
5455  """
5456  if i >= self.__len__():
5457  raise IndexError
5458  Z3_ast_vector_set(self.ctx.ref(), self.vector, i, v.as_ast())
5459 
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 5460 of file z3py.py.

5460  def push(self, v):
5461  """Add `v` in the end of the vector.
5462 
5463  >>> A = AstVector()
5464  >>> len(A)
5465  0
5466  >>> A.push(Int('x'))
5467  >>> len(A)
5468  1
5469  """
5470  Z3_ast_vector_push(self.ctx.ref(), self.vector, v.as_ast())
5471 
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 5472 of file z3py.py.

5472  def resize(self, sz):
5473  """Resize the vector to `sz` elements.
5474 
5475  >>> A = AstVector()
5476  >>> A.resize(10)
5477  >>> len(A)
5478  10
5479  >>> for i in range(10): A[i] = Int('x')
5480  >>> A[5]
5481  x
5482  """
5483  Z3_ast_vector_resize(self.ctx.ref(), self.vector, sz)
5484 
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 5530 of file z3py.py.

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

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

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

5508  def translate(self, other_ctx):
5509  """Copy vector `self` to context `other_ctx`.
5510 
5511  >>> x = Int('x')
5512  >>> A = AstVector()
5513  >>> A.push(x)
5514  >>> c2 = Context()
5515  >>> B = A.translate(c2)
5516  >>> B
5517  [x]
5518  """
5519  return AstVector(Z3_ast_vector_translate(self.ctx.ref(), self.vector, other_ctx.ref()), other_ctx)
5520 
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.

Field Documentation

◆ ctx

ctx

Definition at line 5392 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().

◆ vector

vector

Definition at line 5390 of file z3py.py.