Z3
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Data Fields
ApplyResult Class Reference
+ Inheritance diagram for ApplyResult:

Public Member Functions

def __init__
 
def __del__
 
def __len__
 
def __getitem__
 
def __repr__
 
def sexpr
 
def convert_model
 
def as_expr
 
- Public Member Functions inherited from Z3PPObject
def use_pp
 

Data Fields

 result
 
 ctx
 

Detailed Description

An ApplyResult object contains the subgoals produced by a tactic when applied to a goal. It also contains model and proof converters.

Definition at line 6540 of file z3py.py.

Constructor & Destructor Documentation

def __init__ (   self,
  result,
  ctx 
)

Definition at line 6543 of file z3py.py.

6544  def __init__(self, result, ctx):
6545  self.result = result
6546  self.ctx = ctx
6547  Z3_apply_result_inc_ref(self.ctx.ref(), self.result)
void Z3_API Z3_apply_result_inc_ref(Z3_context c, Z3_apply_result r)
Increment the reference counter of the given Z3_apply_result object.
def __del__ (   self)

Definition at line 6548 of file z3py.py.

6549  def __del__(self):
6550  Z3_apply_result_dec_ref(self.ctx.ref(), self.result)
void Z3_API Z3_apply_result_dec_ref(Z3_context c, Z3_apply_result r)
Decrement the reference counter of the given Z3_apply_result object.

Member Function Documentation

def __getitem__ (   self,
  idx 
)
Return one of the subgoals stored in ApplyResult object `self`.

>>> a, b = Ints('a b')
>>> g = Goal()
>>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
>>> t = Tactic('split-clause')
>>> r = t(g)
>>> r[0]        
[a == 0, Or(b == 0, b == 1), a > b]
>>> r[1]
[a == 1, Or(b == 0, b == 1), a > b]

Definition at line 6570 of file z3py.py.

6571  def __getitem__(self, idx):
6572  """Return one of the subgoals stored in ApplyResult object `self`.
6573 
6574  >>> a, b = Ints('a b')
6575  >>> g = Goal()
6576  >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
6577  >>> t = Tactic('split-clause')
6578  >>> r = t(g)
6579  >>> r[0]
6580  [a == 0, Or(b == 0, b == 1), a > b]
6581  >>> r[1]
6582  [a == 1, Or(b == 0, b == 1), a > b]
6583  """
6584  if idx >= len(self):
6585  raise IndexError
6586  return Goal(goal=Z3_apply_result_get_subgoal(self.ctx.ref(), self.result, idx), ctx=self.ctx)
def __getitem__
Definition: z3py.py:6570
Z3_goal Z3_API Z3_apply_result_get_subgoal(Z3_context c, Z3_apply_result r, unsigned i)
Return one of the subgoals in the Z3_apply_result object returned by Z3_tactic_apply.
def __len__ (   self)
Return the number of subgoals in `self`.

>>> a, b = Ints('a b')
>>> g = Goal()
>>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
>>> t = Tactic('split-clause')
>>> r = t(g)
>>> len(r)
2
>>> t = Then(Tactic('split-clause'), Tactic('split-clause'))
>>> len(t(g))
4
>>> t = Then(Tactic('split-clause'), Tactic('split-clause'), Tactic('propagate-values'))
>>> len(t(g))
1

Definition at line 6551 of file z3py.py.

6552  def __len__(self):
6553  """Return the number of subgoals in `self`.
6554 
6555  >>> a, b = Ints('a b')
6556  >>> g = Goal()
6557  >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
6558  >>> t = Tactic('split-clause')
6559  >>> r = t(g)
6560  >>> len(r)
6561  2
6562  >>> t = Then(Tactic('split-clause'), Tactic('split-clause'))
6563  >>> len(t(g))
6564  4
6565  >>> t = Then(Tactic('split-clause'), Tactic('split-clause'), Tactic('propagate-values'))
6566  >>> len(t(g))
6567  1
6568  """
6569  return int(Z3_apply_result_get_num_subgoals(self.ctx.ref(), self.result))
unsigned Z3_API Z3_apply_result_get_num_subgoals(Z3_context c, Z3_apply_result r)
Return the number of subgoals in the Z3_apply_result object returned by Z3_tactic_apply.
def __repr__ (   self)

Definition at line 6587 of file z3py.py.

6588  def __repr__(self):
6589  return obj_to_string(self)
def as_expr (   self)
Return a Z3 expression consisting of all subgoals.

>>> x = Int('x')
>>> g = Goal()
>>> g.add(x > 1)
>>> g.add(Or(x == 2, x == 3))
>>> r = Tactic('simplify')(g)
>>> r
[[Not(x <= 1), Or(x == 2, x == 3)]]
>>> r.as_expr()
And(Not(x <= 1), Or(x == 2, x == 3))
>>> r = Tactic('split-clause')(g)
>>> r
[[x > 1, x == 2], [x > 1, x == 3]]
>>> r.as_expr()
Or(And(x > 1, x == 2), And(x > 1, x == 3))

Definition at line 6625 of file z3py.py.

