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

Constructor & Destructor Documentation

def __init__ (   self,
  result,
  ctx 
)

Definition at line 6205 of file z3py.py.

6206  def __init__(self, result, ctx):
6207  self.result = result
6208  self.ctx = ctx
6209  Z3_apply_result_inc_ref(self.ctx.ref(), self.result)
def __del__ (   self)

Definition at line 6210 of file z3py.py.

6211  def __del__(self):
6212  Z3_apply_result_dec_ref(self.ctx.ref(), self.result)

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

6233  def __getitem__(self, idx):
6234  """Return one of the subgoals stored in ApplyResult object `self`.
6235 
6236  >>> a, b = Ints('a b')
6237  >>> g = Goal()
6238  >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
6239  >>> t = Tactic('split-clause')
6240  >>> r = t(g)
6241  >>> r[0]
6242  [a == 0, Or(b == 0, b == 1), a > b]
6243  >>> r[1]
6244  [a == 1, Or(b == 0, b == 1), a > b]
6245  """
6246  if idx >= len(self):
6247  raise IndexError
6248  return Goal(goal=Z3_apply_result_get_subgoal(self.ctx.ref(), self.result, idx), ctx=self.ctx)
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 6213 of file z3py.py.

6214  def __len__(self):
6215  """Return the number of subgoals in `self`.
6216 
6217  >>> a, b = Ints('a b')
6218  >>> g = Goal()
6219  >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
6220  >>> t = Tactic('split-clause')
6221  >>> r = t(g)
6222  >>> len(r)
6223  2
6224  >>> t = Then(Tactic('split-clause'), Tactic('split-clause'))
6225  >>> len(t(g))
6226  4
6227  >>> t = Then(Tactic('split-clause'), Tactic('split-clause'), Tactic('propagate-values'))
6228  >>> len(t(g))
6229  1
6230  """
6231  return int(Z3_apply_result_get_num_subgoals(self.ctx.ref(), self.result))
def __repr__ (   self)

Definition at line 6249 of file z3py.py.

6250  def __repr__(self):
6251  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 6287 of file z3py.py.

6288  def as_expr(self):
6289  """Return a Z3 expression consisting of all subgoals.
6290 
6291  >>> x = Int('x')
6292  >>> g = Goal()
6293  >>> g.add(x > 1)
6294  >>> g.add(Or(x == 2, x == 3))
6295  >>> r = Tactic('simplify')(g)
6296  >>> r
6297  [[Not(x <= 1), Or(x == 2, x == 3)]]
6298  >>> r.as_expr()
6299  And(Not(x <= 1), Or(x == 2, x == 3))
6300  >>> r = Tactic('split-clause')(g)
6301  >>> r
6302  [[x > 1, x == 2], [x > 1, x == 3]]
6303  >>> r.as_expr()
6304  Or(And(x > 1, x == 2), And(x > 1, x == 3))
6305  """
6306  sz = len(self)
6307  if sz == 0:
6308  return BoolVal(False, self.ctx)
6309  elif sz == 1:
6310  return self[0].as_expr()
6311  else:
6312  return Or([ self[i].as_expr() for i in range(len(self)) ])
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 6256 of file z3py.py.

6257  def convert_model(self, model, idx=0):
6258  """Convert a model for a subgoal into a model for the original goal.
6259 
6260  >>> a, b = Ints('a b')
6261  >>> g = Goal()
6262  >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
6263  >>> t = Then(Tactic('split-clause'), Tactic('solve-eqs'))
6264  >>> r = t(g)
6265  >>> r[0]
6266  [Or(b == 0, b == 1), Not(0 <= b)]
6267  >>> r[1]
6268  [Or(b == 0, b == 1), Not(1 <= b)]
6269  >>> # Remark: the subgoal r[0] is unsatisfiable
6270  >>> # Creating a solver for solving the second subgoal
6271  >>> s = Solver()
6272  >>> s.add(r[1])
6273  >>> s.check()
6274  sat
6275  >>> s.model()
6276  [b = 0]
6277  >>> # Model s.model() does not assign a value to `a`
6278  >>> # It is a model for subgoal `r[1]`, but not for goal `g`
6279  >>> # The method convert_model creates a model for `g` from a model for `r[1]`.
6280  >>> r.convert_model(s.model(), 1)
6281  [b = 0, a = 1]
6282  """
6283  if __debug__:
6284  _z3_assert(idx < len(self), "index out of bounds")
6285  _z3_assert(isinstance(model, ModelRef), "Z3 Model expected")
6286  return ModelRef(Z3_apply_result_convert_model(self.ctx.ref(), self.result, idx, model.model), self.ctx)
def sexpr (   self)
Return a textual representation of the s-expression representing the set of subgoals in `self`.

Definition at line 6252 of file z3py.py.

6253  def sexpr(self):
6254  """Return a textual representation of the s-expression representing the set of subgoals in `self`."""
6255  return Z3_apply_result_to_string(self.ctx.ref(), self.result)

Field Documentation

ctx

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

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