Inheritance diagram for Goal:Public Member Functions | |
| def | __init__ |
| def | __del__ |
| def | depth |
| def | inconsistent |
| def | prec |
| def | precision |
| def | size |
| def | __len__ |
| def | get |
| def | __getitem__ |
| def | assert_exprs |
| def | append |
| def | insert |
| def | add |
| def | __repr__ |
| def | sexpr |
| def | translate |
| def | simplify |
| def | as_expr |
Data Fields | |
| ctx | |
| goal | |
Goal is a collection of constraints we want to find a solution or show to be unsatisfiable (infeasible). Goals are processed using Tactics. A Tactic transforms a goal into a set of subgoals. A goal has a solution if one of its subgoals has a solution. A goal is unsatisfiable if all subgoals are unsatisfiable.
| def __init__ | ( | self, | |
models = True, |
|||
unsat_cores = False, |
|||
proofs = False, |
|||
ctx = None, |
|||
goal = None |
|||
| ) |
Definition at line 4604 of file z3py.py.
04604 04605 def __init__(self, models=True, unsat_cores=False, proofs=False, ctx=None, goal=None): 04606 if __debug__: 04607 _z3_assert(goal == None or ctx != None, "If goal is different from None, then ctx must be also different from None") 04608 self.ctx = _get_ctx(ctx) 04609 self.goal = goal 04610 if self.goal == None: 04611 self.goal = Z3_mk_goal(self.ctx.ref(), models, unsat_cores, proofs) 04612 Z3_goal_inc_ref(self.ctx.ref(), self.goal)
| def __del__ | ( | self | ) |
| def __getitem__ | ( | self, | |
| arg | |||
| ) |
Return a constraint in the goal `self`.
>>> g = Goal()
>>> x, y = Ints('x y')
>>> g.add(x == 0, y > x)
>>> g[0]
x == 0
>>> g[1]
y > x
Definition at line 4721 of file z3py.py.
04721 04722 def __getitem__(self, arg): 04723 """Return a constraint in the goal `self`. 04724 04725 >>> g = Goal() 04726 >>> x, y = Ints('x y') 04727 >>> g.add(x == 0, y > x) 04728 >>> g[0] 04729 x == 0 04730 >>> g[1] 04731 y > x 04732 """ 04733 if arg >= len(self): 04734 raise IndexError 04735 return self.get(arg)
| def __len__ | ( | self | ) |
Return the number of constraints in the goal `self`.
>>> g = Goal()
>>> len(g)
0
>>> x, y = Ints('x y')
>>> g.add(x == 0, y > x)
>>> len(g)
2
| def __repr__ | ( | self | ) |
| def add | ( | self, | |
| args | |||
| ) |
Add constraints.
>>> x = Int('x')
>>> g = Goal()
>>> g.add(x > 0, x < 2)
>>> g
[x > 0, x < 2]
Definition at line 4773 of file z3py.py.
04773 04774 def add(self, *args): 04775 """Add constraints. 04776 04777 >>> x = Int('x') 04778 >>> g = Goal() 04779 >>> g.add(x > 0, x < 2) 04780 >>> g 04781 [x > 0, x < 2] 04782 """ 04783 self.assert_exprs(*args)
| def append | ( | self, | |
| args | |||
| ) |
Add constraints.
>>> x = Int('x')
>>> g = Goal()
>>> g.append(x > 0, x < 2)
>>> g
[x > 0, x < 2]
Definition at line 4751 of file z3py.py.
04751 04752 def append(self, *args): 04753 """Add constraints. 04754 04755 >>> x = Int('x') 04756 >>> g = Goal() 04757 >>> g.append(x > 0, x < 2) 04758 >>> g 04759 [x > 0, x < 2] 04760 """ 04761 self.assert_exprs(*args)
| def as_expr | ( | self | ) |
Return goal `self` as a single Z3 expression.
>>> x = Int('x')
>>> g = Goal()
>>> g.as_expr()
True
>>> g.add(x > 1)
>>> g.as_expr()
x > 1
>>> g.add(x < 10)
>>> g.as_expr()
And(x > 1, x < 10)
Definition at line 4834 of file z3py.py.
04834 04835 def as_expr(self): 04836 """Return goal `self` as a single Z3 expression. 04837 04838 >>> x = Int('x') 04839 >>> g = Goal() 04840 >>> g.as_expr() 04841 True 04842 >>> g.add(x > 1) 04843 >>> g.as_expr() 04844 x > 1 04845 >>> g.add(x < 10) 04846 >>> g.as_expr() 04847 And(x > 1, x < 10) 04848 """ 04849 sz = len(self) 04850 if sz == 0: 04851 return BoolVal(True, self.ctx) 04852 elif sz == 1: 04853 return self.get(0) 04854 else: 04855 return And([ self.get(i) for i in range(len(self)) ])
| def assert_exprs | ( | self, | |
| args | |||
| ) |
Assert constraints into the goal.
>>> x = Int('x')
>>> g = Goal()
>>> g.assert_exprs(x > 0, x < 2)
>>> g
[x > 0, x < 2]
Definition at line 4736 of file z3py.py.
Referenced by Goal.add(), Fixedpoint.add(), Optimize.add(), Goal.append(), Fixedpoint.append(), and Fixedpoint.insert().
04736 04737 def assert_exprs(self, *args): 04738 """Assert constraints into the goal. 04739 04740 >>> x = Int('x') 04741 >>> g = Goal() 04742 >>> g.assert_exprs(x > 0, x < 2) 04743 >>> g 04744 [x > 0, x < 2] 04745 """ 04746 args = _get_args(args) 04747 s = BoolSort(self.ctx) 04748 for arg in args: 04749 arg = s.cast(arg) 04750 Z3_goal_assert(self.ctx.ref(), self.goal, arg.as_ast())
| def depth | ( | self | ) |
Return the depth of the goal `self`. The depth corresponds to the number of tactics applied to `self`.
>>> x, y = Ints('x y')
>>> g = Goal()
>>> g.add(x == 0, y >= x + 1)
>>> g.depth()
0
>>> r = Then('simplify', 'solve-eqs')(g)
>>> # r has 1 subgoal
>>> len(r)
1
>>> r[0].depth()
2
Definition at line 4617 of file z3py.py.
04617 04618 def depth(self): 04619 """Return the depth of the goal `self`. The depth corresponds to the number of tactics applied to `self`. 04620 04621 >>> x, y = Ints('x y') 04622 >>> g = Goal() 04623 >>> g.add(x == 0, y >= x + 1) 04624 >>> g.depth() 04625 0 04626 >>> r = Then('simplify', 'solve-eqs')(g) 04627 >>> # r has 1 subgoal 04628 >>> len(r) 04629 1 04630 >>> r[0].depth() 04631 2 04632 """ 04633 return int(Z3_goal_depth(self.ctx.ref(), self.goal))
| def get | ( | self, | |
| i | |||
| ) |
Return a constraint in the goal `self`.
>>> g = Goal()
>>> x, y = Ints('x y')
>>> g.add(x == 0, y > x)
>>> g.get(0)
x == 0
>>> g.get(1)
y > x
Definition at line 4708 of file z3py.py.
Referenced by Goal.__getitem__(), and Goal.as_expr().
04708 04709 def get(self, i): 04710 """Return a constraint in the goal `self`. 04711 04712 >>> g = Goal() 04713 >>> x, y = Ints('x y') 04714 >>> g.add(x == 0, y > x) 04715 >>> g.get(0) 04716 x == 0 04717 >>> g.get(1) 04718 y > x 04719 """ 04720 return _to_expr_ref(Z3_goal_formula(self.ctx.ref(), self.goal, i), self.ctx)
| def inconsistent | ( | self | ) |
Return `True` if `self` contains the `False` constraints.
>>> x, y = Ints('x y')
>>> g = Goal()
>>> g.inconsistent()
False
>>> g.add(x == 0, x == 1)
>>> g
[x == 0, x == 1]
>>> g.inconsistent()
False
>>> g2 = Tactic('propagate-values')(g)[0]
>>> g2.inconsistent()
True
Definition at line 4634 of file z3py.py.
04634 04635 def inconsistent(self): 04636 """Return `True` if `self` contains the `False` constraints. 04637 04638 >>> x, y = Ints('x y') 04639 >>> g = Goal() 04640 >>> g.inconsistent() 04641 False 04642 >>> g.add(x == 0, x == 1) 04643 >>> g 04644 [x == 0, x == 1] 04645 >>> g.inconsistent() 04646 False 04647 >>> g2 = Tactic('propagate-values')(g)[0] 04648 >>> g2.inconsistent() 04649 True 04650 """ 04651 return Z3_goal_inconsistent(self.ctx.ref(), self.goal)
| def insert | ( | self, | |
| args | |||
| ) |
Add constraints.
>>> x = Int('x')
>>> g = Goal()
>>> g.insert(x > 0, x < 2)
>>> g
[x > 0, x < 2]
Definition at line 4762 of file z3py.py.
04762 04763 def insert(self, *args): 04764 """Add constraints. 04765 04766 >>> x = Int('x') 04767 >>> g = Goal() 04768 >>> g.insert(x > 0, x < 2) 04769 >>> g 04770 [x > 0, x < 2] 04771 """ 04772 self.assert_exprs(*args)
| def prec | ( | self | ) |
Return the precision (under-approximation, over-approximation, or precise) of the goal `self`.
>>> g = Goal()
>>> g.prec() == Z3_GOAL_PRECISE
True
>>> x, y = Ints('x y')
>>> g.add(x == y + 1)
>>> g.prec() == Z3_GOAL_PRECISE
True
>>> t = With(Tactic('add-bounds'), add_bound_lower=0, add_bound_upper=10)
>>> g2 = t(g)[0]
>>> g2
[x == y + 1, x <= 10, x >= 0, y <= 10, y >= 0]
>>> g2.prec() == Z3_GOAL_PRECISE
False
>>> g2.prec() == Z3_GOAL_UNDER
True
Definition at line 4652 of file z3py.py.
Referenced by Goal.precision().
04652 04653 def prec(self): 04654 """Return the precision (under-approximation, over-approximation, or precise) of the goal `self`. 04655 04656 >>> g = Goal() 04657 >>> g.prec() == Z3_GOAL_PRECISE 04658 True 04659 >>> x, y = Ints('x y') 04660 >>> g.add(x == y + 1) 04661 >>> g.prec() == Z3_GOAL_PRECISE 04662 True 04663 >>> t = With(Tactic('add-bounds'), add_bound_lower=0, add_bound_upper=10) 04664 >>> g2 = t(g)[0] 04665 >>> g2 04666 [x == y + 1, x <= 10, x >= 0, y <= 10, y >= 0] 04667 >>> g2.prec() == Z3_GOAL_PRECISE 04668 False 04669 >>> g2.prec() == Z3_GOAL_UNDER 04670 True 04671 """ 04672 return Z3_goal_precision(self.ctx.ref(), self.goal)
| def precision | ( | self | ) |
| def sexpr | ( | self | ) |
Return a textual representation of the s-expression representing the goal.
Definition at line 4787 of file z3py.py.
Referenced by Fixedpoint.__repr__(), and Optimize.__repr__().
04787 04788 def sexpr(self): 04789 """Return a textual representation of the s-expression representing the goal.""" 04790 return Z3_goal_to_string(self.ctx.ref(), self.goal)
| def simplify | ( | self, | |
| arguments, | |||
| keywords | |||
| ) |
Return a new simplified goal.
This method is essentially invoking the simplify tactic.
>>> g = Goal()
>>> x = Int('x')
>>> g.add(x + 1 >= 2)
>>> g
[x + 1 >= 2]
>>> g2 = g.simplify()
>>> g2
[x >= 1]
>>> # g was not modified
>>> g
[x + 1 >= 2]
Definition at line 4814 of file z3py.py.
04814 04815 def simplify(self, *arguments, **keywords): 04816 """Return a new simplified goal. 04817 04818 This method is essentially invoking the simplify tactic. 04819 04820 >>> g = Goal() 04821 >>> x = Int('x') 04822 >>> g.add(x + 1 >= 2) 04823 >>> g 04824 [x + 1 >= 2] 04825 >>> g2 = g.simplify() 04826 >>> g2 04827 [x >= 1] 04828 >>> # g was not modified 04829 >>> g 04830 [x + 1 >= 2] 04831 """ 04832 t = Tactic('simplify') 04833 return t.apply(self, *arguments, **keywords)[0]
| def size | ( | self | ) |
Return the number of constraints in the goal `self`.
>>> g = Goal()
>>> g.size()
0
>>> x, y = Ints('x y')
>>> g.add(x == 0, y > x)
>>> g.size()
2
Definition at line 4682 of file z3py.py.
Referenced by Goal.__len__(), and BitVecNumRef.as_signed_long().
04682 04683 def size(self): 04684 """Return the number of constraints in the goal `self`. 04685 04686 >>> g = Goal() 04687 >>> g.size() 04688 0 04689 >>> x, y = Ints('x y') 04690 >>> g.add(x == 0, y > x) 04691 >>> g.size() 04692 2 04693 """ 04694 return int(Z3_goal_size(self.ctx.ref(), self.goal))
| def translate | ( | self, | |
| target | |||
| ) |
Copy goal `self` to context `target`.
>>> x = Int('x')
>>> g = Goal()
>>> g.add(x > 10)
>>> g
[x > 10]
>>> c2 = Context()
>>> g2 = g.translate(c2)
>>> g2
[x > 10]
>>> g.ctx == main_ctx()
True
>>> g2.ctx == c2
True
>>> g2.ctx == main_ctx()
False
Definition at line 4791 of file z3py.py.
04791 04792 def translate(self, target): 04793 """Copy goal `self` to context `target`. 04794 04795 >>> x = Int('x') 04796 >>> g = Goal() 04797 >>> g.add(x > 10) 04798 >>> g 04799 [x > 10] 04800 >>> c2 = Context() 04801 >>> g2 = g.translate(c2) 04802 >>> g2 04803 [x > 10] 04804 >>> g.ctx == main_ctx() 04805 True 04806 >>> g2.ctx == c2 04807 True 04808 >>> g2.ctx == main_ctx() 04809 False 04810 """ 04811 if __debug__: 04812 _z3_assert(isinstance(target, Context), "target must be a context") 04813 return Goal(goal=Z3_goal_translate(self.ctx.ref(), self.goal, target.ref()), ctx=target)
Definition at line 4604 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(), Fixedpoint::add_rule(), Optimize::add_soft(), Tactic::apply(), AlgebraicNumRef::approx(), ExprRef::arg(), Goal::as_expr(), ApplyResult::as_expr(), Goal::assert_exprs(), Fixedpoint::assert_exprs(), QuantifierRef::body(), BoolSortRef::cast(), DatatypeSortRef::constructor(), ApplyResult::convert_model(), ExprRef::decl(), RatNumRef::denominator(), FuncDeclRef::domain(), ArraySortRef::domain(), Goal::get(), Fixedpoint::get_answer(), Fixedpoint::get_assertions(), Fixedpoint::get_cover_delta(), Fixedpoint::get_rules(), SortRef::kind(), ArrayRef::mk_default(), Optimize::model(), SortRef::name(), FuncDeclRef::name(), QuantifierRef::no_pattern(), RatNumRef::numerator(), Fixedpoint::param_descrs(), Optimize::param_descrs(), Tactic::param_descrs(), Fixedpoint::parse_file(), Fixedpoint::parse_string(), QuantifierRef::pattern(), Fixedpoint::query(), FuncDeclRef::range(), ArraySortRef::range(), DatatypeSortRef::recognizer(), Fixedpoint::set(), Optimize::set(), Tactic::solver(), ExprRef::sort(), BoolRef::sort(), QuantifierRef::sort(), ArithRef::sort(), BitVecRef::sort(), ArrayRef::sort(), DatatypeRef::sort(), Fixedpoint::statistics(), Optimize::statistics(), Solver::to_smt2(), Fixedpoint::update_rule(), QuantifierRef::var_name(), and QuantifierRef::var_sort().
Definition at line 4604 of file z3py.py.
Referenced by Goal.__del__(), Goal.assert_exprs(), Goal.depth(), Goal.get(), Goal.inconsistent(), Goal.prec(), Goal.sexpr(), Goal.size(), and Goal.translate().
1.7.6.1