Z3
Public Member Functions | Data Fields
AstMap Class Reference

Public Member Functions

def __init__ (self, m=None, ctx=None)
 
def __deepcopy__ (self, memo={})
 
def __del__ (self)
 
def __len__ (self)
 
def __contains__ (self, key)
 
def __getitem__ (self, key)
 
def __setitem__ (self, k, v)
 
def __repr__ (self)
 
def erase (self, k)
 
def reset (self)
 
def keys (self)
 

Data Fields

 map
 
 ctx
 

Detailed Description

A mapping from ASTs to ASTs.

Definition at line 5545 of file z3py.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 5548 of file z3py.py.

5548  def __init__(self, m=None, ctx=None):
5549  self.map = None
5550  if m is None:
5551  self.ctx = _get_ctx(ctx)
5552  self.map = Z3_mk_ast_map(self.ctx.ref())
5553  else:
5554  self.map = m
5555  assert ctx is not None
5556  self.ctx = ctx
5557  Z3_ast_map_inc_ref(self.ctx.ref(), self.map)
5558 
void Z3_API Z3_ast_map_inc_ref(Z3_context c, Z3_ast_map m)
Increment the reference counter of the given AST map.
Z3_ast_map Z3_API Z3_mk_ast_map(Z3_context c)
Return an empty mapping from AST to AST.

◆ __del__()

def __del__ (   self)

Definition at line 5562 of file z3py.py.

5562  def __del__(self):
5563  if self.map is not None and self.ctx.ref() is not None:
5564  Z3_ast_map_dec_ref(self.ctx.ref(), self.map)
5565 
void Z3_API Z3_ast_map_dec_ref(Z3_context c, Z3_ast_map m)
Decrement the reference counter of the given AST map.

Member Function Documentation

◆ __contains__()

def __contains__ (   self,
  key 
)
Return `True` if the map contains key `key`.

>>> M = AstMap()
>>> x = Int('x')
>>> M[x] = x + 1
>>> x in M
True
>>> x+1 in M
False

Definition at line 5579 of file z3py.py.

5579  def __contains__(self, key):
5580  """Return `True` if the map contains key `key`.
5581 
5582  >>> M = AstMap()
5583  >>> x = Int('x')
5584  >>> M[x] = x + 1
5585  >>> x in M
5586  True
5587  >>> x+1 in M
5588  False
5589  """
5590  return Z3_ast_map_contains(self.ctx.ref(), self.map, key.as_ast())
5591 
bool Z3_API Z3_ast_map_contains(Z3_context c, Z3_ast_map m, Z3_ast k)
Return true if the map m contains the AST key k.

◆ __deepcopy__()

def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 5559 of file z3py.py.

5559  def __deepcopy__(self, memo={}):
5560  return AstMap(self.map, self.ctx)
5561 

◆ __getitem__()

def __getitem__ (   self,
  key 
)
Retrieve the value associated with key `key`.

>>> M = AstMap()
>>> x = Int('x')
>>> M[x] = x + 1
>>> M[x]
x + 1

Definition at line 5592 of file z3py.py.

5592  def __getitem__(self, key):
5593  """Retrieve the value associated with key `key`.
5594 
5595  >>> M = AstMap()
5596  >>> x = Int('x')
5597  >>> M[x] = x + 1
5598  >>> M[x]
5599  x + 1
5600  """
5601  return _to_ast_ref(Z3_ast_map_find(self.ctx.ref(), self.map, key.as_ast()), self.ctx)
5602 
Z3_ast Z3_API Z3_ast_map_find(Z3_context c, Z3_ast_map m, Z3_ast k)
Return the value associated with the key k.

◆ __len__()

def __len__ (   self)
Return the size of the map.

>>> M = AstMap()
>>> len(M)
0
>>> x = Int('x')
>>> M[x] = IntVal(1)
>>> len(M)
1

Definition at line 5566 of file z3py.py.

5566  def __len__(self):
5567  """Return the size of the map.
5568 
5569  >>> M = AstMap()
5570  >>> len(M)
5571  0
5572  >>> x = Int('x')
5573  >>> M[x] = IntVal(1)
5574  >>> len(M)
5575  1
5576  """
5577  return int(Z3_ast_map_size(self.ctx.ref(), self.map))
5578 
unsigned Z3_API Z3_ast_map_size(Z3_context c, Z3_ast_map m)
Return the size of the given map.

