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

Constructor & Destructor Documentation

def __init__ (   self,
  ast,
  ctx = None 
)

Definition at line 372 of file z3py.py.

372  def __init__(self, ast, ctx=None):
373  self.ast = ast
374  self.ctx = _get_ctx(ctx)
375  Z3_inc_ref(self.ctx.ref(), self.as_ast())
376 
def as_ast(self)
Definition: z3py.py:419
def __init__
Definition: z3py.py:372
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 377 of file z3py.py.

377  def __del__(self):
378  if self.ctx.ref() is not None and self.ast is not None and Z3_dec_ref is not None:
379  Z3_dec_ref(self.ctx.ref(), self.as_ast())
380  self.ast = None
381 
def as_ast(self)
Definition: z3py.py:419
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:377

Member Function Documentation

def __bool__ (   self)

Definition at line 400 of file z3py.py.

Referenced by AstRef.__nonzero__().

400  def __bool__(self):
401  if is_true(self):
402  return True
403  elif is_false(self):
404  return False
405  elif is_eq(self) and self.num_args() == 2:
406  return self.arg(0).eq(self.arg(1))
407  else:
408  raise Z3Exception("Symbolic expressions cannot be cast to concrete Boolean values.")
409 
def is_eq
Definition: z3py.py:1802
def is_true
Definition: z3py.py:1722
def is_false
Definition: z3py.py:1740
def __bool__(self)
Definition: z3py.py:400
def eq(self, other)
Definition: z3py.py:431
def __copy__ (   self)

Definition at line 464 of file z3py.py.

464  def __copy__(self):
465  return self.translate(self.ctx)
466 
def translate(self, target)
Definition: z3py.py:448
def __copy__(self)
Definition: z3py.py:464
def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 382 of file z3py.py.

382  def __deepcopy__(self, memo={}):
383  return _to_ast_ref(self.ast, self.ctx)
384 
def __deepcopy__
Definition: z3py.py:382
def __eq__ (   self,
  other 
)

Definition at line 391 of file z3py.py.

Referenced by Probe.__ne__().

391  def __eq__(self, other):
392  return self.eq(other)
393 
def __eq__(self, other)
Definition: z3py.py:391
def eq(self, other)
Definition: z3py.py:431
def __hash__ (   self)

Definition at line 394 of file z3py.py.

394  def __hash__(self):
395  return self.hash()
396 
def hash(self)
Definition: z3py.py:467
def __hash__(self)
Definition: z3py.py:394
def __nonzero__ (   self)

Definition at line 397 of file z3py.py.

397  def __nonzero__(self):
398  return self.__bool__()
399 
def __nonzero__(self)
Definition: z3py.py:397
def __bool__(self)
Definition: z3py.py:400
def __repr__ (   self)

Definition at line 388 of file z3py.py.

388  def __repr__(self):
389  return obj_to_string(self)
390 
def __repr__(self)
Definition: z3py.py:388
def __str__ (   self)

Definition at line 385 of file z3py.py.

385  def __str__(self):
386  return obj_to_string(self)
387 
def __str__(self)
Definition: z3py.py:385
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 431 of file z3py.py.

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

431  def eq(self, other):
432  """Return `True` if `self` and `other` are structurally identical.
433 
434  >>> x = Int('x')
435  >>> n1 = x + 1
436  >>> n2 = 1 + x
437  >>> n1.eq(n2)
438  False
439  >>> n1 = simplify(n1)
440  >>> n2 = simplify(n2)
441  >>> n1.eq(n2)
442  True
443  """
444  if z3_debug():
445  _z3_assert(is_ast(other), "Z3 AST expected")
446  return Z3_is_eq_ast(self.ctx_ref(), self.as_ast(), other.as_ast())
447 
def is_ast
Definition: z3py.py:482
def as_ast(self)
Definition: z3py.py:419
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:431
def z3_debug()
Definition: z3py.py:70
def ctx_ref(self)
Definition: z3py.py:427
def get_id (   self)
Return unique identifier for object. It can be used for hash-tables and maps.

Definition at line 423 of file z3py.py.

423  def get_id(self):
424  """Return unique identifier for object. It can be used for hash-tables and maps."""
425  return Z3_get_ast_id(self.ctx_ref(), self.as_ast())
426 
def as_ast(self)
Definition: z3py.py:419
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:423
def ctx_ref(self)
Definition: z3py.py:427
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 467 of file z3py.py.

Referenced by AstRef.__hash__().

467  def hash(self):
468  """Return a hashcode for the `self`.
469 
470  >>> n1 = simplify(Int('x') + 1)
471  >>> n2 = simplify(2 + Int('x') - 1)
472  >>> n1.hash() == n2.hash()
473  True
474  """
475  return Z3_get_ast_hash(self.ctx_ref(), self.as_ast())
476 
def as_ast(self)
Definition: z3py.py:419
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:467
def ctx_ref(self)
Definition: z3py.py:427
def py_value (   self)
Return a Python value that is equivalent to `self`.

Definition at line 477 of file z3py.py.

477  def py_value(self):
478  """Return a Python value that is equivalent to `self`."""
479  return None
480 
481 
def py_value(self)
Definition: z3py.py:477
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 410 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().

410  def sexpr(self):
411  """Return a string representing the AST node in s-expression notation.
412 
413  >>> x = Int('x')
414  >>> ((x + 1)*x).sexpr()
415  '(* (+ x 1) x)'
416  """
417  return Z3_ast_to_string(self.ctx_ref(), self.as_ast())
418 
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:419
def sexpr(self)
Definition: z3py.py:410
def ctx_ref(self)
Definition: z3py.py:427
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 448 of file z3py.py.

Referenced by AstRef.__copy__().

448  def translate(self, target):
449  """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
450 
451  >>> c1 = Context()
452  >>> c2 = Context()
453  >>> x = Int('x', c1)
454  >>> y = Int('y', c2)
455  >>> # Nodes in different contexts can't be mixed.
456  >>> # However, we can translate nodes from one context to another.
457  >>> x.translate(c2) + y
458  x + y
459  """
460  if z3_debug():
461  _z3_assert(isinstance(target, Context), "argument must be a Z3 context")
462  return _to_ast_ref(Z3_translate(self.ctx.ref(), self.as_ast(), target.ref()), target)
463 
def as_ast(self)
Definition: z3py.py:419
def translate(self, target)
Definition: z3py.py:448
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 374 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(), ExprRef.update(), Fixedpoint.update_rule(), and Simplifier.using_params().