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

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  probe,
  ctx = None 
)

Definition at line 7829 of file z3py.py.

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

7855  def __del__(self):
7856  if self.probe is not None and self.ctx.ref() is not None:
7857  Z3_probe_dec_ref(self.ctx.ref(), self.probe)
7858 
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 7938 of file z3py.py.

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

7852  def __deepcopy__(self, memo={}):
7853  return Probe(self.probe, self.ctx)
7854 

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

Referenced by Probe.__ne__().

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

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

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

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

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

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