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

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 5499 of file z3py.py.

5499  def __init__(self, v=None, ctx=None):
5500  self.vector = None
5501  if v is None:
5502  self.ctx = _get_ctx(ctx)
5503  self.vector = Z3_mk_ast_vector(self.ctx.ref())
5504  else:
5505  self.vector = v
5506  assert ctx is not None
5507  self.ctx = ctx
5508  Z3_ast_vector_inc_ref(self.ctx.ref(), self.vector)
5509 

◆ __del__()

def __del__ (   self)

Definition at line 5513 of file z3py.py.

5513  def __del__(self):
5514  if self.vector is not None and self.ctx.ref() is not None:
5515  Z3_ast_vector_dec_ref(self.ctx.ref(), self.vector)
5516 

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

5595  def __contains__(self, item):
5596  """Return `True` if the vector contains `item`.
5597 
5598  >>> x = Int('x')
5599  >>> A = AstVector()
5600  >>> x in A
5601  False
5602  >>> A.push(x)
5603  >>> x in A
5604  True
5605  >>> (x+1) in A
5606  False
5607  >>> A.push(x+1)
5608  >>> (x+1) in A
5609  True
5610  >>> A
5611  [x, x + 1]
5612  """
5613  for elem in self:
5614  if elem.eq(item):
5615  return True
5616  return False
5617 

◆ __copy__()

def __copy__ (   self)

Definition at line 5631 of file z3py.py.

5631  def __copy__(self):
5632  return self.translate(self.ctx)
5633 

◆ __deepcopy__() [1/2]

def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 5510 of file z3py.py.

5510  def __deepcopy__(self, memo={}):
5511  return AstVector(self.vector, self.ctx)
5512 

Referenced by AstVector.__deepcopy__().

◆ __deepcopy__() [2/2]

def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 5634 of file z3py.py.

5634  def __deepcopy__(self, memo={}):
5635  return self.translate(self.ctx)
5636 

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

5530  def __getitem__(self, i):
5531  """Return the AST at position `i`.
5532 
5533  >>> A = AstVector()
5534  >>> A.push(Int('x') + 1)
5535  >>> A.push(Int('y'))
5536  >>> A[0]
5537  x + 1
5538  >>> A[1]
5539  y
5540  """
5541 
5542  if isinstance(i, int):
5543  if i < 0:
5544  i += self.__len__()
5545 
5546  if i >= self.__len__():
5547  raise IndexError
5548  return _to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, i), self.ctx)
5549 
5550  elif isinstance(i, slice):
5551  return [_to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, ii), self.ctx) for ii in range(*i.indices(self.__len__()))]
5552 
5553 

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

5517  def __len__(self):
5518  """Return the size of the vector `self`.
5519 
5520  >>> A = AstVector()
5521  >>> len(A)
5522  0
5523  >>> A.push(Int('x'))
5524  >>> A.push(Int('x'))
5525  >>> len(A)
5526  2
5527  """
5528  return int(Z3_ast_vector_size(self.ctx.ref(), self.vector))
5529 

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

◆ __repr__()

def __repr__ (   self)

Definition at line 5637 of file z3py.py.

5637  def __repr__(self):
5638  return obj_to_string(self)
5639 

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

5554  def __setitem__(self, i, v):
5555  """Update AST at position `i`.
5556 
5557  >>> A = AstVector()
5558  >>> A.push(Int('x') + 1)
5559  >>> A.push(Int('y'))
5560  >>> A[0]
5561  x + 1
5562  >>> A[0] = Int('x')
5563  >>> A[0]
5564  x
5565  """
5566  if i >= self.__len__():
5567  raise IndexError
5568  Z3_ast_vector_set(self.ctx.ref(), self.vector, i, v.as_ast())
5569 

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

5570  def push(self, v):
5571  """Add `v` in the end of the vector.
5572 
5573  >>> A = AstVector()
5574  >>> len(A)
5575  0
5576  >>> A.push(Int('x'))
5577  >>> len(A)
5578  1
5579  """
5580  Z3_ast_vector_push(self.ctx.ref(), self.vector, v.as_ast())
5581 

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

5582  def resize(self, sz):
5583  """Resize the vector to `sz` elements.
5584 
5585  >>> A = AstVector()
5586  >>> A.resize(10)
5587  >>> len(A)
5588  10
5589  >>> for i in range(10): A[i] = Int('x')
5590  >>> A[5]
5591  x
5592  """
5593  Z3_ast_vector_resize(self.ctx.ref(), self.vector, sz)
5594 

◆ sexpr()

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

Definition at line 5640 of file z3py.py.

5640  def sexpr(self):
5641  """Return a textual representation of the s-expression representing the vector."""
5642  return Z3_ast_vector_to_string(self.ctx.ref(), self.vector)
5643 

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

5618  def translate(self, other_ctx):
5619  """Copy vector `self` to context `other_ctx`.
5620 
5621  >>> x = Int('x')
5622  >>> A = AstVector()
5623  >>> A.push(x)
5624  >>> c2 = Context()
5625  >>> B = A.translate(c2)
5626  >>> B
5627  [x]
5628  """
5629  return AstVector(Z3_ast_vector_translate(self.ctx.ref(), self.vector, other_ctx.ref()), other_ctx)
5630 

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 5502 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(), Optimize.assert_and_track(), Solver.assert_exprs(), Fixedpoint.assert_exprs(), Optimize.assert_exprs(), Solver.assertions(), Optimize.assertions(), Solver.check(), Optimize.check(), UserPropagateBase.conflict(), Solver.consequences(), UserPropagateBase.ctx_ref(), 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(), Solver.pop(), Optimize.pop(), Solver.proof(), AstVector.push(), Solver.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(), 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
z3py.UserPropagateBase.__init__
def __init__(self, s, ctx=None)
Definition: z3py.py:10582
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:3515
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.
z3py.UserPropagateBase.push
def push(self)
Definition: z3py.py:10644
z3py.UserPropagateBase.__del__
def __del__(self)
Definition: z3py.py:10607
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.