6626  def as_expr(self):
6627  """Return a Z3 expression consisting of all subgoals.
6628 
6629  >>> x = Int('x')
6630  >>> g = Goal()
6631  >>> g.add(x > 1)
6632  >>> g.add(Or(x == 2, x == 3))
6633  >>> r = Tactic('simplify')(g)
6634  >>> r
6635  [[Not(x <= 1), Or(x == 2, x == 3)]]
6636  >>> r.as_expr()
6637  And(Not(x <= 1), Or(x == 2, x == 3))
6638  >>> r = Tactic('split-clause')(g)
6639  >>> r
6640  [[x > 1, x == 2], [x > 1, x == 3]]
6641  >>> r.as_expr()
6642  Or(And(x > 1, x == 2), And(x > 1, x == 3))
6643  """
6644  sz = len(self)
6645  if sz == 0:
6646  return BoolVal(False, self.ctx)
6647  elif sz == 1:
6648  return self[0].as_expr()
6649  else:
6650  return Or([ self[i].as_expr() for i in range(len(self)) ])
def BoolVal
Definition: z3py.py:1363
def Or
Definition: z3py.py:1519
def convert_model (   self,
  model,
  idx = 0 
)
Convert a model for a subgoal into a model for the original goal.

>>> a, b = Ints('a b')
>>> g = Goal()
>>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
>>> t = Then(Tactic('split-clause'), Tactic('solve-eqs'))
>>> r = t(g)
>>> r[0]        
[Or(b == 0, b == 1), Not(0 <= b)]
>>> r[1]
[Or(b == 0, b == 1), Not(1 <= b)]
>>> # Remark: the subgoal r[0] is unsatisfiable
>>> # Creating a solver for solving the second subgoal
>>> s = Solver()
>>> s.add(r[1])
>>> s.check()
sat
>>> s.model()
[b = 0]
>>> # Model s.model() does not assign a value to `a`
>>> # It is a model for subgoal `r[1]`, but not for goal `g`
>>> # The method convert_model creates a model for `g` from a model for `r[1]`.
>>> r.convert_model(s.model(), 1)
[b = 0, a = 1]

Definition at line 6594 of file z3py.py.

6595  def convert_model(self, model, idx=0):
6596  """Convert a model for a subgoal into a model for the original goal.
6597 
6598  >>> a, b = Ints('a b')
6599  >>> g = Goal()
6600  >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
6601  >>> t = Then(Tactic('split-clause'), Tactic('solve-eqs'))
6602  >>> r = t(g)
6603  >>> r[0]
6604  [Or(b == 0, b == 1), Not(0 <= b)]
6605  >>> r[1]
6606  [Or(b == 0, b == 1), Not(1 <= b)]
6607  >>> # Remark: the subgoal r[0] is unsatisfiable
6608  >>> # Creating a solver for solving the second subgoal
6609  >>> s = Solver()
6610  >>> s.add(r[1])
6611  >>> s.check()
6612  sat
6613  >>> s.model()
6614  [b = 0]
6615  >>> # Model s.model() does not assign a value to `a`
6616  >>> # It is a model for subgoal `r[1]`, but not for goal `g`
6617  >>> # The method convert_model creates a model for `g` from a model for `r[1]`.
6618  >>> r.convert_model(s.model(), 1)
6619  [b = 0, a = 1]
6620  """
6621  if __debug__:
6622  _z3_assert(idx < len(self), "index out of bounds")
6623  _z3_assert(isinstance(model, ModelRef), "Z3 Model expected")
6624  return ModelRef(Z3_apply_result_convert_model(self.ctx.ref(), self.result, idx, model.model), self.ctx)
Z3_model Z3_API Z3_apply_result_convert_model(Z3_context c, Z3_apply_result r, unsigned i, Z3_model m)
Convert a model for the subgoal Z3_apply_result_get_subgoal(c, r, i) into a model for the original go...
def convert_model
Definition: z3py.py:6594
def sexpr (   self)
Return a textual representation of the s-expression representing the set of subgoals in `self`.

Definition at line 6590 of file z3py.py.

6591  def sexpr(self):
6592  """Return a textual representation of the s-expression representing the set of subgoals in `self`."""
6593  return Z3_apply_result_to_string(self.ctx.ref(), self.result)
Z3_string Z3_API Z3_apply_result_to_string(Z3_context c, Z3_apply_result r)
Convert the Z3_apply_result object returned by Z3_tactic_apply into a string.

Field Documentation

ctx

Definition at line 6545 of file z3py.py.

Referenced by Probe.__eq__(), Probe.__ge__(), ApplyResult.__getitem__(), Probe.__gt__(), Probe.__le__(), Probe.__lt__(), Probe.__ne__(), Tactic.apply(), ApplyResult.as_expr(), ApplyResult.convert_model(), Tactic.param_descrs(), and Tactic.solver().

result

Definition at line 6544 of file z3py.py.

Referenced by ApplyResult.__del__(), ApplyResult.__getitem__(), ApplyResult.__len__(), ApplyResult.convert_model(), and ApplyResult.sexpr().