Z3
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Data Fields
Tactic Class Reference

Public Member Functions

def __init__
 
def __del__
 
def solver
 
def apply
 
def __call__
 
def help
 
def param_descrs
 

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

Constructor & Destructor Documentation

def __init__ (   self,
  tactic,
  ctx = None 
)

Definition at line 6323 of file z3py.py.

6324  def __init__(self, tactic, ctx=None):
6325  self.ctx = _get_ctx(ctx)
6326  self.tactic = None
6327  if isinstance(tactic, TacticObj):
6328  self.tactic = tactic
6329  else:
6330  if __debug__:
6331  _z3_assert(isinstance(tactic, str), "tactic name expected")
6332  try:
6333  self.tactic = Z3_mk_tactic(self.ctx.ref(), str(tactic))
6334  except Z3Exception:
6335  raise Z3Exception("unknown tactic '%s'" % tactic)
6336  Z3_tactic_inc_ref(self.ctx.ref(), self.tactic)
def __del__ (   self)

Definition at line 6337 of file z3py.py.

6338  def __del__(self):
6339  if self.tactic != None:
6340  Z3_tactic_dec_ref(self.ctx.ref(), self.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 6375 of file z3py.py.

6376  def __call__(self, goal, *arguments, **keywords):
6377  """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options.
6378 
6379  >>> x, y = Ints('x y')
6380  >>> t = Tactic('solve-eqs')
6381  >>> t(And(x == 0, y >= x + 1))
6382  [[y >= 1]]
6383  """
6384  return self.apply(goal, *arguments, **keywords)
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 6358 of file z3py.py.

Referenced by Tactic.__call__().

6359  def apply(self, goal, *arguments, **keywords):
6360  """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options.
6361 
6362  >>> x, y = Ints('x y')
6363  >>> t = Tactic('solve-eqs')
6364  >>> t.apply(And(x == 0, y >= x + 1))
6365  [[y >= 1]]
6366  """
6367  if __debug__:
6368  _z3_assert(isinstance(goal, Goal) or isinstance(goal, BoolRef), "Z3 Goal or Boolean expressions expected")
6369  goal = _to_goal(goal)
6370  if len(arguments) > 0 or len(keywords) > 0:
6371  p = args2params(arguments, keywords, a.ctx)
6372  return ApplyResult(Z3_tactic_apply_ex(self.ctx.ref(), self.tactic, goal.goal, p.params), self.ctx)
6373  else:
6374  return ApplyResult(Z3_tactic_apply(self.ctx.ref(), self.tactic, goal.goal), self.ctx)
def help (   self)
Display a string containing a description of the available options for the `self` tactic.

Definition at line 6385 of file z3py.py.

6386  def help(self):
6387  """Display a string containing a description of the available options for the `self` tactic."""
6388  print Z3_tactic_get_help(self.ctx.ref(), self.tactic)
def param_descrs (   self)
Return the parameter description set.

Definition at line 6389 of file z3py.py.

6390  def param_descrs(self):
6391  """Return the parameter description set."""
6392  return ParamDescrsRef(Z3_tactic_get_param_descrs(self.ctx.ref(), self.tactic), self.ctx)
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 6341 of file z3py.py.

6342  def solver(self):
6343  """Create a solver using the tactic `self`.
6344 
6345  The solver supports the methods `push()` and `pop()`, but it
6346  will always solve each `check()` from scratch.
6347 
6348  >>> t = Then('simplify', 'nlsat')
6349  >>> s = t.solver()
6350  >>> x = Real('x')
6351  >>> s.add(x**2 == 2, x > 0)
6352  >>> s.check()
6353  sat
6354  >>> s.model()
6355  [x = 1.4142135623?]
6356  """
6357  return Solver(Z3_mk_solver_from_tactic(self.ctx.ref(), self.tactic), self.ctx)

Field Documentation

ctx

Definition at line 6324 of file z3py.py.

Referenced by Probe.__eq__(), Probe.__ge__(), Probe.__gt__(), Probe.__le__(), Probe.__lt__(), Probe.__ne__(), Tactic.apply(), Tactic.param_descrs(), and Tactic.solver().

tactic

Definition at line 6325 of file z3py.py.

Referenced by Tactic.__del__(), Tactic.apply(), Tactic.help(), Tactic.param_descrs(), and Tactic.solver().