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

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 5462 of file z3py.py.

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

5476  def __del__(self):
5477  if self.vector is not None and self.ctx.ref() is not None:
5478  Z3_ast_vector_dec_ref(self.ctx.ref(), self.vector)
5479 
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 5558 of file z3py.py.

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

◆ __copy__()

def __copy__ (   self)

Definition at line 5594 of file z3py.py.

5594  def __copy__(self):
5595  return self.translate(self.ctx)
5596 

◆ __deepcopy__() [1/2]

def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 5473 of file z3py.py.

5473  def __deepcopy__(self, memo={}):
5474  return AstVector(self.vector, self.ctx)
5475 

Referenced by AstVector.__deepcopy__().

◆ __deepcopy__() [2/2]

def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 5597 of file z3py.py.

5597  def __deepcopy__(self, memo={}):
5598  return self.translate(self.ctx)
5599 

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

5493  def __getitem__(self, i):
5494  """Return the 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[1]
5502  y
5503  """
5504 
5505  if isinstance(i, int):
5506  if i < 0:
5507  i += self.__len__()
5508 
5509  if i >= self.__len__():
5510  raise IndexError
5511  return _to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, i), self.ctx)
5512 
5513  elif isinstance(i, slice):
5514  return [_to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, ii), self.ctx) for ii in range(*i.indices(self.__len__()))]
5515 
5516 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3370
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 5480 of file z3py.py.

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

5600  def __repr__(self):
5601  return obj_to_string(self)
5602 

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

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

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

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

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

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