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

Constructor & Destructor Documentation

§ __init__()

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

Definition at line 5093 of file z3py.py.

5093  def __init__(self, v=None, ctx=None):
5094  self.vector = None
5095  if v is None:
5096  self.ctx = _get_ctx(ctx)
5097  self.vector = Z3_mk_ast_vector(self.ctx.ref())
5098  else:
5099  self.vector = v
5100  assert ctx is not None
5101  self.ctx = ctx
5102  Z3_ast_vector_inc_ref(self.ctx.ref(), self.vector)
5103 
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 5107 of file z3py.py.

5107  def __del__(self):
5108  if self.vector is not None and self.ctx.ref() is not None:
5109  Z3_ast_vector_dec_ref(self.ctx.ref(), self.vector)
5110 
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 5180 of file z3py.py.

5180  def __contains__(self, item):
5181  """Return `True` if the vector contains `item`.
5182 
5183  >>> x = Int('x')
5184  >>> A = AstVector()
5185  >>> x in A
5186  False
5187  >>> A.push(x)
5188  >>> x in A
5189  True
5190  >>> (x+1) in A
5191  False
5192  >>> A.push(x+1)
5193  >>> (x+1) in A
5194  True
5195  >>> A
5196  [x, x + 1]
5197  """
5198  for elem in self:
5199  if elem.eq(item):
5200  return True
5201  return False
5202 

§ __deepcopy__()

def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 5104 of file z3py.py.

5104  def __deepcopy__(self, memo={}):
5105  return AstVector(self.vector, self.ctx)
5106 

§ __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 5124 of file z3py.py.

5124  def __getitem__(self, i):
5125  """Return the AST at position `i`.
5126 
5127  >>> A = AstVector()
5128  >>> A.push(Int('x') + 1)
5129  >>> A.push(Int('y'))
5130  >>> A[0]
5131  x + 1
5132  >>> A[1]
5133  y
5134  """
5135  if i >= self.__len__():
5136  raise IndexError
5137  return _to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, i), self.ctx)
5138 
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 5111 of file z3py.py.

5111  def __len__(self):
5112  """Return the size of the vector `self`.
5113 
5114  >>> A = AstVector()
5115  >>> len(A)
5116  0
5117  >>> A.push(Int('x'))
5118  >>> A.push(Int('x'))
5119  >>> len(A)
5120  2
5121  """
5122  return int(Z3_ast_vector_size(self.ctx.ref(), self.vector))
5123 
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 5216 of file z3py.py.

5216  def __repr__(self):
5217  return obj_to_string(self)
5218 

§ __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 5139 of file z3py.py.

5139  def __setitem__(self, i, v):
5140  """Update AST at position `i`.
5141 
5142  >>> A = AstVector()
5143  >>> A.push(Int('x') + 1)
5144  >>> A.push(Int('y'))
5145  >>> A[0]
5146  x + 1
5147  >>> A[0] = Int('x')
5148  >>> A[0]
5149  x
5150  """
5151  if i >= self.__len__():
5152  raise IndexError
5153  Z3_ast_vector_set(self.ctx.ref(), self.vector, i, v.as_ast())
5154 
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 5155 of file z3py.py.

5155  def push(self, v):
5156  """Add `v` in the end of the vector.
5157 
5158  >>> A = AstVector()
5159  >>> len(A)
5160  0
5161  >>> A.push(Int('x'))
5162  >>> len(A)
5163  1
5164  """
5165  Z3_ast_vector_push(self.ctx.ref(), self.vector, v.as_ast())
5166 
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 5167 of file z3py.py.

5167  def resize(self, sz):
5168  """Resize the vector to `sz` elements.
5169 
5170  >>> A = AstVector()
5171  >>> A.resize(10)
5172  >>> len(A)
5173  10
5174  >>> for i in range(10): A[i] = Int('x')
5175  >>> A[5]
5176  x
5177  """
5178  Z3_ast_vector_resize(self.ctx.ref(), self.vector, sz)
5179 
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 5219 of file z3py.py.

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

5219  def sexpr(self):
5220  """Return a textual representation of the s-expression representing the vector."""
5221  return Z3_ast_vector_to_string(self.ctx.ref(), self.vector)
5222 
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 5203 of file z3py.py.

5203  def translate(self, other_ctx):
5204  """Copy vector `self` to context `other_ctx`.
5205 
5206  >>> x = Int('x')
5207  >>> A = AstVector()
5208  >>> A.push(x)
5209  >>> c2 = Context()
5210  >>> B = A.translate(c2)
5211  >>> B
5212  [x]
5213  """
5214  return AstVector(Z3_ast_vector_translate(self.ctx.ref(), self.vector, other_ctx.ref()), other_ctx)
5215 
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 5096 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 5094 of file z3py.py.