Z3
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Data Fields
Goal Class Reference
+ 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
 
- Public Member Functions inherited from Z3PPObject
def use_pp
 

Data Fields

 ctx
 
 goal
 

Detailed Description

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

Constructor & Destructor Documentation

def __init__ (   self,
  models = True,
  unsat_cores = False,
  proofs = False,
  ctx = None,
  goal = None 
)

Definition at line 4460 of file z3py.py.

4461  def __init__(self, models=True, unsat_cores=False, proofs=False, ctx=None, goal=None):
4462  if __debug__:
4463  _z3_assert(goal == None or ctx != None, "If goal is different from None, then ctx must be also different from None")
4464  self.ctx = _get_ctx(ctx)
4465  self.goal = goal
4466  if self.goal == None:
4467  self.goal = Z3_mk_goal(self.ctx.ref(), models, unsat_cores, proofs)
4468  Z3_goal_inc_ref(self.ctx.ref(), self.goal)
def __del__ (   self)

Definition at line 4469 of file z3py.py.

4470  def __del__(self):
4471  if self.goal != None:
4472  Z3_goal_dec_ref(self.ctx.ref(), self.goal)

Member Function Documentation

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

4578  def __getitem__(self, arg):
4579  """Return a constraint in the goal `self`.
4580 
4581  >>> g = Goal()
4582  >>> x, y = Ints('x y')
4583  >>> g.add(x == 0, y > x)
4584  >>> g[0]
4585  x == 0
4586  >>> g[1]
4587  y > x
4588  """
4589  if arg >= len(self):
4590  raise IndexError
4591  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

Definition at line 4551 of file z3py.py.

4552  def __len__(self):
4553  """Return the number of constraints in the goal `self`.
4554 
4555  >>> g = Goal()
4556  >>> len(g)
4557  0
4558  >>> x, y = Ints('x y')
4559  >>> g.add(x == 0, y > x)
4560  >>> len(g)
4561  2
4562  """
4563  return self.size()
def __repr__ (   self)

Definition at line 4640 of file z3py.py.

