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

Constructor & Destructor Documentation

def __init__ (   self,
  ast,
  ctx = None 
)

Definition at line 344 of file z3py.py.

344  def __init__(self, ast, ctx=None):
345  self.ast = ast
346  self.ctx = _get_ctx(ctx)
347  Z3_inc_ref(self.ctx.ref(), self.as_ast())
348 
def as_ast(self)
Definition: z3py.py:391
def __init__
Definition: z3py.py:344
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 349 of file z3py.py.

349  def __del__(self):
350  if self.ctx.ref() is not None and self.ast is not None:
351  Z3_dec_ref(self.ctx.ref(), self.as_ast())
352  self.ast = None
353 
def as_ast(self)
Definition: z3py.py:391
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:349

Member Function Documentation

def __bool__ (   self)

Definition at line 372 of file z3py.py.

Referenced by AstRef.__nonzero__().

372  def __bool__(self):
373  if is_true(self):
374  return True
375  elif is_false(self):
376  return False
377  elif is_eq(self) and self.num_args() == 2:
378  return self.arg(0).eq(self.arg(1))
379  else:
380  raise Z3Exception("Symbolic expressions cannot be cast to concrete Boolean values.")
381 
def is_eq(a)
Definition: z3py.py:1635
def __bool__(self)
Definition: z3py.py:372
def is_true(a)
Definition: z3py.py:1555
def eq(self, other)
Definition: z3py.py:403
def is_false(a)
Definition: z3py.py:1573
def __copy__ (   self)

Definition at line 436 of file z3py.py.

436  def __copy__(self):
437  return self.translate(self.ctx)
438 
def translate(self, target)
Definition: z3py.py:420
def __copy__(self)
Definition: z3py.py:436
def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 354 of file z3py.py.

354  def __deepcopy__(self, memo={}):
355  return _to_ast_ref(self.ast, self.ctx)
356 
def __deepcopy__
Definition: z3py.py:354
def __eq__ (   self,
  other 
)

Definition at line 363 of file z3py.py.

Referenced by Probe.__ne__().

363  def __eq__(self, other):
364  return self.eq(other)
365 
def __eq__(self, other)
Definition: z3py.py:363
def eq(self, other)
Definition: z3py.py:403
def __hash__ (   self)

Definition at line 366 of file z3py.py.

366  def __hash__(self):
367  return self.hash()
368 
def hash(self)
Definition: z3py.py:439
def __hash__(self)
Definition: z3py.py:366
def __nonzero__ (   self)

Definition at line 369 of file z3py.py.

369  def __nonzero__(self):
370  return self.__bool__()
371 
def __nonzero__(self)
Definition: z3py.py:369
def __bool__(self)
Definition: z3py.py:372
def __repr__ (   self)

Definition at line 360 of file z3py.py.

360  def __repr__(self):
361  return obj_to_string(self)
362 
def __repr__(self)
Definition: z3py.py:360
def __str__ (   self)

Definition at line 357 of file z3py.py.

357  def __str__(self):
358  return obj_to_string(self)
359 
def __str__(self)
Definition: z3py.py:357
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 403 of file z3py.py.

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

403  def eq(self, other):
404  """Return `True` if `self` and `other` are structurally identical.
405 
406  >>> x = Int('x')
407  >>> n1 = x + 1
408  >>> n2 = 1 + x
409  >>> n1.eq(n2)
410  False
411  >>> n1 = simplify(n1)
412  >>> n2 = simplify(n2)
413  >>> n1.eq(n2)
414  True
415  """
416  if z3_debug():
417  _z3_assert(is_ast(other), "Z3 AST expected")
418  return Z3_is_eq_ast(self.ctx_ref(), self.as_ast(), other.as_ast())
419 
def as_ast(self)
Definition: z3py.py:391
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:403
def z3_debug()
Definition: z3py.py:64
def ctx_ref(self)
Definition: z3py.py:399
def is_ast(a)
Definition: z3py.py:450
def get_id (   self)
Return unique identifier for object. It can be used for hash-tables and maps.

Definition at line 395 of file z3py.py.

395  def get_id(self):
396  """Return unique identifier for object. It can be used for hash-tables and maps."""
397  return Z3_get_ast_id(self.ctx_ref(), self.as_ast())
398 
def as_ast(self)
Definition: z3py.py:391
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:395
def ctx_ref(self)
Definition: z3py.py:399
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 439 of file z3py.py.

Referenced by AstRef.__hash__().

439  def hash(self):
440  """Return a hashcode for the `self`.
441 
442  >>> n1 = simplify(Int('x') + 1)
443  >>> n2 = simplify(2 + Int('x') - 1)
444  >>> n1.hash() == n2.hash()
445  True
446  """
447  return Z3_get_ast_hash(self.ctx_ref(), self.as_ast())
448 
449 
def as_ast(self)
Definition: z3py.py:391
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:439
def ctx_ref(self)
Definition: z3py.py:399
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 382 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().

382  def sexpr(self):
383  """Return a string representing the AST node in s-expression notation.
384 
385  >>> x = Int('x')
386  >>> ((x + 1)*x).sexpr()
387  '(* (+ x 1) x)'
388  """
389  return Z3_ast_to_string(self.ctx_ref(), self.as_ast())
390 
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:391
def sexpr(self)
Definition: z3py.py:382
def ctx_ref(self)
Definition: z3py.py:399
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 420 of file z3py.py.

Referenced by AstRef.__copy__().

420  def translate(self, target):
421  """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
422 
423  >>> c1 = Context()
424  >>> c2 = Context()
425  >>> x = Int('x', c1)
426  >>> y = Int('y', c2)
427  >>> # Nodes in different contexts can't be mixed.
428  >>> # However, we can translate nodes from one context to another.
429  >>> x.translate(c2) + y
430  x + y
431  """
432  if z3_debug():
433  _z3_assert(isinstance(target, Context), "argument must be a Z3 context")
434  return _to_ast_ref(Z3_translate(self.ctx.ref(), self.as_ast(), target.ref()), target)
435 
def as_ast(self)
Definition: z3py.py:391
def translate(self, target)
Definition: z3py.py:420
def z3_debug()
Definition: z3py.py:64
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 346 of file z3py.py.

Referenced by ArithRef.__add__(), FuncDeclRef.__call__(), AstRef.__copy__(), AstRef.__deepcopy__(), AstMap.__deepcopy__(), Fixedpoint.__deepcopy__(), Optimize.__deepcopy__(), ApplyResult.__deepcopy__(), Tactic.__deepcopy__(), Probe.__deepcopy__(), ArithRef.__div__(), ExprRef.__eq__(), Probe.__eq__(), ArithRef.__ge__(), Probe.__ge__(), ArrayRef.__getitem__(), AstMap.__getitem__(), ApplyResult.__getitem__(), ArithRef.__gt__(), Probe.__gt__(), ArithRef.__le__(), Probe.__le__(), ArithRef.__lt__(), Probe.__lt__(), ArithRef.__mod__(), ArithRef.__mul__(), ExprRef.__ne__(), Probe.__ne__(), ArithRef.__neg__(), ArithRef.__pow__(), ArithRef.__radd__(), ArithRef.__rdiv__(), ArithRef.__rmod__(), ArithRef.__rmul__(), ArithRef.__rpow__(), ArithRef.__rsub__(), ArithRef.__sub__(), 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(), 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(), 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(), and Fixedpoint.update_rule().