Z3
 
Loading...
Searching...
No Matches
Tactic Class Reference

Public Member Functions

 __init__ (self, tactic, ctx=None)
 
 __deepcopy__ (self, memo={})
 
 __del__ (self)
 
 solver (self, logFile=None)
 
 apply (self, goal, *arguments, **keywords)
 
 __call__ (self, goal, *arguments, **keywords)
 
 help (self)
 
 param_descrs (self)
 

Data Fields

 ctx = _get_ctx(ctx)
 
 tactic = None
 

Detailed Description

Tactics transform, solver and/or simplify sets of constraints (Goal).
A Tactic can be converted into a Solver using the method solver().

Several combinators are available for creating new tactics using the built-in ones:
Then(), OrElse(), FailIf(), Repeat(), When(), Cond().

Definition at line 8316 of file z3py.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
tactic,
ctx = None )

Definition at line 8324 of file z3py.py.

8324 def __init__(self, tactic, ctx=None):
8325 self.ctx = _get_ctx(ctx)
8326 self.tactic = None
8327 if isinstance(tactic, TacticObj):
8328 self.tactic = tactic
8329 else:
8330 if z3_debug():
8331 _z3_assert(isinstance(tactic, str), "tactic name expected")
8332 try:
8333 self.tactic = Z3_mk_tactic(self.ctx.ref(), str(tactic))
8334 except Z3Exception:
8335 raise Z3Exception("unknown tactic '%s'" % tactic)
8336 Z3_tactic_inc_ref(self.ctx.ref(), self.tactic)
8337
Z3_tactic Z3_API Z3_mk_tactic(Z3_context c, Z3_string name)
Return a tactic associated with the given name. The complete list of tactics may be obtained using th...
void Z3_API Z3_tactic_inc_ref(Z3_context c, Z3_tactic t)
Increment the reference counter of the given tactic.

◆ __del__()

__del__ ( self)

Definition at line 8341 of file z3py.py.

8341 def __del__(self):
8342 if self.tactic is not None and self.ctx.ref() is not None and Z3_tactic_dec_ref is not None:
8343 Z3_tactic_dec_ref(self.ctx.ref(), self.tactic)
8344
void Z3_API Z3_tactic_dec_ref(Z3_context c, Z3_tactic g)
Decrement the reference counter of the given tactic.

Member Function Documentation

◆ __call__()

__call__ ( self,
goal,
* arguments,
** keywords )
Apply tactic `self` to the given goal or Z3 Boolean expression using the given options.

>>> x, y = Ints('x y')
>>> t = Tactic('solve-eqs')
>>> t(And(x == 0, y >= x + 1))
[[y >= 1]]

Definition at line 8379 of file z3py.py.

8379 def __call__(self, goal, *arguments, **keywords):
8380 """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options.
8381
8382 >>> x, y = Ints('x y')
8383 >>> t = Tactic('solve-eqs')
8384 >>> t(And(x == 0, y >= x + 1))
8385 [[y >= 1]]
8386 """
8387 return self.apply(goal, *arguments, **keywords)
8388

◆ __deepcopy__()

__deepcopy__ ( self,
memo = {} )

Definition at line 8338 of file z3py.py.

8338 def __deepcopy__(self, memo={}):
8339 return Tactic(self.tactic, self.ctx)
8340

◆ apply()

apply ( self,
goal,
* arguments,
** keywords )
Apply tactic `self` to the given goal or Z3 Boolean expression using the given options.

>>> x, y = Ints('x y')
>>> t = Tactic('solve-eqs')
>>> t.apply(And(x == 0, y >= x + 1))
[[y >= 1]]

Definition at line 8362 of file z3py.py.

