Z3
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules 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 4536 of file z3py.py.

Constructor & Destructor Documentation

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

Definition at line 4544 of file z3py.py.

4545  def __init__(self, models=True, unsat_cores=False, proofs=False, ctx=None, goal=None):
4546  if __debug__:
4547  _z3_assert(goal == None or ctx != None, "If goal is different from None, then ctx must be also different from None")
4548  self.ctx = _get_ctx(ctx)
4549  self.goal = goal
4550  if self.goal == None:
4551  self.goal = Z3_mk_goal(self.ctx.ref(), models, unsat_cores, proofs)
4552  Z3_goal_inc_ref(self.ctx.ref(), self.goal)
void Z3_API Z3_goal_inc_ref(__in Z3_context c, __in Z3_goal g)
Increment the reference counter of the given goal.
def __init__
Definition: z3py.py:4544
Z3_goal Z3_API Z3_mk_goal(__in Z3_context c, __in Z3_bool models, __in Z3_bool unsat_cores, __in Z3_bool proofs)
Create a goal (aka problem). A goal is essentially a set of formulas, that can be solved and/or trans...
def __del__ (   self)

Definition at line 4553 of file z3py.py.

4554  def __del__(self):
4555  if self.goal != None:
4556  Z3_goal_dec_ref(self.ctx.ref(), self.goal)
def __del__
Definition: z3py.py:4553
void Z3_API Z3_goal_dec_ref(__in Z3_context c, __in Z3_goal g)
Decrement the reference counter of the given 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 4661 of file z3py.py.

4662  def __getitem__(self, arg):
4663  """Return a constraint in the goal `self`.
4664 
4665  >>> g = Goal()
4666  >>> x, y = Ints('x y')
4667  >>> g.add(x == 0, y > x)
4668  >>> g[0]
4669  x == 0
4670  >>> g[1]
4671  y > x
4672  """
4673  if arg >= len(self):
4674  raise IndexError
4675  return self.get(arg)
def __getitem__
Definition: z3py.py:4661
def get
Definition: z3py.py:4648
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 4635 of file z3py.py.

Referenced by AstVector.__getitem__(), and AstVector.__setitem__().

4636  def __len__(self):
4637  """Return the number of constraints in the goal `self`.
4638 
4639  >>> g = Goal()
4640  >>> len(g)
4641  0
4642  >>> x, y = Ints('x y')
4643  >>> g.add(x == 0, y > x)
4644  >>> len(g)
4645  2
4646  """
4647  return self.size()
def __len__
Definition: z3py.py:4635
def size
Definition: z3py.py:4622
def __repr__ (   self)

Definition at line 4724 of file z3py.py.

4725  def __repr__(self):
4726  return obj_to_string(self)
def __repr__
Definition: z3py.py:4724
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 4713 of file z3py.py.

4714  def add(self, *args):
4715  """Add constraints.
4716 
4717  >>> x = Int('x')
4718  >>> g = Goal()
4719  >>> g.add(x > 0, x < 2)
4720  >>> g
4721  [x > 0, x < 2]
4722  """
4723  self.assert_exprs(*args)
def add
Definition: z3py.py:4713
def assert_exprs
Definition: z3py.py:4676
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 4691 of file z3py.py.

4692  def append(self, *args):
4693  """Add constraints.
4694 
4695  >>> x = Int('x')
4696  >>> g = Goal()
4697  >>> g.append(x > 0, x < 2)
4698  >>> g
4699  [x > 0, x < 2]
4700  """
4701  self.assert_exprs(*args)
def append
Definition: z3py.py:4691
def assert_exprs
Definition: z3py.py:4676
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 4774 of file z3py.py.

4775  def as_expr(self):
4776  """Return goal `self` as a single Z3 expression.
4777 
4778  >>> x = Int('x')
4779  >>> g = Goal()
4780  >>> g.as_expr()
4781  True
4782  >>> g.add(x > 1)
4783  >>> g.as_expr()
4784  x > 1
4785  >>> g.add(x < 10)
4786  >>> g.as_expr()
4787  And(x > 1, x < 10)
4788  """
4789  sz = len(self)
4790  if sz == 0:
4791  return BoolVal(True, self.ctx)
4792  elif sz == 1:
4793  return self.get(0)
4794  else:
4795  return And([ self.get(i) for i in range(len(self)) ])
def BoolVal
Definition: z3py.py:1342
def And
Definition: z3py.py:1468
def as_expr
Definition: z3py.py:4774
def get
Definition: z3py.py:4648
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 4676 of file z3py.py.

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