4641  def __repr__(self):
4642  return obj_to_string(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 4629 of file z3py.py.

4630  def add(self, *args):
4631  """Add constraints.
4632 
4633  >>> x = Int('x')
4634  >>> g = Goal()
4635  >>> g.add(x > 0, x < 2)
4636  >>> g
4637  [x > 0, x < 2]
4638  """
4639  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 4607 of file z3py.py.

4608  def append(self, *args):
4609  """Add constraints.
4610 
4611  >>> x = Int('x')
4612  >>> g = Goal()
4613  >>> g.append(x > 0, x < 2)
4614  >>> g
4615  [x > 0, x < 2]
4616  """
4617  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 4690 of file z3py.py.

4691  def as_expr(self):
4692  """Return goal `self` as a single Z3 expression.
4693 
4694  >>> x = Int('x')
4695  >>> g = Goal()
4696  >>> g.as_expr()
4697  True
4698  >>> g.add(x > 1)
4699  >>> g.as_expr()
4700  x > 1
4701  >>> g.add(x < 10)
4702  >>> g.as_expr()
4703  And(x > 1, x < 10)
4704  """
4705  sz = len(self)
4706  if sz == 0:
4707  return BoolVal(True, self.ctx)
4708  elif sz == 1:
4709  return self.get(0)
4710  else:
4711  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 4592 of file z3py.py.

Referenced by Goal.add(), and Goal.append().

4593  def assert_exprs(self, *args):
4594  """Assert constraints into the goal.
4595 
4596  >>> x = Int('x')
4597  >>> g = Goal()
4598  >>> g.assert_exprs(x > 0, x < 2)
4599  >>> g
4600  [x > 0, x < 2]
4601  """
4602  args = _get_args(args)
4603  s = BoolSort(self.ctx)
4604  for arg in args:
4605  arg = s.cast(arg)
4606  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 4473 of file z3py.py.

4474  def depth(self):
4475  """Return the depth of the goal `self`. The depth corresponds to the number of tactics applied to `self`.
4476 
4477  >>> x, y = Ints('x y')
4478  >>> g = Goal()
4479  >>> g.add(x == 0, y >= x + 1)
4480  >>> g.depth()
4481  0
4482  >>> r = Then('simplify', 'solve-eqs')(g)
4483  >>> # r has 1 subgoal
4484  >>> len(r)
4485  1
4486  >>> r[0].depth()
4487  2
4488  """
4489  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 4564 of file z3py.py.

Referenced by Goal.__getitem__(), and Goal.as_expr().

4565  def get(self, i):
4566  """Return a constraint in the goal `self`.
4567 
4568  >>> g = Goal()
4569  >>> x, y = Ints('x y')
4570  >>> g.add(x == 0, y > x)
4571  >>> g.get(0)
4572  x == 0
4573  >>> g.get(1)
4574  y > x
4575  """
4576  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 4490 of file z3py.py.

4491  def inconsistent(self):
4492  """Return `True` if `self` contains the `False` constraints.
4493 
4494  >>> x, y = Ints('x y')
4495  >>> g = Goal()
4496  >>> g.inconsistent()
4497  False
4498  >>> g.add(x == 0, x == 1)
4499  >>> g
4500  [x == 0, x == 1]
4501  >>> g.inconsistent()
4502  False
4503  >>> g2 = Tactic('propagate-values')(g)[0]
4504  >>> g2.inconsistent()
4505  True
4506  """
4507  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 4618 of file z3py.py.

4619  def insert(self, *args):
4620  """Add constraints.
4621 
4622  >>> x = Int('x')
4623  >>> g = Goal()
4624  >>> g.insert(x > 0, x < 2)
4625  >>> g
4626  [x > 0, x < 2]
4627  """
4628  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 4508 of file z3py.py.

Referenced by Goal.precision().

4509  def prec(self):
4510  """Return the precision (under-approximation, over-approximation, or precise) of the goal `self`.
4511 
4512  >>> g = Goal()
4513  >>> g.prec() == Z3_GOAL_PRECISE
4514  True
4515  >>> x, y = Ints('x y')
4516  >>> g.add(x == y + 1)
4517  >>> g.prec() == Z3_GOAL_PRECISE
4518  True
4519  >>> t = With(Tactic('add-bounds'), add_bound_lower=0, add_bound_upper=10)
4520  >>> g2 = t(g)[0]
4521  >>> g2
4522  [x == y + 1, x <= 10, x >= 0, y <= 10, y >= 0]
4523  >>> g2.prec() == Z3_GOAL_PRECISE
4524  False
4525  >>> g2.prec() == Z3_GOAL_UNDER
4526  True
4527  """
4528  return Z3_goal_precision(self.ctx.ref(), self.goal)
def precision (   self)
Alias for `prec()`.

>>> g = Goal()
>>> g.precision() == Z3_GOAL_PRECISE
True

Definition at line 4529 of file z3py.py.

4530  def precision(self):
4531  """Alias for `prec()`.
4532 
4533  >>> g = Goal()
4534  >>> g.precision() == Z3_GOAL_PRECISE
4535  True
4536  """
4537  return self.prec()
def sexpr (   self)
Return a textual representation of the s-expression representing the goal.

Definition at line 4643 of file z3py.py.

4644  def sexpr(self):
4645  """Return a textual representation of the s-expression representing the goal."""
4646  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 4670 of file z3py.py.

4671  def simplify(self, *arguments, **keywords):
4672  """Return a new simplified goal.
4673 
4674  This method is essentially invoking the simplify tactic.
4675 
4676  >>> g = Goal()
4677  >>> x = Int('x')
4678  >>> g.add(x + 1 >= 2)
4679  >>> g
4680  [x + 1 >= 2]
4681  >>> g2 = g.simplify()
4682  >>> g2
4683  [x >= 1]
4684  >>> # g was not modified
4685  >>> g
4686  [x + 1 >= 2]
4687  """
4688  t = Tactic('simplify')
4689  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 4538 of file z3py.py.

Referenced by Goal.__len__().

4539  def size(self):
4540  """Return the number of constraints in the goal `self`.
4541 
4542  >>> g = Goal()
4543  >>> g.size()
4544  0
4545  >>> x, y = Ints('x y')
4546  >>> g.add(x == 0, y > x)
4547  >>> g.size()
4548  2
4549  """
4550  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 4647 of file z3py.py.

4648  def translate(self, target):
4649  """Copy goal `self` to context `target`.
4650 
4651  >>> x = Int('x')
4652  >>> g = Goal()
4653  >>> g.add(x > 10)
4654  >>> g
4655  [x > 10]
4656  >>> c2 = Context()
4657  >>> g2 = g.translate(c2)
4658  >>> g2
4659  [x > 10]
4660  >>> g.ctx == main_ctx()
4661  True
4662  >>> g2.ctx == c2
4663  True
4664  >>> g2.ctx == main_ctx()
4665  False
4666  """
4667  if __debug__:
4668  _z3_assert(isinstance(target, Context), "target must be a context")
4669  return Goal(goal=Z3_goal_translate(self.ctx.ref(), self.goal, target.ref()), ctx=target)

Field Documentation

ctx

Definition at line 4463 of file z3py.py.

Referenced by Probe.__eq__(), Probe.__ge__(), ApplyResult.__getitem__(), Probe.__gt__(), Probe.__le__(), Probe.__lt__(), Probe.__ne__(), Tactic.apply(), Goal.as_expr(), ApplyResult.as_expr(), Goal.assert_exprs(), ApplyResult.convert_model(), Goal.get(), Fixedpoint.get_assertions(), Fixedpoint.get_cover_delta(), Fixedpoint.get_rules(), Tactic.param_descrs(), Fixedpoint.parse_file(), Fixedpoint.parse_string(), Tactic.solver(), and Fixedpoint.statistics().

goal

Definition at line 4464 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().