|
def | __init__ (self, models=True, unsat_cores=False, proofs=False, ctx=None, goal=None) |
|
def | __deepcopy__ (self, memo={}) |
|
def | __del__ (self) |
|
def | depth (self) |
|
def | inconsistent (self) |
|
def | prec (self) |
|
def | precision (self) |
|
def | size (self) |
|
def | __len__ (self) |
|
def | get (self, i) |
|
def | __getitem__ (self, arg) |
|
def | assert_exprs (self, *args) |
|
def | append (self, *args) |
|
def | insert (self, *args) |
|
def | add (self, *args) |
|
def | convert_model (self, model) |
|
def | __repr__ (self) |
|
def | sexpr (self) |
|
def | dimacs (self, include_names=True) |
|
def | translate (self, target) |
|
def | __copy__ (self) |
|
def | __deepcopy__ (self, memo={}) |
|
def | simplify (self, *arguments, **keywords) |
|
def | as_expr (self) |
|
def | use_pp (self) |
|
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.
Definition at line 5189 of file z3py.py.
◆ __init__()
def __init__ |
( |
|
self, |
|
|
|
models = True , |
|
|
|
unsat_cores = False , |
|
|
|
proofs = False , |
|
|
|
ctx = None , |
|
|
|
goal = None |
|
) |
| |
Definition at line 5197 of file z3py.py.
5197 def __init__(self, models=True, unsat_cores=False, proofs=False, ctx=None, goal=None):
5199 _z3_assert(goal
is None or ctx
is not None,
"If goal is different from None, then ctx must be also different from None")
5200 self.ctx = _get_ctx(ctx)
5202 if self.goal
is None:
5203 self.goal =
Z3_mk_goal(self.ctx.ref(), models, unsat_cores, proofs)
◆ __del__()
Definition at line 5209 of file z3py.py.
5210 if self.goal
is not None and self.ctx.ref()
is not None:
◆ __copy__()
Definition at line 5443 of file z3py.py.
5444 return self.translate(self.ctx)
◆ __deepcopy__() [1/2]
def __deepcopy__ |
( |
|
self, |
|
|
|
memo = {} |
|
) |
| |
Definition at line 5206 of file z3py.py.
5206 def __deepcopy__(self, memo={}):
5207 return Goal(
False,
False,
False, self.ctx, self.goal)
Referenced by Goal.__deepcopy__().
◆ __deepcopy__() [2/2]
def __deepcopy__ |
( |
|
self, |
|
|
|
memo = {} |
|
) |
| |
Definition at line 5446 of file z3py.py.
5446 def __deepcopy__(self, memo={}):
5447 return self.translate(self.ctx)
◆ __getitem__()
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 5317 of file z3py.py.
5317 def __getitem__(self, arg):
5318 """Return a constraint in the goal `self`.
5321 >>> x, y = Ints('x y')
5322 >>> g.add(x == 0, y > x)
5328 if arg >= len(self):
5330 return self.get(arg)
◆ __len__()
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
Definition at line 5291 of file z3py.py.
5292 """Return the number of constraints in the goal `self`.
5297 >>> x, y = Ints('x y')
5298 >>> g.add(x == 0, y > x)
Referenced by AstVector.__getitem__(), and AstVector.__setitem__().
◆ __repr__()
Definition at line 5409 of file z3py.py.
5410 return obj_to_string(self)
◆ add()
◆ append()
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 5347 of file z3py.py.
5347 def append(self, *args):
5352 >>> g.append(x > 0, x < 2)
5356 self.assert_exprs(*args)
◆ as_expr()
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 5469 of file z3py.py.
5470 """Return goal `self` as a single Z3 expression.
5485 return BoolVal(
True, self.ctx)
5489 return And([ self.get(i)
for i
in range(len(self)) ], self.ctx)
◆ assert_exprs()
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 5332 of file z3py.py.
5332 def assert_exprs(self, *args):
5333 """Assert constraints into the goal.
5337 >>> g.assert_exprs(x > 0, x < 2)
5341 args = _get_args(args)
Referenced by Goal.add(), Solver.add(), Fixedpoint.add(), Optimize.add(), Goal.append(), Solver.append(), Fixedpoint.append(), Goal.insert(), Solver.insert(), and Fixedpoint.insert().
◆ convert_model()
def convert_model |
( |
|
self, |
|
|
|
model |
|
) |
| |
Retrieve model from a satisfiable 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[1].convert_model(s.model())
[b = 0, a = 1]
Definition at line 5380 of file z3py.py.
5380 def convert_model(self, model):
5381 """Retrieve model from a satisfiable goal
5382 >>> a, b = Ints('a b')
5384 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
5385 >>> t = Then(Tactic('split-clause'), Tactic('solve-eqs'))
5388 [Or(b == 0, b == 1), Not(0 <= b)]
5390 [Or(b == 0, b == 1), Not(1 <= b)]
5391 >>> # Remark: the subgoal r[0] is unsatisfiable
5392 >>> # Creating a solver for solving the second subgoal
5399 >>> # Model s.model() does not assign a value to `a`
5400 >>> # It is a model for subgoal `r[1]`, but not for goal `g`
5401 >>> # The method convert_model creates a model for `g` from a model for `r[1]`.
5402 >>> r[1].convert_model(s.model())
5406 _z3_assert(isinstance(model, ModelRef),
"Z3 Model expected")
◆ depth()
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 5213 of file z3py.py.
5214 """Return the depth of the goal `self`. The depth corresponds to the number of tactics applied to `self`.
5216 >>> x, y = Ints('x y')
5218 >>> g.add(x == 0, y >= x + 1)
5221 >>> r = Then('simplify', 'solve-eqs')(g)
5222 >>> # r has 1 subgoal
◆ dimacs()
def dimacs |
( |
|
self, |
|
|
|
include_names = True |
|
) |
| |
Return a textual representation of the goal in DIMACS format.
Definition at line 5416 of file z3py.py.
5416 def dimacs(self, include_names = True):
5417 """Return a textual representation of the goal in DIMACS format."""
◆ get()
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 5304 of file z3py.py.
5305 """Return a constraint in the goal `self`.
5308 >>> x, y = Ints('x y')
5309 >>> g.add(x == 0, y > x)
5315 return _to_expr_ref(
Z3_goal_formula(self.ctx.ref(), self.goal, i), self.ctx)
Referenced by Goal.__getitem__(), and Goal.as_expr().
◆ inconsistent()
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 5230 of file z3py.py.
5230 def inconsistent(self):
5231 """Return `True` if `self` contains the `False` constraints.
5233 >>> x, y = Ints('x y')
5235 >>> g.inconsistent()
5237 >>> g.add(x == 0, x == 1)
5240 >>> g.inconsistent()
5242 >>> g2 = Tactic('propagate-values')(g)[0]
5243 >>> g2.inconsistent()
◆ insert()
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 5358 of file z3py.py.
5358 def insert(self, *args):
5363 >>> g.insert(x > 0, x < 2)
5367 self.assert_exprs(*args)
◆ prec()
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 5248 of file z3py.py.
5249 """Return the precision (under-approximation, over-approximation, or precise) of the goal `self`.
5252 >>> g.prec() == Z3_GOAL_PRECISE
5254 >>> x, y = Ints('x y')
5255 >>> g.add(x == y + 1)
5256 >>> g.prec() == Z3_GOAL_PRECISE
5258 >>> t = With(Tactic('add-bounds'), add_bound_lower=0, add_bound_upper=10)
5261 [x == y + 1, x <= 10, x >= 0, y <= 10, y >= 0]
5262 >>> g2.prec() == Z3_GOAL_PRECISE
5264 >>> g2.prec() == Z3_GOAL_UNDER
Referenced by Goal.precision().
◆ precision()
Alias for `prec()`.
>>> g = Goal()
>>> g.precision() == Z3_GOAL_PRECISE
True
Definition at line 5269 of file z3py.py.
5269 def precision(self):
5270 """Alias for `prec()`.
5273 >>> g.precision() == Z3_GOAL_PRECISE
◆ sexpr()
Return a textual representation of the s-expression representing the goal.
Definition at line 5412 of file z3py.py.
5413 """Return a textual representation of the s-expression representing the goal."""
Referenced by Fixedpoint.__repr__(), and Optimize.__repr__().
◆ simplify()
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 5449 of file z3py.py.
5449 def simplify(self, *arguments, **keywords):
5450 """Return a new simplified goal.
5452 This method is essentially invoking the simplify tactic.
5456 >>> g.add(x + 1 >= 2)
5459 >>> g2 = g.simplify()
5462 >>> # g was not modified
5466 t = Tactic(
'simplify')
5467 return t.apply(self, *arguments, **keywords)[0]
◆ size()
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 5278 of file z3py.py.
5279 """Return the number of constraints in the goal `self`.
5284 >>> x, y = Ints('x y')
5285 >>> g.add(x == 0, y > x)
Referenced by Goal.__len__().
◆ translate()
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 5420 of file z3py.py.
5420 def translate(self, target):
5421 """Copy goal `self` to context `target`.
5429 >>> g2 = g.translate(c2)
5432 >>> g.ctx == main_ctx()
5436 >>> g2.ctx == main_ctx()
5440 _z3_assert(isinstance(target, Context),
"target must be a context")
5441 return Goal(goal=
Z3_goal_translate(self.ctx.ref(), self.goal, target.ref()), ctx=target)
Referenced by Goal.__copy__(), AstVector.__copy__(), FuncInterp.__copy__(), ModelRef.__copy__(), Solver.__copy__(), Goal.__deepcopy__(), AstVector.__deepcopy__(), FuncInterp.__deepcopy__(), ModelRef.__deepcopy__(), and Solver.__deepcopy__().
◆ ctx
Definition at line 5200 of file z3py.py.
Referenced by Probe.__call__(), AstMap.__contains__(), Goal.__copy__(), AstVector.__copy__(), FuncInterp.__copy__(), ModelRef.__copy__(), Solver.__copy__(), Goal.__deepcopy__(), AstVector.__deepcopy__(), AstMap.__deepcopy__(), FuncEntry.__deepcopy__(), FuncInterp.__deepcopy__(), ModelRef.__deepcopy__(), Statistics.__deepcopy__(), Solver.__deepcopy__(), Fixedpoint.__deepcopy__(), Optimize.__deepcopy__(), ApplyResult.__deepcopy__(), Tactic.__deepcopy__(), Probe.__deepcopy__(), Goal.__del__(), AstVector.__del__(), AstMap.__del__(), FuncEntry.__del__(), FuncInterp.__del__(), ModelRef.__del__(), Statistics.__del__(), Solver.__del__(), Fixedpoint.__del__(), Optimize.__del__(), ApplyResult.__del__(), Tactic.__del__(), Probe.__del__(), Probe.__eq__(), Probe.__ge__(), AstVector.__getitem__(), AstMap.__getitem__(), ModelRef.__getitem__(), Statistics.__getitem__(), ApplyResult.__getitem__(), Probe.__gt__(), Probe.__le__(), AstVector.__len__(), AstMap.__len__(), ModelRef.__len__(), Statistics.__len__(), ApplyResult.__len__(), Probe.__lt__(), Probe.__ne__(), AstMap.__repr__(), Statistics.__repr__(), AstVector.__setitem__(), AstMap.__setitem__(), Fixedpoint.add_cover(), Fixedpoint.add_rule(), Optimize.add_soft(), Tactic.apply(), FuncEntry.arg_value(), FuncInterp.arity(), Goal.as_expr(), ApplyResult.as_expr(), Solver.assert_and_track(), Optimize.assert_and_track(), Goal.assert_exprs(), Solver.assert_exprs(), Fixedpoint.assert_exprs(), Optimize.assert_exprs(), Solver.assertions(), Optimize.assertions(), Solver.check(), Optimize.check(), UserPropagateBase.conflict(), Solver.consequences(), Goal.convert_model(), UserPropagateBase.ctx_ref(), ModelRef.decls(), Goal.depth(), Goal.dimacs(), Solver.dimacs(), FuncInterp.else_value(), FuncInterp.entry(), AstMap.erase(), ModelRef.eval(), Solver.from_file(), Optimize.from_file(), Solver.from_string(), Optimize.from_string(), Goal.get(), Fixedpoint.get_answer(), Fixedpoint.get_assertions(), Fixedpoint.get_cover_delta(), Fixedpoint.get_ground_sat_answer(), ModelRef.get_interp(), Statistics.get_key_value(), Fixedpoint.get_num_levels(), Fixedpoint.get_rule_names_along_trace(), Fixedpoint.get_rules(), Fixedpoint.get_rules_along_trace(), ModelRef.get_sort(), ModelRef.get_universe(), Solver.help(), Fixedpoint.help(), Optimize.help(), Tactic.help(), Solver.import_model_converter(), Goal.inconsistent(), AstMap.keys(), Statistics.keys(), Optimize.maximize(), Optimize.minimize(), Solver.model(), Optimize.model(), Solver.non_units(), FuncEntry.num_args(), FuncInterp.num_entries(), Solver.num_scopes(), ModelRef.num_sorts(), Optimize.objectives(), Solver.param_descrs(), Fixedpoint.param_descrs(), Optimize.param_descrs(), Tactic.param_descrs(), Fixedpoint.parse_file(), Fixedpoint.parse_string(), Solver.pop(), Optimize.pop(), Goal.prec(), Solver.proof(), AstVector.push(), Solver.push(), Optimize.push(), Fixedpoint.query(), Fixedpoint.query_from_lvl(), Solver.reason_unknown(), Fixedpoint.reason_unknown(), Optimize.reason_unknown(), Fixedpoint.register_relation(), AstMap.reset(), Solver.reset(), AstVector.resize(), Solver.set(), Fixedpoint.set(), Optimize.set(), Fixedpoint.set_predicate_representation(), Goal.sexpr(), AstVector.sexpr(), ModelRef.sexpr(), Solver.sexpr(), Fixedpoint.sexpr(), Optimize.sexpr(), ApplyResult.sexpr(), Goal.size(), Tactic.solver(), Solver.statistics(), Fixedpoint.statistics(), Optimize.statistics(), Solver.to_smt2(), Fixedpoint.to_string(), Solver.trail(), Solver.trail_levels(), Goal.translate(), AstVector.translate(), FuncInterp.translate(), ModelRef.translate(), Solver.translate(), Solver.units(), Solver.unsat_core(), Optimize.unsat_core(), Fixedpoint.update_rule(), and FuncEntry.value().
◆ goal
Definition at line 5201 of file z3py.py.
Referenced by Goal.__deepcopy__(), Goal.__del__(), Goal.assert_exprs(), Goal.convert_model(), Goal.depth(), Goal.dimacs(), Goal.get(), Goal.inconsistent(), Goal.prec(), Goal.sexpr(), Goal.size(), and Goal.translate().
def __init__(self, s, ctx=None)
expr range(expr const &lo, expr const &hi)
Z3_goal_prec Z3_API Z3_goal_precision(Z3_context c, Z3_goal g)
Return the "precision" of the given goal. Goals can be transformed using over and under approximation...
unsigned Z3_API Z3_goal_size(Z3_context c, Z3_goal g)
Return the number of formulas in the given goal.
Z3_goal Z3_API Z3_mk_goal(Z3_context c, bool models, bool unsat_cores, bool proofs)
Create a goal (aka problem). A goal is essentially a set of formulas, that can be solved and/or trans...
def simplify(a, *arguments, **keywords)
Utils.
Z3_ast Z3_API Z3_goal_formula(Z3_context c, Z3_goal g, unsigned idx)
Return a formula from the given goal.
unsigned Z3_API Z3_goal_depth(Z3_context c, Z3_goal g)
Return the depth of the given goal. It tracks how many transformations were applied to it.
void Z3_API Z3_goal_dec_ref(Z3_context c, Z3_goal g)
Decrement the reference counter of the given goal.
Z3_goal Z3_API Z3_goal_translate(Z3_context source, Z3_goal g, Z3_context target)
Copy a goal g from the context source to the context target.
Z3_string Z3_API Z3_goal_to_string(Z3_context c, Z3_goal g)
Convert a goal into a string.
void Z3_API Z3_goal_inc_ref(Z3_context c, Z3_goal g)
Increment the reference counter of the given goal.
Z3_string Z3_API Z3_goal_to_dimacs_string(Z3_context c, Z3_goal g, bool include_names)
Convert a goal into a DIMACS formatted string. The goal must be in CNF. You can convert a goal to CNF...
void Z3_API Z3_goal_assert(Z3_context c, Z3_goal g, Z3_ast a)
Add a new formula a to the given goal. The formula is split according to the following procedure that...
def BoolVal(val, ctx=None)
Z3_model Z3_API Z3_goal_convert_model(Z3_context c, Z3_goal g, Z3_model m)
Convert a model of the formulas of a goal to a model of an original goal. The model may be null,...
bool Z3_API Z3_goal_inconsistent(Z3_context c, Z3_goal g)
Return true if the given goal contains the formula false.