4677  def assert_exprs(self, *args):
4678  """Assert constraints into the goal.
4679 
4680  >>> x = Int('x')
4681  >>> g = Goal()
4682  >>> g.assert_exprs(x > 0, x < 2)
4683  >>> g
4684  [x > 0, x < 2]
4685  """
4686  args = _get_args(args)
4687  s = BoolSort(self.ctx)
4688  for arg in args:
4689  arg = s.cast(arg)
4690  Z3_goal_assert(self.ctx.ref(), self.goal, arg.as_ast())
def BoolSort
Definition: z3py.py:1325
void Z3_API Z3_goal_assert(__in Z3_context c, __in Z3_goal g, __in Z3_ast a)
Add a new formula a to the given goal.
def assert_exprs
Definition: z3py.py:4676
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 4557 of file z3py.py.

4558  def depth(self):
4559  """Return the depth of the goal `self`. The depth corresponds to the number of tactics applied to `self`.
4560 
4561  >>> x, y = Ints('x y')
4562  >>> g = Goal()
4563  >>> g.add(x == 0, y >= x + 1)
4564  >>> g.depth()
4565  0
4566  >>> r = Then('simplify', 'solve-eqs')(g)
4567  >>> # r has 1 subgoal
4568  >>> len(r)
4569  1
4570  >>> r[0].depth()
4571  2
4572  """
4573  return int(Z3_goal_depth(self.ctx.ref(), self.goal))
def depth
Definition: z3py.py:4557
unsigned Z3_API Z3_goal_depth(__in Z3_context c, __in Z3_goal g)
Return the depth of the given goal. It tracks how many transformations were applied to it...
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 4648 of file z3py.py.

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

4649  def get(self, i):
4650  """Return a constraint in the goal `self`.
4651 
4652  >>> g = Goal()
4653  >>> x, y = Ints('x y')
4654  >>> g.add(x == 0, y > x)
4655  >>> g.get(0)
4656  x == 0
4657  >>> g.get(1)
4658  y > x
4659  """
4660  return _to_expr_ref(Z3_goal_formula(self.ctx.ref(), self.goal, i), self.ctx)
Z3_ast Z3_API Z3_goal_formula(__in Z3_context c, __in Z3_goal g, __in unsigned idx)
Return a formula from the given goal.
def get
Definition: z3py.py:4648
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 4574 of file z3py.py.

4575  def inconsistent(self):
4576  """Return `True` if `self` contains the `False` constraints.
4577 
4578  >>> x, y = Ints('x y')
4579  >>> g = Goal()
4580  >>> g.inconsistent()
4581  False
4582  >>> g.add(x == 0, x == 1)
4583  >>> g
4584  [x == 0, x == 1]
4585  >>> g.inconsistent()
4586  False
4587  >>> g2 = Tactic('propagate-values')(g)[0]
4588  >>> g2.inconsistent()
4589  True
4590  """
4591  return Z3_goal_inconsistent(self.ctx.ref(), self.goal)
Z3_bool Z3_API Z3_goal_inconsistent(__in Z3_context c, __in Z3_goal g)
Return true if the given goal contains the formula false.
def inconsistent
Definition: z3py.py:4574
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 4702 of file z3py.py.

4703  def insert(self, *args):
4704  """Add constraints.
4705 
4706  >>> x = Int('x')
4707  >>> g = Goal()
4708  >>> g.insert(x > 0, x < 2)
4709  >>> g
4710  [x > 0, x < 2]
4711  """
4712  self.assert_exprs(*args)
def insert
Definition: z3py.py:4702
def assert_exprs
Definition: z3py.py:4676
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 4592 of file z3py.py.

Referenced by Goal.precision().

4593  def prec(self):
4594  """Return the precision (under-approximation, over-approximation, or precise) of the goal `self`.
4595 
4596  >>> g = Goal()
4597  >>> g.prec() == Z3_GOAL_PRECISE
4598  True
4599  >>> x, y = Ints('x y')
4600  >>> g.add(x == y + 1)
4601  >>> g.prec() == Z3_GOAL_PRECISE
4602  True
4603  >>> t = With(Tactic('add-bounds'), add_bound_lower=0, add_bound_upper=10)
4604  >>> g2 = t(g)[0]
4605  >>> g2
4606  [x == y + 1, x <= 10, x >= 0, y <= 10, y >= 0]
4607  >>> g2.prec() == Z3_GOAL_PRECISE
4608  False
4609  >>> g2.prec() == Z3_GOAL_UNDER
4610  True
4611  """
4612  return Z3_goal_precision(self.ctx.ref(), self.goal)
Z3_goal_prec Z3_API Z3_goal_precision(__in Z3_context c, __in Z3_goal g)
Return the "precision" of the given goal. Goals can be transformed using over and under approximation...
def prec
Definition: z3py.py:4592
def precision (   self)
Alias for `prec()`.

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

