Z3
Public Member Functions | Data Fields
Probe Class Reference

Public Member Functions

def __init__ (self, probe, ctx=None)
 
def __deepcopy__ (self, memo={})
 
def __del__ (self)
 
def __lt__ (self, other)
 
def __gt__ (self, other)
 
def __le__ (self, other)
 
def __ge__ (self, other)
 
def __eq__ (self, other)
 
def __ne__ (self, other)
 
def __call__ (self, goal)
 

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

Constructor & Destructor Documentation

§ __init__()

def __init__ (   self,
  probe,
  ctx = None 
)

Definition at line 7455 of file z3py.py.

7455  def __init__(self, probe, ctx=None):
7456  self.ctx = _get_ctx(ctx)
7457  self.probe = None
7458  if isinstance(probe, ProbeObj):
7459  self.probe = probe
7460  elif isinstance(probe, float):
7461  self.probe = Z3_probe_const(self.ctx.ref(), probe)
7462  elif _is_int(probe):
7463  self.probe = Z3_probe_const(self.ctx.ref(), float(probe))
7464  elif isinstance(probe, bool):
7465  if probe:
7466  self.probe = Z3_probe_const(self.ctx.ref(), 1.0)
7467  else:
7468  self.probe = Z3_probe_const(self.ctx.ref(), 0.0)
7469  else:
7470  if __debug__:
7471  _z3_assert(isinstance(probe, str), "probe name expected")
7472  try:
7473  self.probe = Z3_mk_probe(self.ctx.ref(), probe)
7474  except Z3Exception:
7475  raise Z3Exception("unknown probe '%s'" % probe)
7476  Z3_probe_inc_ref(self.ctx.ref(), self.probe)
7477 
Z3_probe Z3_API Z3_probe_const(Z3_context x, double val)
Return a probe that always evaluates to val.
Z3_probe Z3_API Z3_mk_probe(Z3_context c, Z3_string name)
Return a probe associated with the given name. The complete list of probes may be obtained using the ...
void Z3_API Z3_probe_inc_ref(Z3_context c, Z3_probe p)
Increment the reference counter of the given probe.

§ __del__()

def __del__ (   self)

Definition at line 7481 of file z3py.py.

7481  def __del__(self):
7482  if self.probe is not None and self.ctx.ref() is not None:
7483  Z3_probe_dec_ref(self.ctx.ref(), self.probe)
7484 
void Z3_API Z3_probe_dec_ref(Z3_context c, Z3_probe p)
Decrement the reference counter of the given probe.

Member Function Documentation

§ __call__()

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

7564  def __call__(self, goal):
7565  """Evaluate the probe `self` in the given goal.
7566 
7567  >>> p = Probe('size')
7568  >>> x = Int('x')
7569  >>> g = Goal()
7570  >>> g.add(x > 0)
7571  >>> g.add(x < 10)
7572  >>> p(g)
7573  2.0
7574  >>> g.add(x < 20)
7575  >>> p(g)
7576  3.0
7577  >>> p = Probe('num-consts')
7578  >>> p(g)
7579  1.0
7580  >>> p = Probe('is-propositional')
7581  >>> p(g)
7582  0.0
7583  >>> p = Probe('is-qflia')
7584  >>> p(g)
7585  1.0
7586  """
7587  if __debug__:
7588  _z3_assert(isinstance(goal, Goal) or isinstance(goal, BoolRef), "Z3 Goal or Boolean expression expected")
7589  goal = _to_goal(goal)
7590  return Z3_probe_apply(self.ctx.ref(), self.probe, goal.goal)
7591 
double Z3_API Z3_probe_apply(Z3_context c, Z3_probe p, Z3_goal g)
Execute the probe over the goal. The probe always produce a double value. "Boolean" probes return 0...

§ __deepcopy__()

def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 7478 of file z3py.py.

7478  def __deepcopy__(self, memo={}):
7479  return Probe(self.probe, self.ctx)
7480 

§ __eq__()

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

Referenced by Probe.__ne__().

7537  def __eq__(self, other):
7538  """Return a probe that evaluates to "true" when the value returned by `self` is equal to the value returned by `other`.
7539 
7540  >>> p = Probe('size') == 2
7541  >>> x = Int('x')
7542  >>> g = Goal()
7543  >>> g.add(x > 0)
7544  >>> g.add(x < 10)
7545  >>> p(g)
7546  1.0
7547  """
7548  return Probe(Z3_probe_eq(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
7549 
Z3_probe Z3_API Z3_probe_eq(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is equal to the value returned ...

§ __ge__()

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

7524  def __ge__(self, other):
7525  """Return a probe that evaluates to "true" when the value returned by `self` is greater than or equal to the value returned by `other`.
7526 
7527  >>> p = Probe('size') >= 2
7528  >>> x = Int('x')
7529  >>> g = Goal()
7530  >>> g.add(x > 0)
7531  >>> g.add(x < 10)
7532  >>> p(g)
7533  1.0
7534  """
7535  return Probe(Z3_probe_ge(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
7536 
Z3_probe Z3_API Z3_probe_ge(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is greater than or equal to the...

§ __gt__()

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

7498  def __gt__(self, other):
7499  """Return a probe that evaluates to "true" when the value returned by `self` is greater than the value returned by `other`.
7500 
7501  >>> p = Probe('size') > 10
7502  >>> x = Int('x')
7503  >>> g = Goal()
7504  >>> g.add(x > 0)
7505  >>> g.add(x < 10)
7506  >>> p(g)
7507  0.0
7508  """
7509  return Probe(Z3_probe_gt(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
7510 
Z3_probe Z3_API Z3_probe_gt(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is greater than the value retur...

§ __le__()

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

7511  def __le__(self, other):
7512  """Return a probe that evaluates to "true" when the value returned by `self` is less than or equal to the value returned by `other`.
7513 
7514  >>> p = Probe('size') <= 2
7515  >>> x = Int('x')
7516  >>> g = Goal()
7517  >>> g.add(x > 0)
7518  >>> g.add(x < 10)
7519  >>> p(g)
7520  1.0
7521  """
7522  return Probe(Z3_probe_le(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
7523 
Z3_probe Z3_API Z3_probe_le(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is less than or equal to the va...

§ __lt__()

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

7485  def __lt__(self, other):
7486  """Return a probe that evaluates to "true" when the value returned by `self` is less than the value returned by `other`.
7487 
7488  >>> p = Probe('size') < 10
7489  >>> x = Int('x')
7490  >>> g = Goal()
7491  >>> g.add(x > 0)
7492  >>> g.add(x < 10)
7493  >>> p(g)
7494  1.0
7495  """
7496  return Probe(Z3_probe_lt(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
7497 
Z3_probe Z3_API Z3_probe_lt(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is less than the value returned...

§ __ne__()

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

7550  def __ne__(self, other):
7551  """Return a probe that evaluates to "true" when the value returned by `self` is not equal to the value returned by `other`.
7552 
7553  >>> p = Probe('size') != 2
7554  >>> x = Int('x')
7555  >>> g = Goal()
7556  >>> g.add(x > 0)
7557  >>> g.add(x < 10)
7558  >>> p(g)
7559  0.0
7560  """
7561  p = self.__eq__(other)
7562  return Probe(Z3_probe_not(self.ctx.ref(), p.probe), self.ctx)
7563 
Z3_probe Z3_API Z3_probe_not(Z3_context x, Z3_probe p)
Return a probe that evaluates to "true" when p does not evaluate to true.

Field Documentation

§ ctx

ctx

§ probe

probe