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

Public Member Functions

def __init__
 
def __del__
 
def __lt__
 
def __gt__
 
def __le__
 
def __ge__
 
def __eq__
 
def __ne__
 
def __call__
 

Data Fields

 ctx
 
 probe
 

Detailed Description

Probes are used to inspect a goal (aka problem) and collect information that may be used to decide which solver and/or preprocessing step will be used.

Definition at line 6584 of file z3py.py.

Constructor & Destructor Documentation

def __init__ (   self,
  probe,
  ctx = None 
)

Definition at line 6586 of file z3py.py.

6587  def __init__(self, probe, ctx=None):
6588  self.ctx = _get_ctx(ctx)
6589  self.probe = None
6590  if isinstance(probe, ProbeObj):
6591  self.probe = probe
6592  elif isinstance(probe, float):
6593  self.probe = Z3_probe_const(self.ctx.ref(), probe)
6594  elif isinstance(probe, int) or isinstance(probe, long):
6595  self.probe = Z3_probe_const(self.ctx.ref(), float(probe))
6596  elif isinstance(probe, bool):
6597  if probe:
6598  self.probe = Z3_probe_const(self.ctx.ref(), 1.0)
6599  else:
6600  self.probe = Z3_probe_const(self.ctx.ref(), 0.0)
6601  else:
6602  if __debug__:
6603  _z3_assert(isinstance(probe, str), "probe name expected")
6604  try:
6605  self.probe = Z3_mk_probe(self.ctx.ref(), probe)
6606  except Z3Exception:
6607  raise Z3Exception("unknown probe '%s'" % probe)
6608  Z3_probe_inc_ref(self.ctx.ref(), self.probe)
def __del__ (   self)

Definition at line 6609 of file z3py.py.

6610  def __del__(self):
6611  if self.probe != None:
6612  Z3_probe_dec_ref(self.ctx.ref(), self.probe)

Member Function Documentation

def __call__ (   self,
  goal 
)
Evaluate the probe `self` in the given goal.

>>> p = Probe('size')
>>> x = Int('x')
>>> g = Goal()
>>> g.add(x > 0)
>>> g.add(x < 10)
>>> p(g)
2.0
>>> g.add(x < 20)
>>> p(g)
3.0
>>> p = Probe('num-consts')
>>> p(g)
1.0
>>> p = Probe('is-propositional')
>>> p(g)
0.0
>>> p = Probe('is-qflia')
>>> p(g)
1.0

Definition at line 6692 of file z3py.py.

6693  def __call__(self, goal):
6694  """Evaluate the probe `self` in the given goal.
6695 
6696  >>> p = Probe('size')
6697  >>> x = Int('x')
6698  >>> g = Goal()
6699  >>> g.add(x > 0)
6700  >>> g.add(x < 10)
6701  >>> p(g)
6702  2.0
6703  >>> g.add(x < 20)
6704  >>> p(g)
6705  3.0
6706  >>> p = Probe('num-consts')
6707  >>> p(g)
6708  1.0
6709  >>> p = Probe('is-propositional')
6710  >>> p(g)
6711  0.0
6712  >>> p = Probe('is-qflia')
6713  >>> p(g)
6714  1.0
6715  """
6716  if __debug__:
6717  _z3_assert(isinstance(goal, Goal) or isinstance(goal, BoolRef), "Z3 Goal or Boolean expression expected")
6718  goal = _to_goal(goal)
6719  return Z3_probe_apply(self.ctx.ref(), self.probe, goal.goal)
def __eq__ (   self,
  other 
)
Return a probe that evaluates to "true" when the value returned by `self` is equal to the value returned by `other`.

>>> p = Probe('size') == 2
>>> x = Int('x')
>>> g = Goal()
>>> g.add(x > 0)
>>> g.add(x < 10)
>>> p(g)
1.0

Definition at line 6665 of file z3py.py.

Referenced by Probe.__ne__().

