Z3
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
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

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.

06543 
06544     def __init__(self, result, ctx):
06545         self.result = result
06546         self.ctx    = ctx
06547         Z3_apply_result_inc_ref(self.ctx.ref(), self.result)

def __del__ (   self)

Definition at line 6548 of file z3py.py.

06548 
06549     def __del__(self):
06550         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 6570 of file z3py.py.

06570 
06571     def __getitem__(self, idx):
06572         """Return one of the subgoals stored in ApplyResult object `self`.
06573 
06574         >>> a, b = Ints('a b')
06575         >>> g = Goal()
06576         >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
06577         >>> t = Tactic('split-clause')
06578         >>> r = t(g)
06579         >>> r[0]        
06580         [a == 0, Or(b == 0, b == 1), a > b]
06581         >>> r[1]
06582         [a == 1, Or(b == 0, b == 1), a > b]
06583         """
06584         if idx >= len(self):
06585             raise IndexError
06586         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 6551 of file z3py.py.

06551 
06552     def __len__(self):
06553         """Return the number of subgoals in `self`.
06554         
06555         >>> a, b = Ints('a b')
06556         >>> g = Goal()
06557         >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
06558         >>> t = Tactic('split-clause')
06559         >>> r = t(g)
06560         >>> len(r)
06561         2
06562         >>> t = Then(Tactic('split-clause'), Tactic('split-clause'))
06563         >>> len(t(g))
06564         4
06565         >>> t = Then(Tactic('split-clause'), Tactic('split-clause'), Tactic('propagate-values'))
06566         >>> len(t(g))
06567         1
06568         """
06569         return int(Z3_apply_result_get_num_subgoals(self.ctx.ref(), self.result))

def __repr__ (   self)

Definition at line 6587 of file z3py.py.

06587 
06588     def __repr__(self):
06589         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.

06625 
06626     def as_expr(self):
06627         """Return a Z3 expression consisting of all subgoals.
06628         
06629         >>> x = Int('x')
06630         >>> g = Goal()
06631         >>> g.add(x > 1)
06632         >>> g.add(Or(x == 2, x == 3))
06633         >>> r = Tactic('simplify')(g)
06634         >>> r
06635         [[Not(x <= 1), Or(x == 2, x == 3)]]
06636         >>> r.as_expr()
06637         And(Not(x <= 1), Or(x == 2, x == 3))
06638         >>> r = Tactic('split-clause')(g)
06639         >>> r
06640         [[x > 1, x == 2], [x > 1, x == 3]]
06641         >>> r.as_expr()
06642         Or(And(x > 1, x == 2), And(x > 1, x == 3))
06643         """
06644         sz = len(self)
06645         if sz == 0:
06646             return BoolVal(False, self.ctx)
06647         elif sz == 1:
06648             return self[0].as_expr()
06649         else:
06650             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 6594 of file z3py.py.

06594 
06595     def convert_model(self, model, idx=0):
06596         """Convert a model for a subgoal into a model for the original goal.
06597 
06598         >>> a, b = Ints('a b')
06599         >>> g = Goal()
06600         >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
06601         >>> t = Then(Tactic('split-clause'), Tactic('solve-eqs'))
06602         >>> r = t(g)
06603         >>> r[0]        
06604         [Or(b == 0, b == 1), Not(0 <= b)]
06605         >>> r[1]
06606         [Or(b == 0, b == 1), Not(1 <= b)]
06607         >>> # Remark: the subgoal r[0] is unsatisfiable
06608         >>> # Creating a solver for solving the second subgoal
06609         >>> s = Solver()
06610         >>> s.add(r[1])
06611         >>> s.check()
06612         sat
06613         >>> s.model()
06614         [b = 0]
06615         >>> # Model s.model() does not assign a value to `a`
06616         >>> # It is a model for subgoal `r[1]`, but not for goal `g`
06617         >>> # The method convert_model creates a model for `g` from a model for `r[1]`.
06618         >>> r.convert_model(s.model(), 1)
06619         [b = 0, a = 1]
06620         """
06621         if __debug__:
06622             _z3_assert(idx < len(self), "index out of bounds")
06623             _z3_assert(isinstance(model, ModelRef), "Z3 Model expected")
06624         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 6590 of file z3py.py.

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


Field Documentation

ctx

Definition at line 6543 of file z3py.py.

Referenced by ArithRef.__add__(), BitVecRef.__add__(), BitVecRef.__and__(), FuncDeclRef.__call__(), ArithRef.__div__(), BitVecRef.__div__(), ExprRef.__eq__(), Probe.__eq__(), ArithRef.__ge__(), BitVecRef.__ge__(), Probe.__ge__(), ArrayRef.__getitem__(), ApplyResult.__getitem__(), ArithRef.__gt__(), BitVecRef.__gt__(), Probe.__gt__(), BitVecRef.__invert__(), ArithRef.__le__(), BitVecRef.__le__(), Probe.__le__(), BitVecRef.__lshift__(), ArithRef.__lt__(), BitVecRef.__lt__(), Probe.__lt__(), ArithRef.__mod__(), BitVecRef.__mod__(), ArithRef.__mul__(), BitVecRef.__mul__(), ExprRef.__ne__(), Probe.__ne__(), ArithRef.__neg__(), BitVecRef.__neg__(), BitVecRef.__or__(), ArithRef.__pow__(), ArithRef.__radd__(), BitVecRef.__radd__(), BitVecRef.__rand__(), ArithRef.__rdiv__(), BitVecRef.__rdiv__(), BitVecRef.__rlshift__(), ArithRef.__rmod__(), BitVecRef.__rmod__(), ArithRef.__rmul__(), BitVecRef.__rmul__(), BitVecRef.__ror__(), ArithRef.__rpow__(), BitVecRef.__rrshift__(), BitVecRef.__rshift__(), ArithRef.__rsub__(), BitVecRef.__rsub__(), BitVecRef.__rxor__(), ArithRef.__sub__(), BitVecRef.__sub__(), BitVecRef.__xor__(), DatatypeSortRef.accessor(), Tactic.apply(), AlgebraicNumRef.approx(), ExprRef.arg(), ApplyResult.as_expr(), QuantifierRef.body(), BoolSortRef.cast(), DatatypeSortRef.constructor(), ApplyResult.convert_model(), ExprRef.decl(), RatNumRef.denominator(), FuncDeclRef.domain(), ArraySortRef.domain(), SortRef.kind(), ArrayRef.mk_default(), SortRef.name(), FuncDeclRef.name(), QuantifierRef.no_pattern(), RatNumRef.numerator(), Tactic.param_descrs(), QuantifierRef.pattern(), FuncDeclRef.range(), ArraySortRef.range(), DatatypeSortRef.recognizer(), Tactic.solver(), ExprRef.sort(), BoolRef.sort(), QuantifierRef.sort(), ArithRef.sort(), BitVecRef.sort(), ArrayRef.sort(), DatatypeRef.sort(), QuantifierRef.var_name(), and QuantifierRef.var_sort().

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines