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

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  probe,
  ctx = None 
)

Definition at line 7967 of file z3py.py.

7967  def __init__(self, probe, ctx=None):
7968  self.ctx = _get_ctx(ctx)
7969  self.probe = None
7970  if isinstance(probe, ProbeObj):
7971  self.probe = probe
7972  elif isinstance(probe, float):
7973  self.probe = Z3_probe_const(self.ctx.ref(), probe)
7974  elif _is_int(probe):
7975  self.probe = Z3_probe_const(self.ctx.ref(), float(probe))
7976  elif isinstance(probe, bool):
7977  if probe:
7978  self.probe = Z3_probe_const(self.ctx.ref(), 1.0)
7979  else:
7980  self.probe = Z3_probe_const(self.ctx.ref(), 0.0)
7981  else:
7982  if z3_debug():
7983  _z3_assert(isinstance(probe, str), "probe name expected")
7984  try:
7985  self.probe = Z3_mk_probe(self.ctx.ref(), probe)
7986  except Z3Exception:
7987  raise Z3Exception("unknown probe '%s'" % probe)
7988  Z3_probe_inc_ref(self.ctx.ref(), self.probe)
7989 

◆ __del__()

def __del__ (   self)

Definition at line 7993 of file z3py.py.

7993  def __del__(self):
7994  if self.probe is not None and self.ctx.ref() is not None:
7995  Z3_probe_dec_ref(self.ctx.ref(), self.probe)
7996 

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

8076  def __call__(self, goal):
8077  """Evaluate the probe `self` in the given goal.
8078 
8079  >>> p = Probe('size')
8080  >>> x = Int('x')
8081  >>> g = Goal()
8082  >>> g.add(x > 0)
8083  >>> g.add(x < 10)
8084  >>> p(g)
8085  2.0
8086  >>> g.add(x < 20)
8087  >>> p(g)
8088  3.0
8089  >>> p = Probe('num-consts')
8090  >>> p(g)
8091  1.0
8092  >>> p = Probe('is-propositional')
8093  >>> p(g)
8094  0.0
8095  >>> p = Probe('is-qflia')
8096  >>> p(g)
8097  1.0
8098  """
8099  if z3_debug():
8100  _z3_assert(isinstance(goal, Goal) or isinstance(goal, BoolRef), "Z3 Goal or Boolean expression expected")
8101  goal = _to_goal(goal)
8102  return Z3_probe_apply(self.ctx.ref(), self.probe, goal.goal)
8103 

◆ __deepcopy__()

def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 7990 of file z3py.py.

7990  def __deepcopy__(self, memo={}):
7991  return Probe(self.probe, self.ctx)
7992 

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

8049  def __eq__(self, other):
8050  """Return a probe that evaluates to "true" when the value returned by `self` is equal to the value returned by `other`.
8051 
8052  >>> p = Probe('size') == 2
8053  >>> x = Int('x')
8054  >>> g = Goal()
8055  >>> g.add(x > 0)
8056  >>> g.add(x < 10)
8057  >>> p(g)
8058  1.0
8059  """
8060  return Probe(Z3_probe_eq(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
8061 

Referenced by Probe.__ne__().

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

8036  def __ge__(self, other):
8037  """Return a probe that evaluates to "true" when the value returned by `self` is greater than or equal to the value returned by `other`.
8038 
8039  >>> p = Probe('size') >= 2
8040  >>> x = Int('x')
8041  >>> g = Goal()
8042  >>> g.add(x > 0)
8043  >>> g.add(x < 10)
8044  >>> p(g)
8045  1.0
8046  """
8047  return Probe(Z3_probe_ge(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
8048 

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

8010  def __gt__(self, other):
8011  """Return a probe that evaluates to "true" when the value returned by `self` is greater than the value returned by `other`.
8012 
8013  >>> p = Probe('size') > 10
8014  >>> x = Int('x')
8015  >>> g = Goal()
8016  >>> g.add(x > 0)
8017  >>> g.add(x < 10)
8018  >>> p(g)
8019  0.0
8020  """
8021  return Probe(Z3_probe_gt(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
8022 

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

8023  def __le__(self, other):
8024  """Return a probe that evaluates to "true" when the value returned by `self` is less than or equal to the value returned by `other`.
8025 
8026  >>> p = Probe('size') <= 2
8027  >>> x = Int('x')
8028  >>> g = Goal()
8029  >>> g.add(x > 0)
8030  >>> g.add(x < 10)
8031  >>> p(g)
8032  1.0
8033  """
8034  return Probe(Z3_probe_le(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
8035 

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

7997  def __lt__(self, other):
7998  """Return a probe that evaluates to "true" when the value returned by `self` is less than the value returned by `other`.
7999 
8000  >>> p = Probe('size') < 10
8001  >>> x = Int('x')
8002  >>> g = Goal()
8003  >>> g.add(x > 0)
8004  >>> g.add(x < 10)
8005  >>> p(g)
8006  1.0
8007  """
8008  return Probe(Z3_probe_lt(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
8009 

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

8062  def __ne__(self, other):
8063  """Return a probe that evaluates to "true" when the value returned by `self` is not equal to the value returned by `other`.
8064 
8065  >>> p = Probe('size') != 2
8066  >>> x = Int('x')
8067  >>> g = Goal()
8068  >>> g.add(x > 0)
8069  >>> g.add(x < 10)
8070  >>> p(g)
8071  0.0
8072  """
8073  p = self.__eq__(other)
8074  return Probe(Z3_probe_not(self.ctx.ref(), p.probe), self.ctx)
8075 

Field Documentation

◆ ctx

ctx

◆ probe

probe
z3py.UserPropagateBase.__init__
def __init__(self, s, ctx=None)
Definition: z3py.py:10582
Z3_probe_dec_ref
void Z3_API Z3_probe_dec_ref(Z3_context c, Z3_probe p)
Decrement the reference counter of the given probe.
Z3_probe_le
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...
Z3_probe_const
Z3_probe Z3_API Z3_probe_const(Z3_context x, double val)
Return a probe that always evaluates to val.
z3py.UserPropagateBase.__del__
def __del__(self)
Definition: z3py.py:10607
Z3_probe_inc_ref
void Z3_API Z3_probe_inc_ref(Z3_context c, Z3_probe p)
Increment the reference counter of the given probe.
z3py.z3_debug
def z3_debug()
Definition: z3py.py:56
Z3_probe_ge
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...
Z3_probe_eq
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 ...
Z3_probe_apply
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....
Z3_probe_lt
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...
Z3_mk_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 ...
Z3_probe_not
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.
Z3_probe_gt
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...