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

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
probe,
ctx = None )

Definition at line 8728 of file z3py.py.

8728 def __init__(self, probe, ctx=None):
8729 self.ctx = _get_ctx(ctx)
8730 self.probe = None
8731 if isinstance(probe, ProbeObj):
8732 self.probe = probe
8733 elif isinstance(probe, float):
8734 self.probe = Z3_probe_const(self.ctx.ref(), probe)
8735 elif _is_int(probe):
8736 self.probe = Z3_probe_const(self.ctx.ref(), float(probe))
8737 elif isinstance(probe, bool):
8738 if probe:
8739 self.probe = Z3_probe_const(self.ctx.ref(), 1.0)
8740 else:
8741 self.probe = Z3_probe_const(self.ctx.ref(), 0.0)
8742 else:
8743 if z3_debug():
8744 _z3_assert(isinstance(probe, str), "probe name expected")
8745 try:
8746 self.probe = Z3_mk_probe(self.ctx.ref(), probe)
8747 except Z3Exception:
8748 raise Z3Exception("unknown probe '%s'" % probe)
8749 Z3_probe_inc_ref(self.ctx.ref(), self.probe)
8750
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 8754 of file z3py.py.

8754 def __del__(self):
8755 if self.probe is not None and self.ctx.ref() is not None and Z3_probe_dec_ref is not None:
8756 Z3_probe_dec_ref(self.ctx.ref(), self.probe)
8757
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 8843 of file z3py.py.

8843 def __call__(self, goal):
8844 """Evaluate the probe `self` in the given goal.
8845
8846 >>> p = Probe('size')
8847 >>> x = Int('x')
8848 >>> g = Goal()
8849 >>> g.add(x > 0)
8850 >>> g.add(x < 10)
8851 >>> p(g)
8852 2.0
8853 >>> g.add(x < 20)
8854 >>> p(g)
8855 3.0
8856 >>> p = Probe('num-consts')
8857 >>> p(g)
8858 1.0
8859 >>> p = Probe('is-propositional')
8860 >>> p(g)
8861 0.0
8862 >>> p = Probe('is-qflia')
8863 >>> p(g)
8864 1.0
8865 """
8866 if z3_debug():
8867 _z3_assert(isinstance(goal, (Goal, BoolRef)), "Z3 Goal or Boolean expression expected")
8868 goal = _to_goal(goal)
8869 return Z3_probe_apply(self.ctx.ref(), self.probe, goal.goal)
8870
8871
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 8751 of file z3py.py.

8751 def __deepcopy__(self, memo={}):
8752 return Probe(self.probe, self.ctx)
8753

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

8814 def __eq__(self, other):
8815 """Return a probe that evaluates to "true" when the value returned by `self`
8816 is equal to the value returned by `other`.
8817
8818 >>> p = Probe('size') == 2
8819 >>> x = Int('x')
8820 >>> g = Goal()
8821 >>> g.add(x > 0)
8822 >>> g.add(x < 10)
8823 >>> p(g)
8824 1.0
8825 """
8826 return Probe(Z3_probe_eq(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
8827
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 8800 of file z3py.py.

8800 def __ge__(self, other):
8801 """Return a probe that evaluates to "true" when the value returned by `self`
8802 is greater than or equal to the value returned by `other`.
8803
8804 >>> p = Probe('size') >= 2
8805 >>> x = Int('x')
8806 >>> g = Goal()
8807 >>> g.add(x > 0)
8808 >>> g.add(x < 10)
8809 >>> p(g)
8810 1.0
8811 """
8812 return Probe(Z3_probe_ge(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
8813
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 8772 of file z3py.py.

8772 def __gt__(self, other):
8773 """Return a probe that evaluates to "true" when the value returned by `self`
8774 is greater than the value returned by `other`.
8775
8776 >>> p = Probe('size') > 10
8777 >>> x = Int('x')
8778 >>> g = Goal()
8779 >>> g.add(x > 0)
8780 >>> g.add(x < 10)
8781 >>> p(g)
8782 0.0
8783 """
8784 return Probe(Z3_probe_gt(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
8785
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 8786 of file z3py.py.

8786 def __le__(self, other):
8787 """Return a probe that evaluates to "true" when the value returned by `self`
8788 is less than or equal to the value returned by `other`.
8789
8790 >>> p = Probe('size') <= 2
8791 >>> x = Int('x')
8792 >>> g = Goal()
8793 >>> g.add(x > 0)
8794 >>> g.add(x < 10)
8795 >>> p(g)
8796 1.0
8797 """
8798 return Probe(Z3_probe_le(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
8799
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 8758 of file z3py.py.

8758 def __lt__(self, other):
8759 """Return a probe that evaluates to "true" when the value returned by `self`
8760 is less than the value returned by `other`.
8761
8762 >>> p = Probe('size') < 10
8763 >>> x = Int('x')
8764 >>> g = Goal()
8765 >>> g.add(x > 0)
8766 >>> g.add(x < 10)
8767 >>> p(g)
8768 1.0
8769 """
8770 return Probe(Z3_probe_lt(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
8771
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 8828 of file z3py.py.

8828 def __ne__(self, other):
8829 """Return a probe that evaluates to "true" when the value returned by `self`
8830 is not equal to the value returned by `other`.
8831
8832 >>> p = Probe('size') != 2
8833 >>> x = Int('x')
8834 >>> g = Goal()
8835 >>> g.add(x > 0)
8836 >>> g.add(x < 10)
8837 >>> p(g)
8838 0.0
8839 """
8840 p = self.__eq__(other)
8841 return Probe(Z3_probe_not(self.ctx.ref(), p.probe), self.ctx)
8842
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 8729 of file z3py.py.

◆ probe

probe = None

Definition at line 8730 of file z3py.py.