Z3
Loading...
Searching...
No Matches
ApplyResult Class Reference
Inheritance diagram for ApplyResult:

Public Member Functions

 __init__ (self, result, ctx)
 __deepcopy__ (self, memo={})
 __del__ (self)
 __len__ (self)
 __getitem__ (self, idx)
 __repr__ (self)
 sexpr (self)
 as_expr (self)
Public Member Functions inherited from Z3PPObject
 use_pp (self)

Data Fields

 result = result
 ctx = ctx

Additional Inherited Members

Protected Member Functions inherited from Z3PPObject
 _repr_html_ (self)

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

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
result,
ctx )

Definition at line 8978 of file z3py.py.

8978 def __init__(self, result, ctx):
8979 self.result = result
8980 self.ctx = ctx
8981 Z3_apply_result_inc_ref(self.ctx.ref(), self.result)
8982
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.

◆ __del__()

__del__ ( self)

Definition at line 8986 of file z3py.py.

8986 def __del__(self):
8987 if self.ctx.ref() is not None and Z3_apply_result_dec_ref is not None:
8988 Z3_apply_result_dec_ref(self.ctx.ref(), self.result)
8989
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

◆ __deepcopy__()

__deepcopy__ ( self,
memo = {} )

Definition at line 8983 of file z3py.py.

8983 def __deepcopy__(self, memo={}):
8984 return ApplyResult(self.result, self.ctx)
8985

◆ __getitem__()

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

9009 def __getitem__(self, idx):
9010 """Return one of the subgoals stored in ApplyResult object `self`.
9011
9012 >>> a, b = Ints('a b')
9013 >>> g = Goal()
9014 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
9015 >>> t = Tactic('split-clause')
9016 >>> r = t(g)
9017 >>> r[0]
9018 [a == 0, Or(b == 0, b == 1), a > b]
9019 >>> r[1]
9020 [a == 1, Or(b == 0, b == 1), a > b]
9021 """
9022 if idx < 0:
9023 idx += len(self)
9024 if idx < 0 or idx >= len(self):
9025 raise IndexError
9026 return Goal(goal=Z3_apply_result_get_subgoal(self.ctx.ref(), self.result, idx), ctx=self.ctx)
9027
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.

◆ __len__()

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

8990 def __len__(self):
8991 """Return the number of subgoals in `self`.
8992
8993 >>> a, b = Ints('a b')
8994 >>> g = Goal()
8995 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
8996 >>> t = Tactic('split-clause')
8997 >>> r = t(g)
8998 >>> len(r)
8999 2
9000 >>> t = Then(Tactic('split-clause'), Tactic('split-clause'))
9001 >>> len(t(g))
9002 4
9003 >>> t = Then(Tactic('split-clause'), Tactic('split-clause'), Tactic('propagate-values'))
9004 >>> len(t(g))
9005 1
9006 """
9007 return int(Z3_apply_result_get_num_subgoals(self.ctx.ref(), self.result))
9008
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.

◆ __repr__()

__repr__ ( self)

Definition at line 9028 of file z3py.py.

9028 def __repr__(self):
9029 return obj_to_string(self)
9030

◆ as_expr()

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

9035 def as_expr(self):
9036 """Return a Z3 expression consisting of all subgoals.
9037
9038 >>> x = Int('x')
9039 >>> g = Goal()
9040 >>> g.add(x > 1)
9041 >>> g.add(Or(x == 2, x == 3))
9042 >>> r = Tactic('simplify')(g)
9043 >>> r
9044 [[Not(x <= 1), Or(x == 2, x == 3)]]
9045 >>> r.as_expr()
9046 And(Not(x <= 1), Or(x == 2, x == 3))
9047 >>> r = Tactic('split-clause')(g)
9048 >>> r
9049 [[x > 1, x == 2], [x > 1, x == 3]]
9050 >>> r.as_expr()
9051 Or(And(x > 1, x == 2), And(x > 1, x == 3))
9052 """
9053 sz = len(self)
9054 if sz == 0:
9055 return BoolVal(False, self.ctx)
9056 elif sz == 1:
9057 return self[0].as_expr()
9058 else:
9059 return Or([self[i].as_expr() for i in range(len(self))])
9060

◆ sexpr()

sexpr ( self)
Return a textual representation of the s-expression representing the set of subgoals in `self`.

Definition at line 9031 of file z3py.py.

9031 def sexpr(self):
9032 """Return a textual representation of the s-expression representing the set of subgoals in `self`."""
9033 return Z3_apply_result_to_string(self.ctx.ref(), self.result)
9034
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

ctx = ctx

Definition at line 8980 of file z3py.py.

◆ result

result = result

Definition at line 8979 of file z3py.py.