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

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
probe,
ctx = None )

Definition at line 8847 of file z3py.py.

8847 def __init__(self, probe, ctx=None):
8848 self.ctx = _get_ctx(ctx)
8849 self.probe = None
8850 if isinstance(probe, ProbeObj):
8851 self.probe = probe
8852 elif isinstance(probe, float):
8853 self.probe = Z3_probe_const(self.ctx.ref(), probe)
8854 elif _is_int(probe):
8855 self.probe = Z3_probe_const(self.ctx.ref(), float(probe))
8856 elif isinstance(probe, bool):
8857 if probe:
8858 self.probe = Z3_probe_const(self.ctx.ref(), 1.0)
8859 else:
8860 self.probe = Z3_probe_const(self.ctx.ref(), 0.0)
8861 else:
8862 if z3_debug():
8863 _z3_assert(isinstance(probe, str), "probe name expected")
8864 try:
8865 self.probe = Z3_mk_probe(self.ctx.ref(), probe)
8866 except Z3Exception:
8867 raise Z3Exception("unknown probe '%s'" % probe)
8868 Z3_probe_inc_ref(self.ctx.ref(), self.probe)
8869
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 8873 of file z3py.py.

8873 def __del__(self):
8874 if self.probe is not None and self.ctx.ref() is not None and Z3_probe_dec_ref is not None:
8875 Z3_probe_dec_ref(self.ctx.ref(), self.probe)
8876
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 8962 of file z3py.py.

8962 def __call__(self, goal):
8963 """Evaluate the probe `self` in the given goal.
8964
8965 >>> p = Probe('size')
8966 >>> x = Int('x')
8967 >>> g = Goal()
8968 >>> g.add(x > 0)
8969 >>> g.add(x < 10)
8970 >>> p(g)
8971 2.0
8972 >>> g.add(x < 20)
8973 >>> p(g)
8974 3.0
8975 >>> p = Probe('num-consts')
8976 >>> p(g)
8977 1.0
8978 >>> p = Probe('is-propositional')
8979 >>> p(g)
8980 0.0
8981 >>> p = Probe('is-qflia')
8982 >>> p(g)
8983 1.0
8984 """
8985 if z3_debug():
8986 _z3_assert(isinstance(goal, (Goal, BoolRef)), "Z3 Goal or Boolean expression expected")
8987 goal = _to_goal(goal)
8988 return Z3_probe_apply(self.ctx.ref(), self.probe, goal.goal)
8989
8990
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 8870 of file z3py.py.

8870 def __deepcopy__(self, memo={}):
8871 return Probe(self.probe, self.ctx)
8872

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

8933 def __eq__(self, other):
8934 """Return a probe that evaluates to "true" when the value returned by `self`
8935 is equal to the value returned by `other`.
8936
8937 >>> p = Probe('size') == 2
8938 >>> x = Int('x')
8939 >>> g = Goal()
8940 >>> g.add(x > 0)
8941 >>> g.add(x < 10)
8942 >>> p(g)
8943 1.0
8944 """
8945 return Probe(Z3_probe_eq(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
8946
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 8919 of file z3py.py.

8919 def __ge__(self, other):
8920 """Return a probe that evaluates to "true" when the value returned by `self`
8921 is greater than or equal to the value returned by `other`.
8922
8923 >>> p = Probe('size') >= 2
8924 >>> x = Int('x')
8925 >>> g = Goal()
8926 >>> g.add(x > 0)
8927 >>> g.add(x < 10)
8928 >>> p(g)
8929 1.0
8930 """
8931 return Probe(Z3_probe_ge(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
8932
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 8891 of file z3py.py.

8891 def __gt__(self, other):
8892 """Return a probe that evaluates to "true" when the value returned by `self`
8893 is greater than the value returned by `other`.
8894
8895 >>> p = Probe('size') > 10
8896 >>> x = Int('x')
8897 >>> g = Goal()
8898 >>> g.add(x > 0)
8899 >>> g.add(x < 10)
8900 >>> p(g)
8901 0.0
8902 """
8903 return Probe(Z3_probe_gt(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
8904
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 8905 of file z3py.py.

8905 def __le__(self, other):
8906 """Return a probe that evaluates to "true" when the value returned by `self`
8907 is less than or equal to the value returned by `other`.
8908
8909 >>> p = Probe('size') <= 2
8910 >>> x = Int('x')
8911 >>> g = Goal()
8912 >>> g.add(x > 0)
8913 >>> g.add(x < 10)
8914 >>> p(g)
8915 1.0
8916 """
8917 return Probe(Z3_probe_le(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
8918
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 8877 of file z3py.py.

8877 def __lt__(self, other):
8878 """Return a probe that evaluates to "true" when the value returned by `self`
8879 is less than the value returned by `other`.
8880
8881 >>> p = Probe('size') < 10
8882 >>> x = Int('x')
8883 >>> g = Goal()
8884 >>> g.add(x > 0)
8885 >>> g.add(x < 10)
8886 >>> p(g)
8887 1.0
8888 """
8889 return Probe(Z3_probe_lt(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
8890
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 8947 of file z3py.py.

8947 def __ne__(self, other):
8948 """Return a probe that evaluates to "true" when the value returned by `self`
8949 is not equal to the value returned by `other`.
8950
8951 >>> p = Probe('size') != 2
8952 >>> x = Int('x')
8953 >>> g = Goal()
8954 >>> g.add(x > 0)
8955 >>> g.add(x < 10)
8956 >>> p(g)
8957 0.0
8958 """
8959 p = self.__eq__(other)
8960 return Probe(Z3_probe_not(self.ctx.ref(), p.probe), self.ctx)
8961
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 8848 of file z3py.py.

◆ probe

probe = None

Definition at line 8849 of file z3py.py.