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

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
probe,
ctx = None )

Definition at line 8719 of file z3py.py.

8719 def __init__(self, probe, ctx=None):
8720 self.ctx = _get_ctx(ctx)
8721 self.probe = None
8722 if isinstance(probe, ProbeObj):
8723 self.probe = probe
8724 elif isinstance(probe, float):
8725 self.probe = Z3_probe_const(self.ctx.ref(), probe)
8726 elif _is_int(probe):
8727 self.probe = Z3_probe_const(self.ctx.ref(), float(probe))
8728 elif isinstance(probe, bool):
8729 if probe:
8730 self.probe = Z3_probe_const(self.ctx.ref(), 1.0)
8731 else:
8732 self.probe = Z3_probe_const(self.ctx.ref(), 0.0)
8733 else:
8734 if z3_debug():
8735 _z3_assert(isinstance(probe, str), "probe name expected")
8736 try:
8737 self.probe = Z3_mk_probe(self.ctx.ref(), probe)
8738 except Z3Exception:
8739 raise Z3Exception("unknown probe '%s'" % probe)
8740 Z3_probe_inc_ref(self.ctx.ref(), self.probe)
8741
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 8745 of file z3py.py.

8745 def __del__(self):
8746 if self.probe is not None and self.ctx.ref() is not None and Z3_probe_dec_ref is not None:
8747 Z3_probe_dec_ref(self.ctx.ref(), self.probe)
8748
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 8834 of file z3py.py.

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

8742 def __deepcopy__(self, memo={}):
8743 return Probe(self.probe, self.ctx)
8744

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

8805 def __eq__(self, other):
8806 """Return a probe that evaluates to "true" when the value returned by `self`
8807 is equal to the value returned by `other`.
8808
8809 >>> p = Probe('size') == 2
8810 >>> x = Int('x')
8811 >>> g = Goal()
8812 >>> g.add(x > 0)
8813 >>> g.add(x < 10)
8814 >>> p(g)
8815 1.0
8816 """
8817 return Probe(Z3_probe_eq(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
8818
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 8791 of file z3py.py.

8791 def __ge__(self, other):
8792 """Return a probe that evaluates to "true" when the value returned by `self`
8793 is greater than or equal to the value returned by `other`.
8794
8795 >>> p = Probe('size') >= 2
8796 >>> x = Int('x')
8797 >>> g = Goal()
8798 >>> g.add(x > 0)
8799 >>> g.add(x < 10)
8800 >>> p(g)
8801 1.0
8802 """
8803 return Probe(Z3_probe_ge(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
8804
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 8763 of file z3py.py.

8763 def __gt__(self, other):
8764 """Return a probe that evaluates to "true" when the value returned by `self`
8765 is greater than the value returned by `other`.
8766
8767 >>> p = Probe('size') > 10
8768 >>> x = Int('x')
8769 >>> g = Goal()
8770 >>> g.add(x > 0)
8771 >>> g.add(x < 10)
8772 >>> p(g)
8773 0.0
8774 """
8775 return Probe(Z3_probe_gt(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
8776
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 8777 of file z3py.py.

8777 def __le__(self, other):
8778 """Return a probe that evaluates to "true" when the value returned by `self`
8779 is less than or equal to the value returned by `other`.
8780
8781 >>> p = Probe('size') <= 2
8782 >>> x = Int('x')
8783 >>> g = Goal()
8784 >>> g.add(x > 0)
8785 >>> g.add(x < 10)
8786 >>> p(g)
8787 1.0
8788 """
8789 return Probe(Z3_probe_le(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
8790
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 8749 of file z3py.py.

8749 def __lt__(self, other):
8750 """Return a probe that evaluates to "true" when the value returned by `self`
8751 is less than the value returned by `other`.
8752
8753 >>> p = Probe('size') < 10
8754 >>> x = Int('x')
8755 >>> g = Goal()
8756 >>> g.add(x > 0)
8757 >>> g.add(x < 10)
8758 >>> p(g)
8759 1.0
8760 """
8761 return Probe(Z3_probe_lt(self.ctx.ref(), self.probe, _to_probe(other, self.ctx).probe), self.ctx)
8762
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 8819 of file z3py.py.

8819 def __ne__(self, other):
8820 """Return a probe that evaluates to "true" when the value returned by `self`
8821 is not equal to the value returned by `other`.
8822
8823 >>> p = Probe('size') != 2
8824 >>> x = Int('x')
8825 >>> g = Goal()
8826 >>> g.add(x > 0)
8827 >>> g.add(x < 10)
8828 >>> p(g)
8829 0.0
8830 """
8831 p = self.__eq__(other)
8832 return Probe(Z3_probe_not(self.ctx.ref(), p.probe), self.ctx)
8833
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 8720 of file z3py.py.

◆ probe

probe = None

Definition at line 8721 of file z3py.py.