Z3
Loading...
Searching...
No Matches
Probe Class Reference

Public Member Functions

 __init__ (self, probe, ctx=None)
 __deepcopy__ (self, memo={})
 __del__ (self)
 __lt__ (self, other)
 __gt__ (self, other)
 __le__ (self, other)
 __ge__ (self, other)
 __eq__ (self, other)
 __ne__ (self, other)
 __call__ (self, goal)

Data Fields

 ctx = _get_ctx(ctx)
 probe = None

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

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
probe,
ctx = None )

Definition at line 8752 of file z3py.py.

8752 def __init__(self, probe, ctx=None):
8753 self.ctx = _get_ctx(ctx)
8754 self.probe = None
8755 if isinstance(probe, ProbeObj):
8756 self.probe = probe
8757 elif isinstance(probe, float):
8758 self.probe = Z3_probe_const(self.ctx.ref(), probe)
8759 elif _is_int(probe):
8760 self.probe = Z3_probe_const(self.ctx.ref(), float(probe))
8761 elif isinstance(probe, bool):
8762 if probe:
8763 self.probe = Z3_probe_const(self.ctx.ref(), 1.0)
8764 else:
8765 self.probe = Z3_probe_const(self.ctx.ref(), 0.0)
8766 else:
8767 if z3_debug():
8768 _z3_assert(isinstance(probe, str), "probe name expected")
8769 try:
8770 self.probe = Z3_mk_probe(self.ctx.ref(), probe)
8771 except Z3Exception:
8772 raise Z3Exception("unknown probe '%s'" % probe)
8773 Z3_probe_inc_ref(self.ctx.ref(), self.probe)
8774
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.
Z3_probe Z3_API Z3_probe_const(Z3_context x, double val)
Return a probe that always evaluates to val.

◆ __del__()

__del__ ( self)

Definition at line 8778 of file z3py.py.

8778 def __del__(self):
8779 if self.probe is not None and self.ctx.ref() is not None and Z3_probe_dec_ref is not None:
8780 Z3_probe_dec_ref(self.ctx.ref(), self.probe)
8781
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__()

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

8867 def __call__(self, goal):
8868 """Evaluate the probe `self` in the given goal.
8869
8870 >>> p = Probe('size')
8871 >>> x = Int('x')
8872 >>> g = Goal()
8873 >>> g.add(x > 0)
8874 >>> g.add(x < 10)
8875 >>> p(g)
8876 2.0
8877 >>> g.add(x < 20)
8878 >>> p(g)
8879 3.0
8880 >>> p = Probe('num-consts')
8881 >>> p(g)
8882 1.0
8883 >>> p = Probe('is-propositional')
8884 >>> p(g)
8885 0.0
8886 >>> p = Probe('is-qflia')
8887 >>> p(g)
8888 1.0
8889 """
8890 if z3_debug():
8891 _z3_assert(isinstance(goal, (Goal, BoolRef)), "Z3 Goal or Boolean expression expected")
8892 goal = _to_goal(goal)
8893 return Z3_probe_apply(self.ctx.ref(), self.probe, goal.goal)
8894
8895
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__()

__deepcopy__ ( self,
memo = {} )

Definition at line 8775 of file z3py.py.

8775 def __deepcopy__(self, memo={}):
8776 return Probe(self.probe, self.ctx)
8777

◆ __eq__()

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

8838 def __eq__(self, other):
8839 """Return a probe that evaluates to "true" when the value returned by `self`
8840 is equal to the value returned by `other`.
8841
8842 >>> p = Probe('size') == 2
8843 >>> x = Int('x')
8844 >>> g = Goal()
8845 >>> g.add(x > 0)
8846 >>> g.add(x < 10)
8847 >>> p(g)
8848 1.0
8849 """
8850 return Probe(Z3_probe_eq(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
8851
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__()

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

8824 def __ge__(self, other):
8825 """Return a probe that evaluates to "true" when the value returned by `self`
8826 is greater than or equal to the value returned by `other`.
8827
8828 >>> p = Probe('size') >= 2
8829 >>> x = Int('x')
8830 >>> g = Goal()
8831 >>> g.add(x > 0)
8832 >>> g.add(x < 10)
8833 >>> p(g)
8834 1.0
8835 """
8836 return Probe(Z3_probe_ge(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
8837
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__()

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

8796 def __gt__(self, other):
8797 """Return a probe that evaluates to "true" when the value returned by `self`
8798 is greater than the value returned by `other`.
8799
8800 >>> p = Probe('size') > 10
8801 >>> x = Int('x')
8802 >>> g = Goal()
8803 >>> g.add(x > 0)
8804 >>> g.add(x < 10)
8805 >>> p(g)
8806 0.0
8807 """
8808 return Probe(Z3_probe_gt(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
8809
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__()

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

8810 def __le__(self, other):
8811 """Return a probe that evaluates to "true" when the value returned by `self`
8812 is less than or equal to the value returned by `other`.
8813
8814 >>> p = Probe('size') <= 2
8815 >>> x = Int('x')
8816 >>> g = Goal()
8817 >>> g.add(x > 0)
8818 >>> g.add(x < 10)
8819 >>> p(g)
8820 1.0
8821 """
8822 return Probe(Z3_probe_le(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
8823
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__()

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

8782 def __lt__(self, other):
8783 """Return a probe that evaluates to "true" when the value returned by `self`
8784 is less than the value returned by `other`.
8785
8786 >>> p = Probe('size') < 10
8787 >>> x = Int('x')
8788 >>> g = Goal()
8789 >>> g.add(x > 0)
8790 >>> g.add(x < 10)
8791 >>> p(g)
8792 1.0
8793 """
8794 return Probe(Z3_probe_lt(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
8795
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__()

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

8852 def __ne__(self, other):
8853 """Return a probe that evaluates to "true" when the value returned by `self`
8854 is not equal to the value returned by `other`.
8855
8856 >>> p = Probe('size') != 2
8857 >>> x = Int('x')
8858 >>> g = Goal()
8859 >>> g.add(x > 0)
8860 >>> g.add(x < 10)
8861 >>> p(g)
8862 0.0
8863 """
8864 p = self.__eq__(other)
8865 return Probe(Z3_probe_not(self.ctx.ref(), p.probe), self.ctx)
8866
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 = _get_ctx(ctx)

Definition at line 8753 of file z3py.py.

◆ probe

probe = None

Definition at line 8754 of file z3py.py.