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

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  probe,
  ctx = None 
)

Definition at line 7823 of file z3py.py.

7823  def __init__(self, probe, ctx=None):
7824  self.ctx = _get_ctx(ctx)
7825  self.probe = None
7826  if isinstance(probe, ProbeObj):
7827  self.probe = probe
7828  elif isinstance(probe, float):
7829  self.probe = Z3_probe_const(self.ctx.ref(), probe)
7830  elif _is_int(probe):
7831  self.probe = Z3_probe_const(self.ctx.ref(), float(probe))
7832  elif isinstance(probe, bool):
7833  if probe:
7834  self.probe = Z3_probe_const(self.ctx.ref(), 1.0)
7835  else:
7836  self.probe = Z3_probe_const(self.ctx.ref(), 0.0)
7837  else:
7838  if __debug__:
7839  _z3_assert(isinstance(probe, str), "probe name expected")
7840  try:
7841  self.probe = Z3_mk_probe(self.ctx.ref(), probe)
7842  except Z3Exception:
7843  raise Z3Exception("unknown probe '%s'" % probe)
7844  Z3_probe_inc_ref(self.ctx.ref(), self.probe)
7845 
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 7849 of file z3py.py.

7849  def __del__(self):
7850  if self.probe is not None and self.ctx.ref() is not None:
7851  Z3_probe_dec_ref(self.ctx.ref(), self.probe)
7852 
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 7932 of file z3py.py.

7932  def __call__(self, goal):
7933  """Evaluate the probe `self` in the given goal.
7934 
7935  >>> p = Probe('size')
7936  >>> x = Int('x')
7937  >>> g = Goal()
7938  >>> g.add(x > 0)
7939  >>> g.add(x < 10)
7940  >>> p(g)
7941  2.0
7942  >>> g.add(x < 20)
7943  >>> p(g)
7944  3.0
7945  >>> p = Probe('num-consts')
7946  >>> p(g)
7947  1.0
7948  >>> p = Probe('is-propositional')
7949  >>> p(g)
7950  0.0
7951  >>> p = Probe('is-qflia')
7952  >>> p(g)
7953  1.0
7954  """
7955  if __debug__:
7956  _z3_assert(isinstance(goal, Goal) or isinstance(goal, BoolRef), "Z3 Goal or Boolean expression expected")
7957  goal = _to_goal(goal)
7958  return Z3_probe_apply(self.ctx.ref(), self.probe, goal.goal)
7959 
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 7846 of file z3py.py.

7846  def __deepcopy__(self, memo={}):
7847  return Probe(self.probe, self.ctx)
7848 

◆ __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 7905 of file z3py.py.

Referenced by Probe.__ne__().

7905  def __eq__(self, other):
7906  """Return a probe that evaluates to "true" when the value returned by `self` is equal to the value returned by `other`.
7907 
7908  >>> p = Probe('size') == 2
7909  >>> x = Int('x')
7910  >>> g = Goal()
7911  >>> g.add(x > 0)
7912  >>> g.add(x < 10)
7913  >>> p(g)
7914  1.0
7915  """
7916  return Probe(Z3_probe_eq(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
7917 
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 7892 of file z3py.py.

7892  def __ge__(self, other):
7893  """Return a probe that evaluates to "true" when the value returned by `self` is greater than or equal to the value returned by `other`.
7894 
7895  >>> p = Probe('size') >= 2
7896  >>> x = Int('x')
7897  >>> g = Goal()
7898  >>> g.add(x > 0)
7899  >>> g.add(x < 10)
7900  >>> p(g)
7901  1.0
7902  """
7903  return Probe(Z3_probe_ge(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
7904 
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 7866 of file z3py.py.

7866  def __gt__(self, other):
7867  """Return a probe that evaluates to "true" when the value returned by `self` is greater than the value returned by `other`.
7868 
7869  >>> p = Probe('size') > 10
7870  >>> x = Int('x')
7871  >>> g = Goal()
7872  >>> g.add(x > 0)
7873  >>> g.add(x < 10)
7874  >>> p(g)
7875  0.0
7876  """
7877  return Probe(Z3_probe_gt(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
7878 
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 7879 of file z3py.py.

7879  def __le__(self, other):
7880  """Return a probe that evaluates to "true" when the value returned by `self` is less than or equal to the value returned by `other`.
7881 
7882  >>> p = Probe('size') <= 2
7883  >>> x = Int('x')
7884  >>> g = Goal()
7885  >>> g.add(x > 0)
7886  >>> g.add(x < 10)
7887  >>> p(g)
7888  1.0
7889  """
7890  return Probe(Z3_probe_le(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
7891 
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 7853 of file z3py.py.

7853  def __lt__(self, other):
7854  """Return a probe that evaluates to "true" when the value returned by `self` is less than the value returned by `other`.
7855 
7856  >>> p = Probe('size') < 10
7857  >>> x = Int('x')
7858  >>> g = Goal()
7859  >>> g.add(x > 0)
7860  >>> g.add(x < 10)
7861  >>> p(g)
7862  1.0
7863  """
7864  return Probe(Z3_probe_lt(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
7865 
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 7918 of file z3py.py.

7918  def __ne__(self, other):
7919  """Return a probe that evaluates to "true" when the value returned by `self` is not equal to the value returned by `other`.
7920 
7921  >>> p = Probe('size') != 2
7922  >>> x = Int('x')
7923  >>> g = Goal()
7924  >>> g.add(x > 0)
7925  >>> g.add(x < 10)
7926  >>> p(g)
7927  0.0
7928  """
7929  p = self.__eq__(other)
7930  return Probe(Z3_probe_not(self.ctx.ref(), p.probe), self.ctx)
7931 
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