Z3
Public Member Functions | Data Fields
ApplyResult Class Reference
+ Inheritance diagram for ApplyResult:

Public Member Functions

def __init__ (self, result, ctx)
 
def __del__ (self)
 
def __len__ (self)
 
def __getitem__ (self, idx)
 
def __repr__ (self)
 
def sexpr (self)
 
def convert_model (self, model, idx=0)
 
def as_expr (self)
 
- Public Member Functions inherited from Z3PPObject
def use_pp (self)
 

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.

6543  def __init__(self, result, ctx):
6544  self.result = result
6545  self.ctx = ctx
6546  Z3_apply_result_inc_ref(self.ctx.ref(), self.result)
6547 
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 __init__(self, result, ctx)
Definition: z3py.py:6543
def __del__ (   self)

Definition at line 6548 of file z3py.py.

6548  def __del__(self):
6549  Z3_apply_result_dec_ref(self.ctx.ref(), self.result)
6550 
def __del__(self)
Definition: z3py.py:6548
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.

6570  def __getitem__(self, idx):
6571  """Return one of the subgoals stored in ApplyResult object `self`.
6572 
6573  >>> a, b = Ints('a b')
6574  >>> g = Goal()
6575  >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
6576  >>> t = Tactic('split-clause')
6577  >>> r = t(g)
6578  >>> r[0]
6579  [a == 0, Or(b == 0, b == 1), a > b]
6580  >>> r[1]
6581  [a == 1, Or(b == 0, b == 1), a > b]
6582  """
6583  if idx >= len(self):
6584  raise IndexError
6585  return Goal(goal=Z3_apply_result_get_subgoal(self.ctx.ref(), self.result, idx), ctx=self.ctx)
6586 
def __getitem__(self, idx)
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.

6551  def __len__(self):
6552  """Return the number of subgoals in `self`.
6553 
6554  >>> a, b = Ints('a b')
6555  >>> g = Goal()
6556  >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
6557  >>> t = Tactic('split-clause')
6558  >>> r = t(g)
6559  >>> len(r)
6560  2
6561  >>> t = Then(Tactic('split-clause'), Tactic('split-clause'))
6562  >>> len(t(g))
6563  4
6564  >>> t = Then(Tactic('split-clause'), Tactic('split-clause'), Tactic('propagate-values'))
6565  >>> len(t(g))
6566  1
6567  """
6568  return int(Z3_apply_result_get_num_subgoals(self.ctx.ref(), self.result))
6569 
def __len__(self)
Definition: z3py.py:6551
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.

6587  def __repr__(self):
6588  return obj_to_string(self)
6589 
def __repr__(self)
Definition: z3py.py:6587
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.

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

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

6590  def sexpr(self):
6591  """Return a textual representation of the s-expression representing the set of subgoals in `self`."""
6592  return Z3_apply_result_to_string(self.ctx.ref(), self.result)
6593 
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.
def sexpr(self)
Definition: z3py.py:6590

Field Documentation

ctx
result