◆ __repr__()

def __repr__ (   self)

Definition at line 5619 of file z3py.py.

5619  def __repr__(self):
5620  return Z3_ast_map_to_string(self.ctx.ref(), self.map)
5621 
Z3_string Z3_API Z3_ast_map_to_string(Z3_context c, Z3_ast_map m)
Convert the given map into a string.

◆ __setitem__()

def __setitem__ (   self,
  k,
  v 
)
Add/Update key `k` with value `v`.

>>> M = AstMap()
>>> x = Int('x')
>>> M[x] = x + 1
>>> len(M)
1
>>> M[x]
x + 1
>>> M[x] = IntVal(1)
>>> M[x]
1

Definition at line 5603 of file z3py.py.

5603  def __setitem__(self, k, v):
5604  """Add/Update key `k` with value `v`.
5605 
5606  >>> M = AstMap()
5607  >>> x = Int('x')
5608  >>> M[x] = x + 1
5609  >>> len(M)
5610  1
5611  >>> M[x]
5612  x + 1
5613  >>> M[x] = IntVal(1)
5614  >>> M[x]
5615  1
5616  """
5617  Z3_ast_map_insert(self.ctx.ref(), self.map, k.as_ast(), v.as_ast())
5618 
void Z3_API Z3_ast_map_insert(Z3_context c, Z3_ast_map m, Z3_ast k, Z3_ast v)
Store/Replace a new key, value pair in the given map.

◆ erase()

def erase (   self,
  k 
)
Remove the entry associated with key `k`.

>>> M = AstMap()
>>> x = Int('x')
>>> M[x] = x + 1
>>> len(M)
1
>>> M.erase(x)
>>> len(M)
0

Definition at line 5622 of file z3py.py.

5622  def erase(self, k):
5623  """Remove the entry associated with key `k`.
5624 
5625  >>> M = AstMap()
5626  >>> x = Int('x')
5627  >>> M[x] = x + 1
5628  >>> len(M)
5629  1
5630  >>> M.erase(x)
5631  >>> len(M)
5632  0
5633  """
5634  Z3_ast_map_erase(self.ctx.ref(), self.map, k.as_ast())
5635 
void Z3_API Z3_ast_map_erase(Z3_context c, Z3_ast_map m, Z3_ast k)
Erase a key from the map.

◆ keys()

def keys (   self)
Return an AstVector containing all keys in the map.

>>> M = AstMap()
>>> x = Int('x')
>>> M[x]   = x + 1
>>> M[x+x] = IntVal(1)
>>> M.keys()
[x, x + x]

Definition at line 5651 of file z3py.py.

5651  def keys(self):
5652  """Return an AstVector containing all keys in the map.
5653 
5654  >>> M = AstMap()
5655  >>> x = Int('x')
5656  >>> M[x] = x + 1
5657  >>> M[x+x] = IntVal(1)
5658  >>> M.keys()
5659  [x, x + x]
5660  """
5661  return AstVector(Z3_ast_map_keys(self.ctx.ref(), self.map), self.ctx)
5662 
Z3_ast_vector Z3_API Z3_ast_map_keys(Z3_context c, Z3_ast_map m)
Return the keys stored in the given map.

◆ reset()

def reset (   self)
Remove all entries from the map.

>>> M = AstMap()
>>> x = Int('x')
>>> M[x]   = x + 1
>>> M[x+x] = IntVal(1)
>>> len(M)
2
>>> M.reset()
>>> len(M)
0

Definition at line 5636 of file z3py.py.

5636  def reset(self):
5637  """Remove all entries from the map.
5638 
5639  >>> M = AstMap()
5640  >>> x = Int('x')
5641  >>> M[x] = x + 1
5642  >>> M[x+x] = IntVal(1)
5643  >>> len(M)
5644  2
5645  >>> M.reset()
5646  >>> len(M)
5647  0
5648  """
5649  Z3_ast_map_reset(self.ctx.ref(), self.map)
5650 
void Z3_API Z3_ast_map_reset(Z3_context c, Z3_ast_map m)
Remove all keys from the given map.

Field Documentation

◆ ctx

ctx

Definition at line 5551 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(), 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(), Optimize.unsat_core(), and Fixedpoint.update_rule().

◆ map

map

Definition at line 5549 of file z3py.py.