Z3
Public Member Functions | Data Fields
Probe Class Reference

Public Member Functions

def __init__ (self, probe, ctx=None)
 
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 7212 of file z3py.py.

Constructor & Destructor Documentation

§ __init__()

def __init__ (   self,
  probe,
  ctx = None 
)

Definition at line 7214 of file z3py.py.

7214  def __init__(self, probe, ctx=None):
7215  self.ctx = _get_ctx(ctx)
7216  self.probe = None
7217  if isinstance(probe, ProbeObj):
7218  self.probe = probe
7219  elif isinstance(probe, float):
7220  self.probe = Z3_probe_const(self.ctx.ref(), probe)
7221  elif _is_int(probe):
7222  self.probe = Z3_probe_const(self.ctx.ref(), float(probe))
7223  elif isinstance(probe, bool):
7224  if probe:
7225  self.probe = Z3_probe_const(self.ctx.ref(), 1.0)
7226  else:
7227  self.probe = Z3_probe_const(self.ctx.ref(), 0.0)
7228  else:
7229  if __debug__:
7230  _z3_assert(isinstance(probe, str), "probe name expected")
7231  try:
7232  self.probe = Z3_mk_probe(self.ctx.ref(), probe)
7233  except Z3Exception:
7234  raise Z3Exception("unknown probe '%s'" % probe)
7235  Z3_probe_inc_ref(self.ctx.ref(), self.probe)
7236 
Z3_probe Z3_API Z3_probe_const(Z3_context x, double val)
Return a probe that always evaluates to val.
void Z3_API Z3_probe_inc_ref(Z3_context c, Z3_probe p)
Increment the reference counter of the given probe.
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 ...

§ __del__()

def __del__ (   self)

Definition at line 7237 of file z3py.py.

7237  def __del__(self):
7238  if self.probe is not None and self.ctx.ref() is not None:
7239  Z3_probe_dec_ref(self.ctx.ref(), self.probe)
7240 
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 7320 of file z3py.py.

7320  def __call__(self, goal):
7321  """Evaluate the probe `self` in the given goal.
7322 
7323  >>> p = Probe('size')
7324  >>> x = Int('x')
7325  >>> g = Goal()
7326  >>> g.add(x > 0)
7327  >>> g.add(x < 10)
7328  >>> p(g)
7329  2.0
7330  >>> g.add(x < 20)
7331  >>> p(g)
7332  3.0
7333  >>> p = Probe('num-consts')
7334  >>> p(g)
7335  1.0
7336  >>> p = Probe('is-propositional')
7337  >>> p(g)
7338  0.0
7339  >>> p = Probe('is-qflia')
7340  >>> p(g)
7341  1.0
7342  """
7343  if __debug__:
7344  _z3_assert(isinstance(goal, Goal) or isinstance(goal, BoolRef), "Z3 Goal or Boolean expression expected")
7345  goal = _to_goal(goal)
7346  return Z3_probe_apply(self.ctx.ref(), self.probe, goal.goal)
7347 
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...

§ __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 7293 of file z3py.py.

Referenced by Probe.__ne__().

7293  def __eq__(self, other):
7294  """Return a probe that evaluates to "true" when the value returned by `self` is equal to the value returned by `other`.
7295 
7296  >>> p = Probe('size') == 2
7297  >>> x = Int('x')
7298  >>> g = Goal()
7299  >>> g.add(x > 0)
7300  >>> g.add(x < 10)
7301  >>> p(g)
7302  1.0
7303  """
7304  return Probe(Z3_probe_eq(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
7305 
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 7280 of file z3py.py.

7280  def __ge__(self, other):
7281  """Return a probe that evaluates to "true" when the value returned by `self` is greater than or equal to the value returned by `other`.
7282 
7283  >>> p = Probe('size') >= 2
7284  >>> x = Int('x')
7285  >>> g = Goal()
7286  >>> g.add(x > 0)
7287  >>> g.add(x < 10)
7288  >>> p(g)
7289  1.0
7290  """
7291  return Probe(Z3_probe_ge(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
7292 
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 7254 of file z3py.py.

7254  def __gt__(self, other):
7255  """Return a probe that evaluates to "true" when the value returned by `self` is greater than the value returned by `other`.
7256 
7257  >>> p = Probe('size') > 10
7258  >>> x = Int('x')
7259  >>> g = Goal()
7260  >>> g.add(x > 0)
7261  >>> g.add(x < 10)
7262  >>> p(g)
7263  0.0
7264  """
7265  return Probe(Z3_probe_gt(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
7266 
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 7267 of file z3py.py.

7267  def __le__(self, other):
7268  """Return a probe that evaluates to "true" when the value returned by `self` is less than or equal to the value returned by `other`.
7269 
7270  >>> p = Probe('size') <= 2
7271  >>> x = Int('x')
7272  >>> g = Goal()
7273  >>> g.add(x > 0)
7274  >>> g.add(x < 10)
7275  >>> p(g)
7276  1.0
7277  """
7278  return Probe(Z3_probe_le(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
7279 
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 7241 of file z3py.py.

7241  def __lt__(self, other):
7242  """Return a probe that evaluates to "true" when the value returned by `self` is less than the value returned by `other`.
7243 
7244  >>> p = Probe('size') < 10
7245  >>> x = Int('x')
7246  >>> g = Goal()
7247  >>> g.add(x > 0)
7248  >>> g.add(x < 10)
7249  >>> p(g)
7250  1.0
7251  """
7252  return Probe(Z3_probe_lt(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
7253 
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 7306 of file z3py.py.

7306  def __ne__(self, other):
7307  """Return a probe that evaluates to "true" when the value returned by `self` is not equal to the value returned by `other`.
7308 
7309  >>> p = Probe('size') != 2
7310  >>> x = Int('x')
7311  >>> g = Goal()
7312  >>> g.add(x > 0)
7313  >>> g.add(x < 10)
7314  >>> p(g)
7315  0.0
7316  """
7317  p = self.__eq__(other)
7318  return Probe(Z3_probe_not(self.ctx.ref(), p.probe), self.ctx)
7319 
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