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

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 5458 of file z3py.py.

5458  def __init__(self, v=None, ctx=None):
5459  self.vector = None
5460  if v is None:
5461  self.ctx = _get_ctx(ctx)
5462  self.vector = Z3_mk_ast_vector(self.ctx.ref())
5463  else:
5464  self.vector = v
5465  assert ctx is not None
5466  self.ctx = ctx
5467  Z3_ast_vector_inc_ref(self.ctx.ref(), self.vector)
5468 
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 5472 of file z3py.py.

5472  def __del__(self):
5473  if self.vector is not None and self.ctx.ref() is not None:
5474  Z3_ast_vector_dec_ref(self.ctx.ref(), self.vector)
5475 
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 5554 of file z3py.py.

5554  def __contains__(self, item):
5555  """Return `True` if the vector contains `item`.
5556 
5557  >>> x = Int('x')
5558  >>> A = AstVector()
5559  >>> x in A
5560  False
5561  >>> A.push(x)
5562  >>> x in A
5563  True
5564  >>> (x+1) in A
5565  False
5566  >>> A.push(x+1)
5567  >>> (x+1) in A
5568  True
5569  >>> A
5570  [x, x + 1]
5571  """
5572  for elem in self:
5573  if elem.eq(item):
5574  return True
5575  return False
5576 

◆ __copy__()

def __copy__ (   self)

Definition at line 5590 of file z3py.py.

5590  def __copy__(self):
5591  return self.translate(self.ctx)
5592 

◆ __deepcopy__() [1/2]

def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 5469 of file z3py.py.

5469  def __deepcopy__(self, memo={}):
5470  return AstVector(self.vector, self.ctx)
5471 

Referenced by AstVector.__deepcopy__().

◆ __deepcopy__() [2/2]

def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 5593 of file z3py.py.

5593  def __deepcopy__(self, memo={}):
5594  return self.translate(self.ctx)
5595 

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

5489  def __getitem__(self, i):
5490  """Return the AST at position `i`.
5491 
5492  >>> A = AstVector()
5493  >>> A.push(Int('x') + 1)
5494  >>> A.push(Int('y'))
5495  >>> A[0]
5496  x + 1
5497  >>> A[1]
5498  y
5499  """
5500 
5501  if isinstance(i, int):
5502  if i < 0:
5503  i += self.__len__()
5504 
5505  if i >= self.__len__():
5506  raise IndexError
5507  return _to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, i), self.ctx)
5508 
5509  elif isinstance(i, slice):
5510  return [_to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, ii), self.ctx) for ii in range(*i.indices(self.__len__()))]
5511 
5512 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3431
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 5476 of file z3py.py.

5476  def __len__(self):
5477  """Return the size of the vector `self`.
5478 
5479  >>> A = AstVector()
5480  >>> len(A)
5481  0
5482  >>> A.push(Int('x'))
5483  >>> A.push(Int('x'))
5484  >>> len(A)
5485  2
5486  """
5487  return int(Z3_ast_vector_size(self.ctx.ref(), self.vector))
5488 
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 5596 of file z3py.py.

5596  def __repr__(self):
5597  return obj_to_string(self)
5598 

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

5513  def __setitem__(self, i, v):
5514  """Update AST at position `i`.
5515 
5516  >>> A = AstVector()
5517  >>> A.push(Int('x') + 1)
5518  >>> A.push(Int('y'))
5519  >>> A[0]
5520  x + 1
5521  >>> A[0] = Int('x')
5522  >>> A[0]
5523  x
5524  """
5525  if i >= self.__len__():
5526  raise IndexError
5527  Z3_ast_vector_set(self.ctx.ref(), self.vector, i, v.as_ast())
5528 
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 5529 of file z3py.py.

5529  def push(self, v):
5530  """Add `v` in the end of the vector.
5531 
5532  >>> A = AstVector()
5533  >>> len(A)
5534  0
5535  >>> A.push(Int('x'))
5536  >>> len(A)
5537  1
5538  """
5539  Z3_ast_vector_push(self.ctx.ref(), self.vector, v.as_ast())
5540 
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 5541 of file z3py.py.

5541  def resize(self, sz):
5542  """Resize the vector to `sz` elements.
5543 
5544  >>> A = AstVector()
5545  >>> A.resize(10)
5546  >>> len(A)
5547  10
5548  >>> for i in range(10): A[i] = Int('x')
5549  >>> A[5]
5550  x
5551  """
5552  Z3_ast_vector_resize(self.ctx.ref(), self.vector, sz)
5553 
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 5599 of file z3py.py.

5599  def sexpr(self):
5600  """Return a textual representation of the s-expression representing the vector."""
5601  return Z3_ast_vector_to_string(self.ctx.ref(), self.vector)
5602 
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 5577 of file z3py.py.

5577  def translate(self, other_ctx):
5578  """Copy vector `self` to context `other_ctx`.
5579 
5580  >>> x = Int('x')
5581  >>> A = AstVector()
5582  >>> A.push(x)
5583  >>> c2 = Context()
5584  >>> B = A.translate(c2)
5585  >>> B
5586  [x]
5587  """
5588  return AstVector(Z3_ast_vector_translate(self.ctx.ref(), self.vector, other_ctx.ref()), other_ctx)
5589 
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 5461 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(), 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(), 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