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

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 5481 of file z3py.py.

5481  def __init__(self, v=None, ctx=None):
5482  self.vector = None
5483  if v is None:
5484  self.ctx = _get_ctx(ctx)
5485  self.vector = Z3_mk_ast_vector(self.ctx.ref())
5486  else:
5487  self.vector = v
5488  assert ctx is not None
5489  self.ctx = ctx
5490  Z3_ast_vector_inc_ref(self.ctx.ref(), self.vector)
5491 

◆ __del__()

def __del__ (   self)

Definition at line 5495 of file z3py.py.

5495  def __del__(self):
5496  if self.vector is not None and self.ctx.ref() is not None:
5497  Z3_ast_vector_dec_ref(self.ctx.ref(), self.vector)
5498 

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

5577  def __contains__(self, item):
5578  """Return `True` if the vector contains `item`.
5579 
5580  >>> x = Int('x')
5581  >>> A = AstVector()
5582  >>> x in A
5583  False
5584  >>> A.push(x)
5585  >>> x in A
5586  True
5587  >>> (x+1) in A
5588  False
5589  >>> A.push(x+1)
5590  >>> (x+1) in A
5591  True
5592  >>> A
5593  [x, x + 1]
5594  """
5595  for elem in self:
5596  if elem.eq(item):
5597  return True
5598  return False
5599 

◆ __copy__()

def __copy__ (   self)

Definition at line 5613 of file z3py.py.

5613  def __copy__(self):
5614  return self.translate(self.ctx)
5615 

◆ __deepcopy__() [1/2]

def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 5492 of file z3py.py.

5492  def __deepcopy__(self, memo={}):
5493  return AstVector(self.vector, self.ctx)
5494 

Referenced by AstVector.__deepcopy__().

◆ __deepcopy__() [2/2]

def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 5616 of file z3py.py.

5616  def __deepcopy__(self, memo={}):
5617  return self.translate(self.ctx)
5618 

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

5512  def __getitem__(self, i):
5513  """Return the AST at position `i`.
5514 
5515  >>> A = AstVector()
5516  >>> A.push(Int('x') + 1)
5517  >>> A.push(Int('y'))
5518  >>> A[0]
5519  x + 1
5520  >>> A[1]
5521  y
5522  """
5523 
5524  if isinstance(i, int):
5525  if i < 0:
5526  i += self.__len__()
5527 
5528  if i >= self.__len__():
5529  raise IndexError
5530  return _to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, i), self.ctx)
5531 
5532  elif isinstance(i, slice):
5533  return [_to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, ii), self.ctx) for ii in range(*i.indices(self.__len__()))]
5534 
5535 

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

5499  def __len__(self):
5500  """Return the size of the vector `self`.
5501 
5502  >>> A = AstVector()
5503  >>> len(A)
5504  0
5505  >>> A.push(Int('x'))
5506  >>> A.push(Int('x'))
5507  >>> len(A)
5508  2
5509  """
5510  return int(Z3_ast_vector_size(self.ctx.ref(), self.vector))
5511 

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

◆ __repr__()

def __repr__ (   self)

Definition at line 5619 of file z3py.py.

5619  def __repr__(self):
5620  return obj_to_string(self)
5621 

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

5536  def __setitem__(self, i, v):
5537  """Update AST at position `i`.
5538 
5539  >>> A = AstVector()
5540  >>> A.push(Int('x') + 1)
5541  >>> A.push(Int('y'))
5542  >>> A[0]
5543  x + 1
5544  >>> A[0] = Int('x')
5545  >>> A[0]
5546  x
5547  """
5548  if i >= self.__len__():
5549  raise IndexError
5550  Z3_ast_vector_set(self.ctx.ref(), self.vector, i, v.as_ast())
5551 

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

5552  def push(self, v):
5553  """Add `v` in the end of the vector.
5554 
5555  >>> A = AstVector()
5556  >>> len(A)
5557  0
5558  >>> A.push(Int('x'))
5559  >>> len(A)
5560  1
5561  """
5562  Z3_ast_vector_push(self.ctx.ref(), self.vector, v.as_ast())
5563 

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

5564  def resize(self, sz):
5565  """Resize the vector to `sz` elements.
5566 
5567  >>> A = AstVector()
5568  >>> A.resize(10)
5569  >>> len(A)
5570  10
5571  >>> for i in range(10): A[i] = Int('x')
5572  >>> A[5]
5573  x
5574  """
5575  Z3_ast_vector_resize(self.ctx.ref(), self.vector, sz)
5576 

◆ sexpr()

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

Definition at line 5622 of file z3py.py.

5622  def sexpr(self):
5623  """Return a textual representation of the s-expression representing the vector."""
5624  return Z3_ast_vector_to_string(self.ctx.ref(), self.vector)
5625 

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

5600  def translate(self, other_ctx):
5601  """Copy vector `self` to context `other_ctx`.
5602 
5603  >>> x = Int('x')
5604  >>> A = AstVector()
5605  >>> A.push(x)
5606  >>> c2 = Context()
5607  >>> B = A.translate(c2)
5608  >>> B
5609  [x]
5610  """
5611  return AstVector(Z3_ast_vector_translate(self.ctx.ref(), self.vector, other_ctx.ref()), other_ctx)
5612 

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 5484 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__(), ModelRef.__getitem__(), Statistics.__getitem__(), ApplyResult.__getitem__(), AstMap.__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(), Optimize.assert_and_track(), Solver.assert_exprs(), Fixedpoint.assert_exprs(), Optimize.assert_exprs(), Solver.assertions(), Optimize.assertions(), Solver.check(), Optimize.check(), Solver.consequences(), ModelRef.decls(), Solver.dimacs(), 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(), Solver.import_model_converter(), 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(), Optimize.pop(), Solver.pop(), Solver.proof(), Solver.push(), Optimize.push(), AstVector.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(), Solver.trail(), Solver.trail_levels(), AstVector.translate(), FuncInterp.translate(), ModelRef.translate(), Solver.translate(), Solver.units(), Solver.unsat_core(), Optimize.unsat_core(), Fixedpoint.update_rule(), and FuncEntry.value().

◆ vector

vector
Z3_ast_vector_translate
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.
z3::range
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3488
Z3_ast_vector_push
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.
Z3_ast_vector_size
unsigned Z3_API Z3_ast_vector_size(Z3_context c, Z3_ast_vector v)
Return the size of the given AST vector.
Z3_ast_vector_to_string
Z3_string Z3_API Z3_ast_vector_to_string(Z3_context c, Z3_ast_vector v)
Convert AST vector into a string.
Z3_ast_vector_dec_ref
void Z3_API Z3_ast_vector_dec_ref(Z3_context c, Z3_ast_vector v)
Decrement the reference counter of the given AST vector.
Z3_ast_vector_inc_ref
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_set
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.
Z3_ast_vector_get
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.
Z3_mk_ast_vector
Z3_ast_vector Z3_API Z3_mk_ast_vector(Z3_context c)
Return an empty AST vector.
Z3_ast_vector_resize
void Z3_API Z3_ast_vector_resize(Z3_context c, Z3_ast_vector v, unsigned n)
Resize the AST vector v.