Z3
Public Member Functions | Data Fields
AstRef Class Reference
+ Inheritance diagram for AstRef:

Public Member Functions

def __init__
 
def __del__ (self)
 
def __deepcopy__
 
def __str__ (self)
 
def __repr__ (self)
 
def __eq__ (self, other)
 
def __hash__ (self)
 
def __nonzero__ (self)
 
def __bool__ (self)
 
def sexpr (self)
 
def as_ast (self)
 
def get_id (self)
 
def ctx_ref (self)
 
def eq (self, other)
 
def translate (self, target)
 
def __copy__ (self)
 
def hash (self)
 
def py_value (self)
 
- Public Member Functions inherited from Z3PPObject
def use_pp (self)
 

Data Fields

 ast
 
 ctx
 

Detailed Description

AST are Direct Acyclic Graphs (DAGs) used to represent sorts, declarations and expressions.

Definition at line 352 of file z3py.py.

Constructor & Destructor Documentation

def __init__ (   self,
  ast,
  ctx = None 
)

Definition at line 355 of file z3py.py.

355  def __init__(self, ast, ctx=None):
356  self.ast = ast
357  self.ctx = _get_ctx(ctx)
358  Z3_inc_ref(self.ctx.ref(), self.as_ast())
359 
def as_ast(self)
Definition: z3py.py:402
def __init__
Definition: z3py.py:355
void Z3_API Z3_inc_ref(Z3_context c, Z3_ast a)
Increment the reference counter of the given AST. The context c should have been created using Z3_mk_...
def __del__ (   self)

Definition at line 360 of file z3py.py.

360  def __del__(self):
361  if self.ctx.ref() is not None and self.ast is not None and Z3_dec_ref is not None:
362  Z3_dec_ref(self.ctx.ref(), self.as_ast())
363  self.ast = None
364 
def as_ast(self)
Definition: z3py.py:402
void Z3_API Z3_dec_ref(Z3_context c, Z3_ast a)
Decrement the reference counter of the given AST. The context c should have been created using Z3_mk_...
def __del__(self)
Definition: z3py.py:360

Member Function Documentation

def __bool__ (   self)

Definition at line 383 of file z3py.py.

Referenced by AstRef.__nonzero__().

383  def __bool__(self):
384  if is_true(self):
385  return True
386  elif is_false(self):
387  return False
388  elif is_eq(self) and self.num_args() == 2:
389  return self.arg(0).eq(self.arg(1))
390  else:
391  raise Z3Exception("Symbolic expressions cannot be cast to concrete Boolean values.")
392 
def is_eq
Definition: z3py.py:1740
def is_true
Definition: z3py.py:1660
def is_false
Definition: z3py.py:1678
def __bool__(self)
Definition: z3py.py:383
def eq(self, other)
Definition: z3py.py:414
def __copy__ (   self)

Definition at line 447 of file z3py.py.

447  def __copy__(self):
448  return self.translate(self.ctx)
449 
def translate(self, target)
Definition: z3py.py:431
def __copy__(self)
Definition: z3py.py:447
def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 365 of file z3py.py.

365  def __deepcopy__(self, memo={}):
366  return _to_ast_ref(self.ast, self.ctx)
367 
def __deepcopy__
Definition: z3py.py:365
def __eq__ (   self,
  other 
)

Definition at line 374 of file z3py.py.

Referenced by Probe.__ne__().

374  def __eq__(self, other):
375  return self.eq(other)
376 
def __eq__(self, other)
Definition: z3py.py:374
def eq(self, other)
Definition: z3py.py:414
def __hash__ (   self)

Definition at line 377 of file z3py.py.

377  def __hash__(self):
378  return self.hash()
379 
def hash(self)
Definition: z3py.py:450
def __hash__(self)
Definition: z3py.py:377
def __nonzero__ (   self)

Definition at line 380 of file z3py.py.

380  def __nonzero__(self):
381  return self.__bool__()
382 
def __nonzero__(self)
Definition: z3py.py:380
def __bool__(self)
Definition: z3py.py:383
def __repr__ (   self)

Definition at line 371 of file z3py.py.

371  def __repr__(self):
372  return obj_to_string(self)
373 
def __repr__(self)
Definition: z3py.py:371
def __str__ (   self)

Definition at line 368 of file z3py.py.

368  def __str__(self):
369  return obj_to_string(self)
370 
def __str__(self)
Definition: z3py.py:368
def as_ast (   self)
def ctx_ref (   self)
def eq (   self,
  other 
)
Return `True` if `self` and `other` are structurally identical.

