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

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  probe,
  ctx = None 
)

Definition at line 7536 of file z3py.py.

7536  def __init__(self, probe, ctx=None):
7537  self.ctx = _get_ctx(ctx)
7538  self.probe = None
7539  if isinstance(probe, ProbeObj):
7540  self.probe = probe
7541  elif isinstance(probe, float):
7542  self.probe = Z3_probe_const(self.ctx.ref(), probe)
7543  elif _is_int(probe):
7544  self.probe = Z3_probe_const(self.ctx.ref(), float(probe))
7545  elif isinstance(probe, bool):
7546  if probe:
7547  self.probe = Z3_probe_const(self.ctx.ref(), 1.0)
7548  else:
7549  self.probe = Z3_probe_const(self.ctx.ref(), 0.0)
7550  else:
7551  if __debug__:
7552  _z3_assert(isinstance(probe, str), "probe name expected")
7553  try:
7554  self.probe = Z3_mk_probe(self.ctx.ref(), probe)
7555  except Z3Exception:
7556  raise Z3Exception("unknown probe '%s'" % probe)
7557  Z3_probe_inc_ref(self.ctx.ref(), self.probe)
7558 
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 7562 of file z3py.py.

7562  def __del__(self):
7563  if self.probe is not None and self.ctx.ref() is not None:
7564  Z3_probe_dec_ref(self.ctx.ref(), self.probe)
7565 
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 7645 of file z3py.py.

7645  def __call__(self, goal):
7646  """Evaluate the probe `self` in the given goal.
7647 
7648  >>> p = Probe('size')
7649  >>> x = Int('x')
7650  >>> g = Goal()
7651  >>> g.add(x > 0)
7652  >>> g.add(x < 10)
7653  >>> p(g)
7654  2.0
7655  >>> g.add(x < 20)
7656  >>> p(g)
7657  3.0
7658  >>> p = Probe('num-consts')
7659  >>> p(g)
7660  1.0
7661  >>> p = Probe('is-propositional')
7662  >>> p(g)
7663  0.0
7664  >>> p = Probe('is-qflia')
7665  >>> p(g)
7666  1.0
7667  """
7668  if __debug__:
7669  _z3_assert(isinstance(goal, Goal) or isinstance(goal, BoolRef), "Z3 Goal or Boolean expression expected")
7670  goal = _to_goal(goal)
7671  return Z3_probe_apply(self.ctx.ref(), self.probe, goal.goal)
7672 
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 7559 of file z3py.py.

7559  def __deepcopy__(self, memo={}):
7560  return Probe(self.probe, self.ctx)
7561 

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

Referenced by Probe.__ne__().

7618  def __eq__(self, other):
7619  """Return a probe that evaluates to "true" when the value returned by `self` is equal to the value returned by `other`.
7620 
7621  >>> p = Probe('size') == 2
7622  >>> x = Int('x')
7623  >>> g = Goal()
7624  >>> g.add(x > 0)
7625  >>> g.add(x < 10)
7626  >>> p(g)
7627  1.0
7628  """
7629  return Probe(Z3_probe_eq(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
7630 
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 7605 of file z3py.py.

7605  def __ge__(self, other):
7606  """Return a probe that evaluates to "true" when the value returned by `self` is greater than or equal to the value returned by `other`.
7607 
7608  >>> p = Probe('size') >= 2
7609  >>> x = Int('x')
7610  >>> g = Goal()
7611  >>> g.add(x > 0)
7612  >>> g.add(x < 10)
7613  >>> p(g)
7614  1.0
7615  """
7616  return Probe(Z3_probe_ge(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
7617 
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 7579 of file z3py.py.

7579  def __gt__(self, other):
7580  """Return a probe that evaluates to "true" when the value returned by `self` is greater than the value returned by `other`.
7581 
7582  >>> p = Probe('size') > 10
7583  >>> x = Int('x')
7584  >>> g = Goal()
7585  >>> g.add(x > 0)
7586  >>> g.add(x < 10)
7587  >>> p(g)
7588  0.0
7589  """
7590  return Probe(Z3_probe_gt(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
7591 
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 7592 of file z3py.py.

7592  def __le__(self, other):
7593  """Return a probe that evaluates to "true" when the value returned by `self` is less than or equal to the value returned by `other`.
7594 
7595  >>> p = Probe('size') <= 2
7596  >>> x = Int('x')
7597  >>> g = Goal()
7598  >>> g.add(x > 0)
7599  >>> g.add(x < 10)
7600  >>> p(g)
7601  1.0
7602  """
7603  return Probe(Z3_probe_le(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
7604 
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 7566 of file z3py.py.

7566  def __lt__(self, other):
7567  """Return a probe that evaluates to "true" when the value returned by `self` is less than the value returned by `other`.
7568 
7569  >>> p = Probe('size') < 10
7570  >>> x = Int('x')
7571  >>> g = Goal()
7572  >>> g.add(x > 0)
7573  >>> g.add(x < 10)
7574  >>> p(g)
7575  1.0
7576  """
7577  return Probe(Z3_probe_lt(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
7578 
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 7631 of file z3py.py.

7631  def __ne__(self, other):
7632  """Return a probe that evaluates to "true" when the value returned by `self` is not equal to the value returned by `other`.
7633 
7634  >>> p = Probe('size') != 2
7635  >>> x = Int('x')
7636  >>> g = Goal()
7637  >>> g.add(x > 0)
7638  >>> g.add(x < 10)
7639  >>> p(g)
7640  0.0
7641  """
7642  p = self.__eq__(other)
7643  return Probe(Z3_probe_not(self.ctx.ref(), p.probe), self.ctx)
7644 
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