Z3
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules 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 6318 of file z3py.py.

Constructor & Destructor Documentation

def __init__ (   self,
  result,
  ctx 
)

Definition at line 6321 of file z3py.py.

6322  def __init__(self, result, ctx):
6323  self.result = result
6324  self.ctx = ctx
6325  Z3_apply_result_inc_ref(self.ctx.ref(), self.result)
void Z3_API Z3_apply_result_inc_ref(__in Z3_context c, __in Z3_apply_result r)
Increment the reference counter of the given Z3_apply_result object.
def __del__ (   self)

Definition at line 6326 of file z3py.py.

6327  def __del__(self):
6328  Z3_apply_result_dec_ref(self.ctx.ref(), self.result)
void Z3_API Z3_apply_result_dec_ref(__in Z3_context c, __in 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 6348 of file z3py.py.

6349  def __getitem__(self, idx):
6350  """Return one of the subgoals stored in ApplyResult object `self`.
6351 
6352  >>> a, b = Ints('a b')
6353  >>> g = Goal()
6354  >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
6355  >>> t = Tactic('split-clause')
6356  >>> r = t(g)
6357  >>> r[0]
6358  [a == 0, Or(b == 0, b == 1), a > b]
6359  >>> r[1]
6360  [a == 1, Or(b == 0, b == 1), a > b]
6361  """
6362  if idx >= len(self):
6363  raise IndexError
6364  return Goal(goal=Z3_apply_result_get_subgoal(self.ctx.ref(), self.result, idx), ctx=self.ctx)
Z3_goal Z3_API Z3_apply_result_get_subgoal(__in Z3_context c, __in Z3_apply_result r, __in unsigned i)
Return one of the subgoals in the Z3_apply_result object returned by Z3_tactic_apply.
def __getitem__
Definition: z3py.py:6348
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 6329 of file z3py.py.

6330  def __len__(self):
6331  """Return the number of subgoals in `self`.
6332 
6333  >>> a, b = Ints('a b')
6334  >>> g = Goal()
6335  >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
6336  >>> t = Tactic('split-clause')
6337  >>> r = t(g)
6338  >>> len(r)
6339  2
6340  >>> t = Then(Tactic('split-clause'), Tactic('split-clause'))
6341  >>> len(t(g))
6342  4
6343  >>> t = Then(Tactic('split-clause'), Tactic('split-clause'), Tactic('propagate-values'))
6344  >>> len(t(g))
6345  1
6346  """
6347  return int(Z3_apply_result_get_num_subgoals(self.ctx.ref(), self.result))
unsigned Z3_API Z3_apply_result_get_num_subgoals(__in Z3_context c, __in 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 6365 of file z3py.py.

6366  def __repr__(self):
6367  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 6403 of file z3py.py.

6404  def as_expr(self):
6405  """Return a Z3 expression consisting of all subgoals.
6406 
6407  >>> x = Int('x')
6408  >>> g = Goal()
6409  >>> g.add(x > 1)
6410  >>> g.add(Or(x == 2, x == 3))
6411  >>> r = Tactic('simplify')(g)
6412  >>> r
6413  [[Not(x <= 1), Or(x == 2, x == 3)]]
6414  >>> r.as_expr()
6415  And(Not(x <= 1), Or(x == 2, x == 3))
6416  >>> r = Tactic('split-clause')(g)
6417  >>> r
6418  [[x > 1, x == 2], [x > 1, x == 3]]
6419  >>> r.as_expr()
6420  Or(And(x > 1, x == 2), And(x > 1, x == 3))
6421  """
6422  sz = len(self)
6423  if sz == 0:
6424  return BoolVal(False, self.ctx)
6425  elif sz == 1:
6426  return self[0].as_expr()
6427  else:
6428  return Or([ self[i].as_expr() for i in range(len(self)) ])
def BoolVal
Definition: z3py.py:1342
def Or
Definition: z3py.py:1498
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 6372 of file z3py.py.

6373  def convert_model(self, model, idx=0):
6374  """Convert a model for a subgoal into a model for the original goal.
6375 
6376  >>> a, b = Ints('a b')
6377  >>> g = Goal()
6378  >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
6379  >>> t = Then(Tactic('split-clause'), Tactic('solve-eqs'))
6380  >>> r = t(g)
6381  >>> r[0]
6382  [Or(b == 0, b == 1), Not(0 <= b)]
6383  >>> r[1]
6384  [Or(b == 0, b == 1), Not(1 <= b)]
6385  >>> # Remark: the subgoal r[0] is unsatisfiable
6386  >>> # Creating a solver for solving the second subgoal
6387  >>> s = Solver()
6388  >>> s.add(r[1])
6389  >>> s.check()
6390  sat
6391  >>> s.model()
6392  [b = 0]
6393  >>> # Model s.model() does not assign a value to `a`
6394  >>> # It is a model for subgoal `r[1]`, but not for goal `g`
6395  >>> # The method convert_model creates a model for `g` from a model for `r[1]`.
6396  >>> r.convert_model(s.model(), 1)
6397  [b = 0, a = 1]
6398  """
6399  if __debug__:
6400  _z3_assert(idx < len(self), "index out of bounds")
6401  _z3_assert(isinstance(model, ModelRef), "Z3 Model expected")
6402  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(__in Z3_context c, __in Z3_apply_result r, __in unsigned i, __in 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:6372
def sexpr (   self)
Return a textual representation of the s-expression representing the set of subgoals in `self`.

Definition at line 6368 of file z3py.py.

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

Field Documentation

ctx

Definition at line 6323 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 6322 of file z3py.py.

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