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

Constructor & Destructor Documentation

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

Definition at line 4604 of file z3py.py.

4605  def __init__(self, models=True, unsat_cores=False, proofs=False, ctx=None, goal=None):
4606  if __debug__:
4607  _z3_assert(goal == None or ctx != None, "If goal is different from None, then ctx must be also different from None")
4608  self.ctx = _get_ctx(ctx)
4609  self.goal = goal
4610  if self.goal == None:
4611  self.goal = Z3_mk_goal(self.ctx.ref(), models, unsat_cores, proofs)
4612  Z3_goal_inc_ref(self.ctx.ref(), self.goal)
Z3_goal Z3_API Z3_mk_goal(Z3_context c, Z3_bool models, Z3_bool unsat_cores, Z3_bool proofs)
Create a goal (aka problem). A goal is essentially a set of formulas, that can be solved and/or trans...
void Z3_API Z3_goal_inc_ref(Z3_context c, Z3_goal g)
Increment the reference counter of the given goal.
def __init__
Definition: z3py.py:4604
def __del__ (   self)

Definition at line 4613 of file z3py.py.

4614  def __del__(self):
4615  if self.goal != None:
4616  Z3_goal_dec_ref(self.ctx.ref(), self.goal)
def __del__
Definition: z3py.py:4613
void Z3_API Z3_goal_dec_ref(Z3_context c, 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 4721 of file z3py.py.

4722  def __getitem__(self, arg):
4723  """Return a constraint in the goal `self`.
4724 
4725  >>> g = Goal()
4726  >>> x, y = Ints('x y')
4727  >>> g.add(x == 0, y > x)
4728  >>> g[0]
4729  x == 0
4730  >>> g[1]
4731  y > x
4732  """
4733  if arg >= len(self):
4734  raise IndexError
4735  return self.get(arg)
def __getitem__
Definition: z3py.py:4721
def get
Definition: z3py.py:4708
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 4695 of file z3py.py.

4696  def __len__(self):
4697  """Return the number of constraints in the goal `self`.
4698 
4699  >>> g = Goal()
4700  >>> len(g)
4701  0
4702  >>> x, y = Ints('x y')
4703  >>> g.add(x == 0, y > x)
4704  >>> len(g)
4705  2
4706  """
4707  return self.size()
def __len__
Definition: z3py.py:4695
def size
Definition: z3py.py:4682
def __repr__ (   self)

Definition at line 4784 of file z3py.py.

4785  def __repr__(self):
4786  return obj_to_string(self)
def __repr__
Definition: z3py.py:4784
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 4773 of file z3py.py.

4774  def add(self, *args):
4775  """Add constraints.
4776 
4777  >>> x = Int('x')
4778  >>> g = Goal()
4779  >>> g.add(x > 0, x < 2)
4780  >>> g
4781  [x > 0, x < 2]
4782  """
4783  self.assert_exprs(*args)
def add
Definition: z3py.py:4773
def assert_exprs
Definition: z3py.py:4736
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 4751 of file z3py.py.

4752  def append(self, *args):
4753  """Add constraints.
4754 
4755  >>> x = Int('x')
4756  >>> g = Goal()
4757  >>> g.append(x > 0, x < 2)
4758  >>> g
4759  [x > 0, x < 2]
4760  """
4761  self.assert_exprs(*args)
def append
Definition: z3py.py:4751
def assert_exprs
Definition: z3py.py:4736
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 4834 of file z3py.py.

4835  def as_expr(self):
4836  """Return goal `self` as a single Z3 expression.
4837 
4838  >>> x = Int('x')
4839  >>> g = Goal()
4840  >>> g.as_expr()
4841  True
4842  >>> g.add(x > 1)
4843  >>> g.as_expr()
4844  x > 1
4845  >>> g.add(x < 10)
4846  >>> g.as_expr()
4847  And(x > 1, x < 10)
4848  """
4849  sz = len(self)
4850  if sz == 0:
4851  return BoolVal(True, self.ctx)
4852  elif sz == 1:
4853  return self.get(0)
4854  else:
4855  return And([ self.get(i) for i in range(len(self)) ])
def BoolVal
Definition: z3py.py:1363
def And
Definition: z3py.py:1489
def as_expr
Definition: z3py.py:4834
def get
Definition: z3py.py:4708
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 4736 of file z3py.py.

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

4737  def assert_exprs(self, *args):
4738  """Assert constraints into the goal.
4739 
4740  >>> x = Int('x')
4741  >>> g = Goal()
4742  >>> g.assert_exprs(x > 0, x < 2)
4743  >>> g
4744  [x > 0, x < 2]
4745  """
4746  args = _get_args(args)
4747  s = BoolSort(self.ctx)
4748  for arg in args:
4749  arg = s.cast(arg)
4750  Z3_goal_assert(self.ctx.ref(), self.goal, arg.as_ast())
def BoolSort
Definition: z3py.py:1346
def assert_exprs
Definition: z3py.py:4736
void Z3_API Z3_goal_assert(Z3_context c, Z3_goal g, Z3_ast a)
Add a new formula a to the given goal.
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 4617 of file z3py.py.

4618  def depth(self):
4619  """Return the depth of the goal `self`. The depth corresponds to the number of tactics applied to `self`.
4620 
4621  >>> x, y = Ints('x y')
4622  >>> g = Goal()
4623  >>> g.add(x == 0, y >= x + 1)
4624  >>> g.depth()
4625  0
4626  >>> r = Then('simplify', 'solve-eqs')(g)
4627  >>> # r has 1 subgoal
4628  >>> len(r)
4629  1
4630  >>> r[0].depth()
4631  2
4632  """
4633  return int(Z3_goal_depth(self.ctx.ref(), self.goal))
def depth
Definition: z3py.py:4617
unsigned Z3_API Z3_goal_depth(Z3_context c, 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 4708 of file z3py.py.

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

4709  def get(self, i):
4710  """Return a constraint in the goal `self`.
4711 
4712  >>> g = Goal()
4713  >>> x, y = Ints('x y')
4714  >>> g.add(x == 0, y > x)
4715  >>> g.get(0)
4716  x == 0
4717  >>> g.get(1)
4718  y > x
4719  """
4720  return _to_expr_ref(Z3_goal_formula(self.ctx.ref(), self.goal, i), self.ctx)
def get
Definition: z3py.py:4708
Z3_ast Z3_API Z3_goal_formula(Z3_context c, Z3_goal g, unsigned idx)
Return a formula from the given goal.
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 4634 of file z3py.py.

4635  def inconsistent(self):
4636  """Return `True` if `self` contains the `False` constraints.
4637 
4638  >>> x, y = Ints('x y')
4639  >>> g = Goal()
4640  >>> g.inconsistent()
4641  False
4642  >>> g.add(x == 0, x == 1)
4643  >>> g
4644  [x == 0, x == 1]
4645  >>> g.inconsistent()
4646  False
4647  >>> g2 = Tactic('propagate-values')(g)[0]
4648  >>> g2.inconsistent()
4649  True
4650  """
4651  return Z3_goal_inconsistent(self.ctx.ref(), self.goal)
Z3_bool Z3_API Z3_goal_inconsistent(Z3_context c, Z3_goal g)
Return true if the given goal contains the formula false.
def inconsistent
Definition: z3py.py:4634
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 4762 of file z3py.py.

4763  def insert(self, *args):
4764  """Add constraints.
4765 
4766  >>> x = Int('x')
4767  >>> g = Goal()
4768  >>> g.insert(x > 0, x < 2)
4769  >>> g
4770  [x > 0, x < 2]
4771  """
4772  self.assert_exprs(*args)
def insert
Definition: z3py.py:4762
def assert_exprs
Definition: z3py.py:4736
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 4652 of file z3py.py.

Referenced by Goal.precision().

4653  def prec(self):
4654  """Return the precision (under-approximation, over-approximation, or precise) of the goal `self`.
4655 
4656  >>> g = Goal()
4657  >>> g.prec() == Z3_GOAL_PRECISE
4658  True
4659  >>> x, y = Ints('x y')
4660  >>> g.add(x == y + 1)
4661  >>> g.prec() == Z3_GOAL_PRECISE
4662  True
4663  >>> t = With(Tactic('add-bounds'), add_bound_lower=0, add_bound_upper=10)
4664  >>> g2 = t(g)[0]
4665  >>> g2
4666  [x == y + 1, x <= 10, x >= 0, y <= 10, y >= 0]
4667  >>> g2.prec() == Z3_GOAL_PRECISE
4668  False
4669  >>> g2.prec() == Z3_GOAL_UNDER
4670  True
4671  """
4672  return Z3_goal_precision(self.ctx.ref(), self.goal)
def prec
Definition: z3py.py:4652
Z3_goal_prec Z3_API Z3_goal_precision(Z3_context c, Z3_goal g)
Return the &quot;precision&quot; of the given goal. Goals can be transformed using over and under approximation...
def precision (   self)
Alias for `prec()`.

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

Definition at line 4673 of file z3py.py.

4674  def precision(self):
4675  """Alias for `prec()`.
4676 
4677  >>> g = Goal()
4678  >>> g.precision() == Z3_GOAL_PRECISE
4679  True
4680  """
4681  return self.prec()
def prec
Definition: z3py.py:4652
def precision
Definition: z3py.py:4673
def sexpr (   self)
Return a textual representation of the s-expression representing the goal.

Definition at line 4787 of file z3py.py.

Referenced by Fixedpoint.__repr__(), and Optimize.__repr__().

4788  def sexpr(self):
4789  """Return a textual representation of the s-expression representing the goal."""
4790  return Z3_goal_to_string(self.ctx.ref(), self.goal)
def sexpr
Definition: z3py.py:4787
Z3_string Z3_API Z3_goal_to_string(Z3_context c, 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 4814 of file z3py.py.

4815  def simplify(self, *arguments, **keywords):
4816  """Return a new simplified goal.
4817 
4818  This method is essentially invoking the simplify tactic.
4819 
4820  >>> g = Goal()
4821  >>> x = Int('x')
4822  >>> g.add(x + 1 >= 2)
4823  >>> g
4824  [x + 1 >= 2]
4825  >>> g2 = g.simplify()
4826  >>> g2
4827  [x >= 1]
4828  >>> # g was not modified
4829  >>> g
4830  [x + 1 >= 2]
4831  """
4832  t = Tactic('simplify')
4833  return t.apply(self, *arguments, **keywords)[0]
def simplify
Definition: z3py.py:4814
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 4682 of file z3py.py.

Referenced by Goal.__len__().

4683  def size(self):
4684  """Return the number of constraints in the goal `self`.
4685 
4686  >>> g = Goal()
4687  >>> g.size()
4688  0
4689  >>> x, y = Ints('x y')
4690  >>> g.add(x == 0, y > x)
4691  >>> g.size()
4692  2
4693  """
4694  return int(Z3_goal_size(self.ctx.ref(), self.goal))
unsigned Z3_API Z3_goal_size(Z3_context c, Z3_goal g)
Return the number of formulas in the given goal.
def size
Definition: z3py.py:4682
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 4791 of file z3py.py.

4792  def translate(self, target):
4793  """Copy goal `self` to context `target`.
4794 
4795  >>> x = Int('x')
4796  >>> g = Goal()
4797  >>> g.add(x > 10)
4798  >>> g
4799  [x > 10]
4800  >>> c2 = Context()
4801  >>> g2 = g.translate(c2)
4802  >>> g2
4803  [x > 10]
4804  >>> g.ctx == main_ctx()
4805  True
4806  >>> g2.ctx == c2
4807  True
4808  >>> g2.ctx == main_ctx()
4809  False
4810  """
4811  if __debug__:
4812  _z3_assert(isinstance(target, Context), "target must be a context")
4813  return Goal(goal=Z3_goal_translate(self.ctx.ref(), self.goal, target.ref()), ctx=target)
Z3_goal Z3_API Z3_goal_translate(Z3_context source, Z3_goal g, Z3_context target)
Copy a goal g from the context source to a the context target.
def translate
Definition: z3py.py:4791

Field Documentation

ctx

Definition at line 4607 of file z3py.py.

Referenced by Probe.__eq__(), Probe.__ge__(), ApplyResult.__getitem__(), Probe.__gt__(), Probe.__le__(), Probe.__lt__(), Probe.__ne__(), Fixedpoint.add_rule(), Optimize.add_soft(), Tactic.apply(), Goal.as_expr(), ApplyResult.as_expr(), Goal.assert_exprs(), Fixedpoint.assert_exprs(), ApplyResult.convert_model(), Goal.get(), Fixedpoint.get_answer(), Fixedpoint.get_assertions(), Fixedpoint.get_cover_delta(), Fixedpoint.get_rules(), Optimize.model(), Fixedpoint.param_descrs(), Optimize.param_descrs(), Tactic.param_descrs(), Fixedpoint.parse_file(), Fixedpoint.parse_string(), Fixedpoint.query(), Fixedpoint.set(), Optimize.set(), Tactic.solver(), Fixedpoint.statistics(), Optimize.statistics(), Solver.to_smt2(), and Fixedpoint.update_rule().

goal

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