8362 def apply(self, goal, *arguments, **keywords):
8363 """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options.
8364
8365 >>> x, y = Ints('x y')
8366 >>> t = Tactic('solve-eqs')
8367 >>> t.apply(And(x == 0, y >= x + 1))
8368 [[y >= 1]]
8369 """
8370 if z3_debug():
8371 _z3_assert(isinstance(goal, (Goal, BoolRef)), "Z3 Goal or Boolean expressions expected")
8372 goal = _to_goal(goal)
8373 if len(arguments) > 0 or len(keywords) > 0:
8374 p = args2params(arguments, keywords, self.ctx)
8375 return ApplyResult(Z3_tactic_apply_ex(self.ctx.ref(), self.tactic, goal.goal, p.params), self.ctx)
8376 else:
8377 return ApplyResult(Z3_tactic_apply(self.ctx.ref(), self.tactic, goal.goal), self.ctx)
8378
Z3_apply_result Z3_API Z3_tactic_apply_ex(Z3_context c, Z3_tactic t, Z3_goal g, Z3_params p)
Apply tactic t to the goal g using the parameter set p.
Z3_apply_result Z3_API Z3_tactic_apply(Z3_context c, Z3_tactic t, Z3_goal g)
Apply tactic t to the goal g.

◆ help()

help ( self)
Display a string containing a description of the available options for the `self` tactic.

Definition at line 8389 of file z3py.py.

8389 def help(self):
8390 """Display a string containing a description of the available options for the `self` tactic."""
8391 print(Z3_tactic_get_help(self.ctx.ref(), self.tactic))
8392
Z3_string Z3_API Z3_tactic_get_help(Z3_context c, Z3_tactic t)
Return a string containing a description of parameters accepted by the given tactic.

◆ param_descrs()

param_descrs ( self)
Return the parameter description set.

Definition at line 8393 of file z3py.py.

8393 def param_descrs(self):
8394 """Return the parameter description set."""
8395 return ParamDescrsRef(Z3_tactic_get_param_descrs(self.ctx.ref(), self.tactic), self.ctx)
8396
8397
Z3_param_descrs Z3_API Z3_tactic_get_param_descrs(Z3_context c, Z3_tactic t)
Return the parameter description set for the given tactic object.

◆ solver()

solver ( self,
logFile = None )
Create a solver using the tactic `self`.

The solver supports the methods `push()` and `pop()`, but it
will always solve each `check()` from scratch.

>>> t = Then('simplify', 'nlsat')
>>> s = t.solver()
>>> x = Real('x')
>>> s.add(x**2 == 2, x > 0)
>>> s.check()
sat
>>> s.model()
[x = 1.4142135623?]

Definition at line 8345 of file z3py.py.

8345 def solver(self, logFile=None):
8346 """Create a solver using the tactic `self`.
8347
8348 The solver supports the methods `push()` and `pop()`, but it
8349 will always solve each `check()` from scratch.
8350
8351 >>> t = Then('simplify', 'nlsat')
8352 >>> s = t.solver()
8353 >>> x = Real('x')
8354 >>> s.add(x**2 == 2, x > 0)
8355 >>> s.check()
8356 sat
8357 >>> s.model()
8358 [x = 1.4142135623?]
8359 """
8360 return Solver(Z3_mk_solver_from_tactic(self.ctx.ref(), self.tactic), self.ctx, logFile)
8361
Z3_solver Z3_API Z3_mk_solver_from_tactic(Z3_context c, Z3_tactic t)
Create a new solver that is implemented using the given tactic. The solver supports the commands Z3_s...

Referenced by Solver.__del__(), Solver.assert_and_track(), Solver.assert_exprs(), Solver.check(), Solver.model(), Solver.num_scopes(), Solver.pop(), Solver.push(), Solver.reset(), and Solver.set().

Field Documentation

◆ ctx

ctx = _get_ctx(ctx)

Definition at line 8325 of file z3py.py.

