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

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 5121 of file z3py.py.

5121  def __init__(self, v=None, ctx=None):
5122  self.vector = None
5123  if v is None:
5124  self.ctx = _get_ctx(ctx)
5125  self.vector = Z3_mk_ast_vector(self.ctx.ref())
5126  else:
5127  self.vector = v
5128  assert ctx is not None
5129  self.ctx = ctx
5130  Z3_ast_vector_inc_ref(self.ctx.ref(), self.vector)
5131 
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 5135 of file z3py.py.

5135  def __del__(self):
5136  if self.vector is not None and self.ctx.ref() is not None:
5137  Z3_ast_vector_dec_ref(self.ctx.ref(), self.vector)
5138 
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 5217 of file z3py.py.

5217  def __contains__(self, item):
5218  """Return `True` if the vector contains `item`.
5219 
5220  >>> x = Int('x')
5221  >>> A = AstVector()
5222  >>> x in A
5223  False
5224  >>> A.push(x)
5225  >>> x in A
5226  True
5227  >>> (x+1) in A
5228  False
5229  >>> A.push(x+1)
5230  >>> (x+1) in A
5231  True
5232  >>> A
5233  [x, x + 1]
5234  """
5235  for elem in self:
5236  if elem.eq(item):
5237  return True
5238  return False
5239 

◆ __copy__()

def __copy__ (   self)

Definition at line 5253 of file z3py.py.

5253  def __copy__(self):
5254  return self.translate(self.ctx)
5255 

◆ __deepcopy__() [1/2]

def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 5132 of file z3py.py.

5132  def __deepcopy__(self, memo={}):
5133  return AstVector(self.vector, self.ctx)
5134 

◆ __deepcopy__() [2/2]

def __deepcopy__ (   self)

Definition at line 5256 of file z3py.py.

5256  def __deepcopy__(self):
5257  return self.translate(self.ctx)
5258 

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

5152  def __getitem__(self, i):
5153  """Return the AST at position `i`.
5154 
5155  >>> A = AstVector()
5156  >>> A.push(Int('x') + 1)
5157  >>> A.push(Int('y'))
5158  >>> A[0]
5159  x + 1
5160  >>> A[1]
5161  y
5162  """
5163 
5164  if isinstance(i, int):
5165  if i < 0:
5166  i += self.__len__()
5167 
5168  if i >= self.__len__():
5169  raise IndexError
5170  return _to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, i), self.ctx)
5171 
5172  elif isinstance(i, slice):
5173  return [_to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, ii), self.ctx) for ii in range(*i.indices(self.__len__()))]
5174 
5175 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:2868
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 5139 of file z3py.py.

5139  def __len__(self):
5140  """Return the size of the vector `self`.
5141 
5142  >>> A = AstVector()
5143  >>> len(A)
5144  0
5145  >>> A.push(Int('x'))
5146  >>> A.push(Int('x'))
5147  >>> len(A)
5148  2
5149  """
5150  return int(Z3_ast_vector_size(self.ctx.ref(), self.vector))
5151 
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 5259 of file z3py.py.

5259  def __repr__(self):
5260  return obj_to_string(self)
5261 

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

5176  def __setitem__(self, i, v):
5177  """Update AST at position `i`.
5178 
5179  >>> A = AstVector()
5180  >>> A.push(Int('x') + 1)
5181  >>> A.push(Int('y'))
5182  >>> A[0]
5183  x + 1
5184  >>> A[0] = Int('x')
5185  >>> A[0]
5186  x
5187  """
5188  if i >= self.__len__():
5189  raise IndexError
5190  Z3_ast_vector_set(self.ctx.ref(), self.vector, i, v.as_ast())
5191 
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 5192 of file z3py.py.

5192  def push(self, v):
5193  """Add `v` in the end of the vector.
5194 
5195  >>> A = AstVector()
5196  >>> len(A)
5197  0
5198  >>> A.push(Int('x'))
5199  >>> len(A)
5200  1
5201  """
5202  Z3_ast_vector_push(self.ctx.ref(), self.vector, v.as_ast())
5203 
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 5204 of file z3py.py.

5204  def resize(self, sz):
5205  """Resize the vector to `sz` elements.
5206 
5207  >>> A = AstVector()
5208  >>> A.resize(10)
5209  >>> len(A)
5210  10
5211  >>> for i in range(10): A[i] = Int('x')
5212  >>> A[5]
5213  x
5214  """
5215  Z3_ast_vector_resize(self.ctx.ref(), self.vector, sz)
5216 
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 5262 of file z3py.py.

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

5262  def sexpr(self):
5263  """Return a textual representation of the s-expression representing the vector."""
5264  return Z3_ast_vector_to_string(self.ctx.ref(), self.vector)
5265 
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 5240 of file z3py.py.

5240  def translate(self, other_ctx):
5241  """Copy vector `self` to context `other_ctx`.
5242 
5243  >>> x = Int('x')
5244  >>> A = AstVector()
5245  >>> A.push(x)
5246  >>> c2 = Context()
5247  >>> B = A.translate(c2)
5248  >>> B
5249  [x]
5250  """
5251  return AstVector(Z3_ast_vector_translate(self.ctx.ref(), self.vector, other_ctx.ref()), other_ctx)
5252 
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 5124 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(), Fixedpoint.assert_exprs(), Optimize.assert_exprs(), Optimize.assertions(), Optimize.check(), ApplyResult.convert_model(), 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(), Fixedpoint.pop(), Optimize.pop(), Fixedpoint.push(), 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(), and Fixedpoint.update_rule().

◆ vector

vector

Definition at line 5122 of file z3py.py.