6666  def __eq__(self, other):
6667  """Return a probe that evaluates to "true" when the value returned by `self` is equal to the value returned by `other`.
6668 
6669  >>> p = Probe('size') == 2
6670  >>> x = Int('x')
6671  >>> g = Goal()
6672  >>> g.add(x > 0)
6673  >>> g.add(x < 10)
6674  >>> p(g)
6675  1.0
6676  """
6677  return Probe(Z3_probe_eq(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
def __ge__ (   self,
  other 
)
Return a probe that evaluates to "true" when the value returned by `self` is greater than or equal to the value returned by `other`.

>>> p = Probe('size') >= 2
>>> x = Int('x')
>>> g = Goal()
>>> g.add(x > 0)
>>> g.add(x < 10)
>>> p(g)
1.0

Definition at line 6652 of file z3py.py.

6653  def __ge__(self, other):
6654  """Return a probe that evaluates to "true" when the value returned by `self` is greater than or equal to the value returned by `other`.
6655 
6656  >>> p = Probe('size') >= 2
6657  >>> x = Int('x')
6658  >>> g = Goal()
6659  >>> g.add(x > 0)
6660  >>> g.add(x < 10)
6661  >>> p(g)
6662  1.0
6663  """
6664  return Probe(Z3_probe_ge(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
def __gt__ (   self,
  other 
)
Return a probe that evaluates to "true" when the value returned by `self` is greater than the value returned by `other`.

>>> p = Probe('size') > 10
>>> x = Int('x')
>>> g = Goal()
>>> g.add(x > 0)
>>> g.add(x < 10)
>>> p(g)
0.0

Definition at line 6626 of file z3py.py.

6627  def __gt__(self, other):
6628  """Return a probe that evaluates to "true" when the value returned by `self` is greater than the value returned by `other`.
6629 
6630  >>> p = Probe('size') > 10
6631  >>> x = Int('x')
6632  >>> g = Goal()
6633  >>> g.add(x > 0)
6634  >>> g.add(x < 10)
6635  >>> p(g)
6636  0.0
6637  """
6638  return Probe(Z3_probe_gt(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
def __le__ (   self,
  other 
)
Return a probe that evaluates to "true" when the value returned by `self` is less than or equal to the value returned by `other`.

>>> p = Probe('size') <= 2
>>> x = Int('x')
>>> g = Goal()
>>> g.add(x > 0)
>>> g.add(x < 10)
>>> p(g)
1.0

Definition at line 6639 of file z3py.py.

6640  def __le__(self, other):
6641  """Return a probe that evaluates to "true" when the value returned by `self` is less than or equal to the value returned by `other`.
6642 
6643  >>> p = Probe('size') <= 2
6644  >>> x = Int('x')
6645  >>> g = Goal()
6646  >>> g.add(x > 0)
6647  >>> g.add(x < 10)
6648  >>> p(g)
6649  1.0
6650  """
6651  return Probe(Z3_probe_le(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
def __lt__ (   self,
  other 
)
Return a probe that evaluates to "true" when the value returned by `self` is less than the value returned by `other`.

>>> p = Probe('size') < 10
>>> x = Int('x')
>>> g = Goal()
>>> g.add(x > 0)
>>> g.add(x < 10)
>>> p(g)
1.0

Definition at line 6613 of file z3py.py.

6614  def __lt__(self, other):
6615  """Return a probe that evaluates to "true" when the value returned by `self` is less than the value returned by `other`.
6616 
6617  >>> p = Probe('size') < 10
6618  >>> x = Int('x')
6619  >>> g = Goal()
6620  >>> g.add(x > 0)
6621  >>> g.add(x < 10)
6622  >>> p(g)
6623  1.0
6624  """
6625  return Probe(Z3_probe_lt(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
def __ne__ (   self,
  other 
)
Return a probe that evaluates to "true" when the value returned by `self` is not equal to the value returned by `other`.

>>> p = Probe('size') != 2
>>> x = Int('x')
>>> g = Goal()
>>> g.add(x > 0)
>>> g.add(x < 10)
>>> p(g)
0.0

Definition at line 6678 of file z3py.py.

6679  def __ne__(self, other):
6680  """Return a probe that evaluates to "true" when the value returned by `self` is not equal to the value returned by `other`.
6681 
6682  >>> p = Probe('size') != 2
6683  >>> x = Int('x')
6684  >>> g = Goal()
6685  >>> g.add(x > 0)
6686  >>> g.add(x < 10)
6687  >>> p(g)
6688  0.0
6689  """
6690  p = self.__eq__(other)
6691  return Probe(Z3_probe_not(self.ctx.ref(), p.probe), self.ctx)

Field Documentation

ctx

Definition at line 6587 of file z3py.py.

Referenced by Probe.__eq__(), Probe.__ge__(), Probe.__gt__(), Probe.__le__(), Probe.__lt__(), and Probe.__ne__().

probe

Definition at line 6588 of file z3py.py.

Referenced by Probe.__call__(), Probe.__del__(), Probe.__eq__(), Probe.__ge__(), Probe.__gt__(), Probe.__le__(), and Probe.__lt__().