>>> x = Int('x')
>>> n1 = x + 1
>>> n2 = 1 + x
>>> n1.eq(n2)
False
>>> n1 = simplify(n1)
>>> n2 = simplify(n2)
>>> n1.eq(n2)
True

Definition at line 414 of file z3py.py.

Referenced by AstRef.__bool__(), AstRef.__eq__(), SortRef.cast(), and BoolSortRef.cast().

414  def eq(self, other):
415  """Return `True` if `self` and `other` are structurally identical.
416 
417  >>> x = Int('x')
418  >>> n1 = x + 1
419  >>> n2 = 1 + x
420  >>> n1.eq(n2)
421  False
422  >>> n1 = simplify(n1)
423  >>> n2 = simplify(n2)
424  >>> n1.eq(n2)
425  True
426  """
427  if z3_debug():
428  _z3_assert(is_ast(other), "Z3 AST expected")
429  return Z3_is_eq_ast(self.ctx_ref(), self.as_ast(), other.as_ast())
430 
def is_ast
Definition: z3py.py:465
def as_ast(self)
Definition: z3py.py:402
bool Z3_API Z3_is_eq_ast(Z3_context c, Z3_ast t1, Z3_ast t2)
Compare terms.
def eq(self, other)
Definition: z3py.py:414
def z3_debug()
Definition: z3py.py:70
def ctx_ref(self)
Definition: z3py.py:410
def get_id (   self)
Return unique identifier for object. It can be used for hash-tables and maps.

Definition at line 406 of file z3py.py.

406  def get_id(self):
407  """Return unique identifier for object. It can be used for hash-tables and maps."""
408  return Z3_get_ast_id(self.ctx_ref(), self.as_ast())
409 
def as_ast(self)
Definition: z3py.py:402
unsigned Z3_API Z3_get_ast_id(Z3_context c, Z3_ast t)
Return a unique identifier for t. The identifier is unique up to structural equality. Thus, two ast nodes created by the same context and having the same children and same function symbols have the same identifiers. Ast nodes created in the same context, but having different children or different functions have different identifiers. Variables and quantifiers are also assigned different identifiers according to their structure.
def get_id(self)
Definition: z3py.py:406
def ctx_ref(self)
Definition: z3py.py:410
def hash (   self)
Return a hashcode for the `self`.

>>> n1 = simplify(Int('x') + 1)
>>> n2 = simplify(2 + Int('x') - 1)
>>> n1.hash() == n2.hash()
True

Definition at line 450 of file z3py.py.

Referenced by AstRef.__hash__().

450  def hash(self):
451  """Return a hashcode for the `self`.
452 
453  >>> n1 = simplify(Int('x') + 1)
454  >>> n2 = simplify(2 + Int('x') - 1)
455  >>> n1.hash() == n2.hash()
456  True
457  """
458  return Z3_get_ast_hash(self.ctx_ref(), self.as_ast())
459 
def as_ast(self)
Definition: z3py.py:402
unsigned Z3_API Z3_get_ast_hash(Z3_context c, Z3_ast a)
Return a hash code for the given AST. The hash code is structural but two different AST objects can m...
def hash(self)
Definition: z3py.py:450
def ctx_ref(self)
Definition: z3py.py:410
def py_value (   self)
Return a Python value that is equivalent to `self`.

Definition at line 460 of file z3py.py.

460  def py_value(self):
461  """Return a Python value that is equivalent to `self`."""
462  return None
463 
464 
def py_value(self)
Definition: z3py.py:460
def sexpr (   self)
Return a string representing the AST node in s-expression notation.

>>> x = Int('x')
>>> ((x + 1)*x).sexpr()
'(* (+ x 1) x)'

Definition at line 393 of file z3py.py.

Referenced by ArithRef.__div__(), BitVecRef.__div__(), BitVecRef.__ge__(), ArrayRef.__getitem__(), BitVecRef.__gt__(), BitVecRef.__le__(), BitVecRef.__lshift__(), BitVecRef.__lt__(), BitVecRef.__mod__(), ArithRef.__rdiv__(), BitVecRef.__rdiv__(), Fixedpoint.__repr__(), Optimize.__repr__(), BitVecRef.__rlshift__(), BitVecRef.__rmod__(), BitVecRef.__rrshift__(), BitVecRef.__rshift__(), BitVecSortRef.cast(), and FPSortRef.cast().

393  def sexpr(self):
394  """Return a string representing the AST node in s-expression notation.
395 
396  >>> x = Int('x')
397  >>> ((x + 1)*x).sexpr()
398  '(* (+ x 1) x)'
399  """
400  return Z3_ast_to_string(self.ctx_ref(), self.as_ast())
401 
Z3_string Z3_API Z3_ast_to_string(Z3_context c, Z3_ast a)
Convert the given AST node into a string.
def as_ast(self)
Definition: z3py.py:402
def sexpr(self)
Definition: z3py.py:393
def ctx_ref(self)
Definition: z3py.py:410
def translate (   self,
  target 
)
Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.