Referenced by ArithRef.__add__(), BitVecRef.__add__(), BitVecRef.__and__(), FuncDeclRef.__call__(), AstMap.__contains__(), AstRef.__copy__(), AstVector.__copy__(), FuncInterp.__copy__(), Goal.__copy__(), ModelRef.__copy__(), AstMap.__deepcopy__(), AstRef.__deepcopy__(), AstVector.__deepcopy__(), Datatype.__deepcopy__(), FuncEntry.__deepcopy__(), FuncInterp.__deepcopy__(), Goal.__deepcopy__(), ModelRef.__deepcopy__(), ParamDescrsRef.__deepcopy__(), ParamsRef.__deepcopy__(), Statistics.__deepcopy__(), AstMap.__del__(), AstRef.__del__(), AstVector.__del__(), Context.__del__(), FuncEntry.__del__(), FuncInterp.__del__(), Goal.__del__(), ModelRef.__del__(), ParamDescrsRef.__del__(), ParamsRef.__del__(), ScopedConstructor.__del__(), ScopedConstructorList.__del__(), Solver.__del__(), Statistics.__del__(), ArithRef.__div__(), BitVecRef.__div__(), ExprRef.__eq__(), ArithRef.__ge__(), BitVecRef.__ge__(), AstMap.__getitem__(), AstVector.__getitem__(), ModelRef.__getitem__(), Statistics.__getitem__(), ArithRef.__gt__(), BitVecRef.__gt__(), BitVecRef.__invert__(), ArithRef.__le__(), BitVecRef.__le__(), AstMap.__len__(), AstVector.__len__(), ModelRef.__len__(), Statistics.__len__(), BitVecRef.__lshift__(), ArithRef.__lt__(), BitVecRef.__lt__(), ArithRef.__mod__(), BitVecRef.__mod__(), ArithRef.__mul__(), BitVecRef.__mul__(), BoolRef.__mul__(), ExprRef.__ne__(), ArithRef.__neg__(), BitVecRef.__neg__(), BitVecRef.__or__(), ArithRef.__pow__(), ArithRef.__radd__(), BitVecRef.__radd__(), BitVecRef.__rand__(), ArithRef.__rdiv__(), BitVecRef.__rdiv__(), AstMap.__repr__(), ParamDescrsRef.__repr__(), ParamsRef.__repr__(), Statistics.__repr__(), BitVecRef.__rlshift__(), ArithRef.__rmod__(), BitVecRef.__rmod__(), ArithRef.__rmul__(), BitVecRef.__rmul__(), BitVecRef.__ror__(), ArithRef.__rpow__(), BitVecRef.__rrshift__(), BitVecRef.__rshift__(), ArithRef.__rsub__(), BitVecRef.__rsub__(), BitVecRef.__rxor__(), AstMap.__setitem__(), AstVector.__setitem__(), ArithRef.__sub__(), BitVecRef.__sub__(), BitVecRef.__xor__(), DatatypeSortRef.accessor(), ExprRef.arg(), FuncEntry.arg_value(), FuncInterp.arity(), Goal.as_expr(), Solver.assert_and_track(), Goal.assert_exprs(), Solver.assert_exprs(), QuantifierRef.body(), Solver.check(), Goal.convert_model(), AstRef.ctx_ref(), ExprRef.decl(), ModelRef.decls(), ArrayRef.default(), RatNumRef.denominator(), Goal.depth(), Goal.dimacs(), FuncDeclRef.domain(), ArraySortRef.domain_n(), FuncInterp.else_value(), FuncInterp.entry(), AstMap.erase(), ModelRef.eval(), Goal.get(), ParamDescrsRef.get_documentation(), ModelRef.get_interp(), Statistics.get_key_value(), ParamDescrsRef.get_kind(), ParamDescrsRef.get_name(), ModelRef.get_sort(), ModelRef.get_universe(), Goal.inconsistent(), AstMap.keys(), Statistics.keys(), Solver.model(), SortRef.name(), QuantifierRef.no_pattern(), FuncEntry.num_args(), FuncInterp.num_entries(), Solver.num_scopes(), ModelRef.num_sorts(), FuncDeclRef.params(), QuantifierRef.pattern(), AlgebraicNumRef.poly(), Solver.pop(), Goal.prec(), AstVector.push(), Solver.push(), QuantifierRef.qid(), ArraySortRef.range(), FuncDeclRef.range(), DatatypeSortRef.recognizer(), Context.ref(), AstMap.reset(), Solver.reset(), AstVector.resize(), ParamsRef.set(), Solver.set(), AstVector.sexpr(), Goal.sexpr(), ModelRef.sexpr(), Goal.size(), ParamDescrsRef.size(), QuantifierRef.skolem_id(), AstRef.translate(), AstVector.translate(), Goal.translate(), ModelRef.translate(), ParamsRef.validate(), FuncEntry.value(), QuantifierRef.var_name(), and QuantifierRef.var_sort().

◆ tactic

tactic = None

Definition at line 8326 of file z3py.py.