Z3
Public Member Functions | Data Fields
Tactic Class Reference

Public Member Functions

def __init__
 
def __del__ (self)
 
def solver (self)
 
def apply (self, goal, arguments, keywords)
 
def __call__ (self, goal, arguments, keywords)
 
def help (self)
 
def param_descrs (self)
 

Data Fields

 ctx
 
 tactic
 

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

Constructor & Destructor Documentation

def __init__ (   self,
  tactic,
  ctx = None 
)

Definition at line 6462 of file z3py.py.

6462  def __init__(self, tactic, ctx=None):
6463  self.ctx = _get_ctx(ctx)
6464  self.tactic = None
6465  if isinstance(tactic, TacticObj):
6466  self.tactic = tactic
6467  else:
6468  if __debug__:
6469  _z3_assert(isinstance(tactic, str), "tactic name expected")
6470  try:
6471  self.tactic = Z3_mk_tactic(self.ctx.ref(), str(tactic))
6472  except Z3Exception:
6473  raise Z3Exception("unknown tactic '%s'" % tactic)
6474  Z3_tactic_inc_ref(self.ctx.ref(), self.tactic)
6475 
Z3_tactic Z3_API Z3_mk_tactic(__in Z3_context c, __in Z3_string name)
Return a tactic associated with the given name. The complete list of tactics may be obtained using th...
def __init__
Definition: z3py.py:6462
void Z3_API Z3_tactic_inc_ref(__in Z3_context c, __in Z3_tactic t)
Increment the reference counter of the given tactic.
def __del__ (   self)

Definition at line 6476 of file z3py.py.

6476  def __del__(self):
6477  if self.tactic != None:
6478  Z3_tactic_dec_ref(self.ctx.ref(), self.tactic)
6479 
def __del__(self)
Definition: z3py.py:6476
void Z3_API Z3_tactic_dec_ref(__in Z3_context c, __in Z3_tactic g)
Decrement the reference counter of the given tactic.

Member Function Documentation

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

6514  def __call__(self, goal, *arguments, **keywords):
6515  """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options.
6516 
6517  >>> x, y = Ints('x y')
6518  >>> t = Tactic('solve-eqs')
6519  >>> t(And(x == 0, y >= x + 1))
6520  [[y >= 1]]
6521  """
6522  return self.apply(goal, *arguments, **keywords)
6523 
def apply(self, goal, arguments, keywords)
Definition: z3py.py:6497
def __call__(self, goal, arguments, keywords)
Definition: z3py.py:6514
def 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 6497 of file z3py.py.

Referenced by Tactic.__call__().

6497  def apply(self, goal, *arguments, **keywords):
6498  """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options.
6499 
6500  >>> x, y = Ints('x y')
6501  >>> t = Tactic('solve-eqs')
6502  >>> t.apply(And(x == 0, y >= x + 1))
6503  [[y >= 1]]
6504  """
6505  if __debug__:
6506  _z3_assert(isinstance(goal, Goal) or isinstance(goal, BoolRef), "Z3 Goal or Boolean expressions expected")
6507  goal = _to_goal(goal)
6508  if len(arguments) > 0 or len(keywords) > 0:
6509  p = args2params(arguments, keywords, self.ctx)
6510  return ApplyResult(Z3_tactic_apply_ex(self.ctx.ref(), self.tactic, goal.goal, p.params), self.ctx)
6511  else:
6512  return ApplyResult(Z3_tactic_apply(self.ctx.ref(), self.tactic, goal.goal), self.ctx)
6513 
Z3_apply_result Z3_API Z3_tactic_apply(__in Z3_context c, __in Z3_tactic t, __in Z3_goal g)
Apply tactic t to the goal g.
def args2params
Definition: z3py.py:4490
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.
def apply(self, goal, arguments, keywords)
Definition: z3py.py:6497
def help (   self)
Display a string containing a description of the available options for the `self` tactic.

Definition at line 6524 of file z3py.py.

6524  def help(self):
6525  """Display a string containing a description of the available options for the `self` tactic."""
6526  print(Z3_tactic_get_help(self.ctx.ref(), self.tactic))
6527 
Z3_string Z3_API Z3_tactic_get_help(__in Z3_context c, __in Z3_tactic t)
Return a string containing a description of parameters accepted by the given tactic.
def help(self)
Definition: z3py.py:6524
def param_descrs (   self)
Return the parameter description set.

Definition at line 6528 of file z3py.py.

6528  def param_descrs(self):
6529  """Return the parameter description set."""
6530  return ParamDescrsRef(Z3_tactic_get_param_descrs(self.ctx.ref(), self.tactic), self.ctx)
6531 
def param_descrs(self)
Definition: z3py.py:6528
Z3_param_descrs Z3_API Z3_tactic_get_param_descrs(__in Z3_context c, __in Z3_tactic t)
Return the parameter description set for the given tactic object.
def solver (   self)
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 6480 of file z3py.py.

6480  def solver(self):
6481  """Create a solver using the tactic `self`.
6482 
6483  The solver supports the methods `push()` and `pop()`, but it
6484  will always solve each `check()` from scratch.
6485 
6486  >>> t = Then('simplify', 'nlsat')
6487  >>> s = t.solver()
6488  >>> x = Real('x')
6489  >>> s.add(x**2 == 2, x > 0)
6490  >>> s.check()
6491  sat
6492  >>> s.model()
6493  [x = 1.4142135623?]
6494  """
6495  return Solver(Z3_mk_solver_from_tactic(self.ctx.ref(), self.tactic), self.ctx)
6496 
def solver(self)
Definition: z3py.py:6480
Z3_solver Z3_API Z3_mk_solver_from_tactic(__in Z3_context c, __in Z3_tactic t)
Create a new solver that is implemented using the given tactic. The solver supports the commands Z3_s...

Field Documentation

ctx
tactic