>>> c1 = Context()
>>> c2 = Context()
>>> x  = Int('x', c1)
>>> y  = Int('y', c2)
>>> # Nodes in different contexts can't be mixed.
>>> # However, we can translate nodes from one context to another.
>>> x.translate(c2) + y
x + y

Definition at line 431 of file z3py.py.

Referenced by AstRef.__copy__().

431  def translate(self, target):
432  """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
433 
434  >>> c1 = Context()
435  >>> c2 = Context()
436  >>> x = Int('x', c1)
437  >>> y = Int('y', c2)
438  >>> # Nodes in different contexts can't be mixed.
439  >>> # However, we can translate nodes from one context to another.
440  >>> x.translate(c2) + y
441  x + y
442  """
443  if z3_debug():
444  _z3_assert(isinstance(target, Context), "argument must be a Z3 context")
445  return _to_ast_ref(Z3_translate(self.ctx.ref(), self.as_ast(), target.ref()), target)
446 
def as_ast(self)
Definition: z3py.py:402
def translate(self, target)
Definition: z3py.py:431
def z3_debug()
Definition: z3py.py:70
Z3_ast Z3_API Z3_translate(Z3_context source, Z3_ast a, Z3_context target)
Translate/Copy the AST a from context source to context target. AST a must have been created using co...

Field Documentation

ast
ctx

Definition at line 357 of file z3py.py.

Referenced by ArithRef.__add__(), FuncDeclRef.__call__(), AstRef.__copy__(), AstRef.__deepcopy__(), AstMap.__deepcopy__(), Fixedpoint.__deepcopy__(), Optimize.__deepcopy__(), ApplyResult.__deepcopy__(), Simplifier.__deepcopy__(), Tactic.__deepcopy__(), Probe.__deepcopy__(), ArithRef.__div__(), ExprRef.__eq__(), Probe.__eq__(), ArithRef.__ge__(), Probe.__ge__(), AstMap.__getitem__(), ApplyResult.__getitem__(), ArithRef.__gt__(), Probe.__gt__(), ArithRef.__le__(), Probe.__le__(), ArithRef.__lt__(), Probe.__lt__(), ArithRef.__mod__(), BoolRef.__mul__(), ArithRef.__mul__(), ExprRef.__ne__(), Probe.__ne__(), ArithRef.__neg__(), ArithRef.__pow__(), ArithRef.__radd__(), ArithRef.__rdiv__(), ArithRef.__rmod__(), ArithRef.__rmul__(), ArithRef.__rpow__(), ArithRef.__rsub__(), ArithRef.__sub__(), Simplifier.add(), Fixedpoint.add_rule(), Optimize.add_soft(), Tactic.apply(), AlgebraicNumRef.approx(), ExprRef.arg(), ApplyResult.as_expr(), Optimize.assert_and_track(), Fixedpoint.assert_exprs(), Optimize.assert_exprs(), Optimize.assertions(), BoolSortRef.cast(), ExprRef.decl(), ArrayRef.default(), FuncDeclRef.domain(), ArraySortRef.domain(), ArraySortRef.domain_n(), ParserContext.from_string(), Fixedpoint.get_answer(), Fixedpoint.get_assertions(), Fixedpoint.get_cover_delta(), Fixedpoint.get_ground_sat_answer(), Fixedpoint.get_rule_names_along_trace(), Fixedpoint.get_rules(), Fixedpoint.get_rules_along_trace(), AstMap.keys(), SortRef.kind(), Optimize.model(), SortRef.name(), FuncDeclRef.name(), Optimize.objectives(), Fixedpoint.param_descrs(), Optimize.param_descrs(), Simplifier.param_descrs(), Tactic.param_descrs(), FuncDeclRef.params(), Fixedpoint.parse_file(), Fixedpoint.parse_string(), AlgebraicNumRef.poly(), Fixedpoint.query(), FuncDeclRef.range(), ArraySortRef.range(), Fixedpoint.set(), Optimize.set(), Optimize.set_on_model(), Tactic.solver(), ExprRef.sort(), BoolRef.sort(), ArithRef.sort(), ArrayRef.sort(), FiniteDomainRef.sort(), Fixedpoint.statistics(), Optimize.statistics(), Solver.to_smt2(), Optimize.unsat_core(), Fixedpoint.update_rule(), and Simplifier.using_params().