Definition at line 4613 of file z3py.py.

4614  def precision(self):
4615  """Alias for `prec()`.
4616 
4617  >>> g = Goal()
4618  >>> g.precision() == Z3_GOAL_PRECISE
4619  True
4620  """
4621  return self.prec()
def prec
Definition: z3py.py:4592
def precision
Definition: z3py.py:4613
def sexpr (   self)
Return a textual representation of the s-expression representing the goal.

Definition at line 4727 of file z3py.py.

Referenced by Fixedpoint.__repr__().

4728  def sexpr(self):
4729  """Return a textual representation of the s-expression representing the goal."""
4730  return Z3_goal_to_string(self.ctx.ref(), self.goal)
def sexpr
Definition: z3py.py:4727
Z3_string Z3_API Z3_goal_to_string(__in Z3_context c, __in Z3_goal g)
Convert a goal into a string.
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 4754 of file z3py.py.

4755  def simplify(self, *arguments, **keywords):
4756  """Return a new simplified goal.
4757 
4758  This method is essentially invoking the simplify tactic.
4759 
4760  >>> g = Goal()
4761  >>> x = Int('x')
4762  >>> g.add(x + 1 >= 2)
4763  >>> g
4764  [x + 1 >= 2]
4765  >>> g2 = g.simplify()
4766  >>> g2
4767  [x >= 1]
4768  >>> # g was not modified
4769  >>> g
4770  [x + 1 >= 2]
4771  """
4772  t = Tactic('simplify')
4773  return t.apply(self, *arguments, **keywords)[0]
def simplify
Definition: z3py.py:4754
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 4622 of file z3py.py.

Referenced by Goal.__len__().

4623  def size(self):
4624  """Return the number of constraints in the goal `self`.
4625 
4626  >>> g = Goal()
4627  >>> g.size()
4628  0
4629  >>> x, y = Ints('x y')
4630  >>> g.add(x == 0, y > x)
4631  >>> g.size()
4632  2
4633  """
4634  return int(Z3_goal_size(self.ctx.ref(), self.goal))
unsigned Z3_API Z3_goal_size(__in Z3_context c, __in Z3_goal g)
Return the number of formulas in the given goal.
def size
Definition: z3py.py:4622
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 4731 of file z3py.py.

4732  def translate(self, target):
4733  """Copy goal `self` to context `target`.
4734 
4735  >>> x = Int('x')
4736  >>> g = Goal()
4737  >>> g.add(x > 10)
4738  >>> g
4739  [x > 10]
4740  >>> c2 = Context()
4741  >>> g2 = g.translate(c2)
4742  >>> g2
4743  [x > 10]
4744  >>> g.ctx == main_ctx()
4745  True
4746  >>> g2.ctx == c2
4747  True
4748  >>> g2.ctx == main_ctx()
4749  False
4750  """
4751  if __debug__:
4752  _z3_assert(isinstance(target, Context), "target must be a context")
4753  return Goal(goal=Z3_goal_translate(self.ctx.ref(), self.goal, target.ref()), ctx=target)
Z3_goal Z3_API Z3_goal_translate(__in Z3_context source, __in Z3_goal g, __in Z3_context target)
Copy a goal g from the context source to a the context target.
def translate
Definition: z3py.py:4731

Field Documentation

ctx

Definition at line 4547 of file z3py.py.

Referenced by Probe.__eq__(), Probe.__ge__(), AstVector.__getitem__(), AstMap.__getitem__(), ApplyResult.__getitem__(), Probe.__gt__(), Probe.__le__(), Probe.__lt__(), Probe.__ne__(), Fixedpoint.add_rule(), Tactic.apply(), FuncEntry.arg_value(), Goal.as_expr(), ApplyResult.as_expr(), Goal.assert_exprs(), Fixedpoint.assert_exprs(), ApplyResult.convert_model(), FuncInterp.else_value(), FuncInterp.entry(), Goal.get(), Fixedpoint.get_answer(), Fixedpoint.get_assertions(), Fixedpoint.get_cover_delta(), Fixedpoint.get_rules(), AstMap.keys(), Fixedpoint.param_descrs(), Tactic.param_descrs(), Fixedpoint.parse_file(), Fixedpoint.parse_string(), Fixedpoint.set(), Tactic.solver(), Fixedpoint.statistics(), Solver.to_smt2(), Fixedpoint.update_rule(), and FuncEntry.value().

goal

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