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

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 5438 of file z3py.py.

5438  def __init__(self, v=None, ctx=None):
5439  self.vector = None
5440  if v is None:
5441  self.ctx = _get_ctx(ctx)
5442  self.vector = Z3_mk_ast_vector(self.ctx.ref())
5443  else:
5444  self.vector = v
5445  assert ctx is not None
5446  self.ctx = ctx
5447  Z3_ast_vector_inc_ref(self.ctx.ref(), self.vector)
5448 
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 5452 of file z3py.py.

5452  def __del__(self):
5453  if self.vector is not None and self.ctx.ref() is not None:
5454  Z3_ast_vector_dec_ref(self.ctx.ref(), self.vector)
5455 
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 5534 of file z3py.py.

5534  def __contains__(self, item):
5535  """Return `True` if the vector contains `item`.
5536 
5537  >>> x = Int('x')
5538  >>> A = AstVector()
5539  >>> x in A
5540  False
5541  >>> A.push(x)
5542  >>> x in A
5543  True
5544  >>> (x+1) in A
5545  False
5546  >>> A.push(x+1)
5547  >>> (x+1) in A
5548  True
5549  >>> A
5550  [x, x + 1]
5551  """
5552  for elem in self:
5553  if elem.eq(item):
5554  return True
5555  return False
5556 

◆ __copy__()

def __copy__ (   self)

Definition at line 5570 of file z3py.py.

5570  def __copy__(self):
5571  return self.translate(self.ctx)
5572 

◆ __deepcopy__() [1/2]

def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 5449 of file z3py.py.

5449  def __deepcopy__(self, memo={}):
5450  return AstVector(self.vector, self.ctx)
5451 

◆ __deepcopy__() [2/2]

def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 5573 of file z3py.py.

5573  def __deepcopy__(self, memo={}):
5574  return self.translate(self.ctx)
5575 

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

5469  def __getitem__(self, i):
5470  """Return the AST at position `i`.
5471 
5472  >>> A = AstVector()
5473  >>> A.push(Int('x') + 1)
5474  >>> A.push(Int('y'))
5475  >>> A[0]
5476  x + 1
5477  >>> A[1]
5478  y
5479  """
5480 
5481  if isinstance(i, int):
5482  if i < 0:
5483  i += self.__len__()
5484 
5485  if i >= self.__len__():
5486  raise IndexError
5487  return _to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, i), self.ctx)
5488 
5489  elif isinstance(i, slice):
5490  return [_to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, ii), self.ctx) for ii in range(*i.indices(self.__len__()))]
5491 
5492 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3358
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 5456 of file z3py.py.

5456  def __len__(self):
5457  """Return the size of the vector `self`.
5458 
5459  >>> A = AstVector()
5460  >>> len(A)
5461  0
5462  >>> A.push(Int('x'))
5463  >>> A.push(Int('x'))
5464  >>> len(A)
5465  2
5466  """
5467  return int(Z3_ast_vector_size(self.ctx.ref(), self.vector))
5468 
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 5576 of file z3py.py.

5576  def __repr__(self):
5577  return obj_to_string(self)
5578 

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

5493  def __setitem__(self, i, v):
5494  """Update AST at position `i`.
5495 
5496  >>> A = AstVector()
5497  >>> A.push(Int('x') + 1)
5498  >>> A.push(Int('y'))
5499  >>> A[0]
5500  x + 1
5501  >>> A[0] = Int('x')
5502  >>> A[0]
5503  x
5504  """
5505  if i >= self.__len__():
5506  raise IndexError
5507  Z3_ast_vector_set(self.ctx.ref(), self.vector, i, v.as_ast())
5508 
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 5509 of file z3py.py.

5509  def push(self, v):
5510  """Add `v` in the end of the vector.
5511 
5512  >>> A = AstVector()
5513  >>> len(A)
5514  0
5515  >>> A.push(Int('x'))
5516  >>> len(A)
5517  1
5518  """
5519  Z3_ast_vector_push(self.ctx.ref(), self.vector, v.as_ast())
5520 
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 5521 of file z3py.py.

5521  def resize(self, sz):
5522  """Resize the vector to `sz` elements.
5523 
5524  >>> A = AstVector()
5525  >>> A.resize(10)
5526  >>> len(A)
5527  10
5528  >>> for i in range(10): A[i] = Int('x')
5529  >>> A[5]
5530  x
5531  """
5532  Z3_ast_vector_resize(self.ctx.ref(), self.vector, sz)
5533 
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 5579 of file z3py.py.

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

5579  def sexpr(self):
5580  """Return a textual representation of the s-expression representing the vector."""
5581  return Z3_ast_vector_to_string(self.ctx.ref(), self.vector)
5582 
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 5557 of file z3py.py.

5557  def translate(self, other_ctx):
5558  """Copy vector `self` to context `other_ctx`.
5559 
5560  >>> x = Int('x')
5561  >>> A = AstVector()
5562  >>> A.push(x)
5563  >>> c2 = Context()
5564  >>> B = A.translate(c2)
5565  >>> B
5566  [x]
5567  """
5568  return AstVector(Z3_ast_vector_translate(self.ctx.ref(), self.vector, other_ctx.ref()), other_ctx)
5569 
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 5441 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().

◆ vector

vector

Definition at line 5439 of file z3py.py.